openModeller  Version 1.5.0
dg_garp_bs.cpp
Go to the documentation of this file.
1 
30 #include "dg_garp_bs.hh"
31 #include "GarpAlgorithm.h"
32 
33 #include <openmodeller/om.hh>
34 #include <openmodeller/Random.hh>
35 #include <openmodeller/Sampler.hh>
36 
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <math.h>
40 
41 #ifdef WIN32
42 #include <windows.h>
43 #define SLEEP(secs) Sleep(secs * 1000)
44 #else
45 #include <unistd.h>
46 #define SLEEP(secs) sleep(secs);
47 #endif
48 
49 #define NUM_PARAM 11
50 
51 /************************************/
52 /*** Algorithm parameter metadata ***/
53 
55 {
56  // Best Subsets Parameters
57  {
58  "TrainingProportion", // Id.
59  "Training Proportion", // Name.
60  "Double", // Type.
61 
62  // Overview.
63  "Proportion of the occurrence data to be used to train the models.",
64 
65  // Description.
66  "",
67 
68  1, // Not zero if the parameter has lower limit.
69  0, // Parameter's lower limit.
70  1, // Not zero if the parameter has upper limit.
71  1, // Parameter's upper limit.
72  "0.5" // Parameter's typical (default) value.
73  },
74 
75  {
76  "TotalRuns", // Id.
77  "Total Runs", // Name.
78  "Integer", // Type.
79 
80  // Overview.
81  "Maximum number of GARP runs to be performed.",
82 
83  // Description.
84  "",
85 
86  1, // Not zero if the parameter has lower limit.
87  0, // Parameter's lower limit.
88  1, // Not zero if the parameter has upper limit.
89  10000, // Parameter's upper limit.
90  "10" // Parameter's typical (default) value.
91  },
92 
93  {
94  "HardOmissionThreshold", // Id.
95  "Hard Omission Threshold", // Name.
96  "Double", // Type.
97 
98  // Overview.
99  "Maximum acceptable omission error. Set to 100% to use only soft omission",
100 
101  // Description.
102  "",
103 
104  1, // Not zero if the parameter has lower limit.
105  0, // Parameter's lower limit.
106  1, // Not zero if the parameter has upper limit.
107  100, // Parameter's upper limit.
108  "100" // Parameter's typical (default) value.
109  },
110 
111  {
112  "ModelsUnderOmissionThreshold", // Id.
113  "Models Under Omission Threshold", // Name.
114  "Integer", // Type.
115 
116  // Overview.
117  "Minimum number of models below omission threshold.",
118 
119  // Description.
120  "",
121 
122  1, // Not zero if the parameter has lower limit.
123  0, // Parameter's lower limit.
124  1, // Not zero if the parameter has upper limit.
125  10000, // Parameter's upper limit.
126  "20" // Parameter's typical (default) value.
127  },
128 
129  {
130  "CommissionThreshold", // Id.
131  "Commission Threshold", // Name.
132  "Double", // Type.
133 
134  // Overview.
135  "Percentage of distribution of models to be taken regarding commission error.",
136 
137  // Description.
138  "",
139 
140  1, // Not zero if the parameter has lower limit.
141  0, // Parameter's lower limit.
142  1, // Not zero if the parameter has upper limit.
143  100, // Parameter's upper limit.
144  "50" // Parameter's typical (default) value.
145  },
146 
147  {
148  "CommissionSampleSize", // Id.
149  "Commission Sample Size", // Name.
150  "Integer", // Type.
151 
152  // Overview.
153  "Number of samples used to calculate commission error.",
154 
155  // Description.
156  "",
157 
158  1, // Not zero if the parameter has lower limit.
159  1, // Parameter's lower limit.
160  0, // Not zero if the parameter has upper limit.
161  0, // Parameter's upper limit.
162  "10000" // Parameter's typical (default) value.
163  },
164 
165  {
166  "MaxThreads", // Id.
167  "Maximum Number of Threads", // Name.
168  "Integer", // Type.
169 
170  // Overview.
171  "Maximum number of threads of executions to run simultaneously.",
172 
173  // Description.
174  "",
175 
176  1, // Not zero if the parameter has lower limit.
177  1, // Parameter's lower limit.
178  1, // Not zero if the parameter has upper limit.
179  1024, // Parameter's upper limit.
180  "1" // Parameter's typical (default) value.
181  },
182 
183  // GARP parameters
184  {
185  "MaxGenerations", // Id.
186  "Max generations", // Name.
187  "Integer", // Type.
188 
189  // Overview.
190  "Maximum number of iterations run by the Genetic Algorithm.",
191 
192  // Description.
193  "Maximum number of iterations (generations) run by the Genetic\
194  Algorithm.",
195 
196  1, // Not zero if the parameter has lower limit.
197  1, // Parameter's lower limit.
198  0, // Not zero if the parameter has upper limit.
199  0, // Parameter's upper limit.
200  "400" // Parameter's typical (default) value.
201  },
202 
203  {
204  "ConvergenceLimit", // Id.
205  "Convergence limit", // Name.
206  "Real", // Type.
207 
208  // Overview.
209  "Defines the convergence value that makes the algorithm stop\
210  (before reaching MaxGenerations).",
211 
212  // Description.
213  "",
214 
215  1, // Not zero if the parameter has lower limit.
216  0.0, // Parameter's lower limit.
217  1, // Not zero if the parameter has upper limit.
218  1.0, // Parameter's upper limit.
219  "0.01" // Parameter's typical (default) value.
220  },
221 
222  {
223  "PopulationSize", // Id.
224  "Population size", // Name.
225  "Integer", // Type.
226 
227  "Maximum number of rules to be kept in solution.", // Overview.
228  "", // Description
229 
230  1, // Not zero if the parameter has lower limit.
231  1, // Parameter's lower limit.
232  1, // Not zero if the parameter has upper limit.
233  500, // Parameter's upper limit.
234  "50" // Parameter's typical (default) value.
235  },
236 
237  {
238  "Resamples", // Id.
239  "Resamples", // Name.
240  "Integer", // Type.
241 
242  // Overview.
243  "Number of points sampled (with replacement) used to test rules.",
244 
245  // Description.
246  "",
247 
248  1, // Not zero if the parameter has lower limit.
249  1, // Parameter's lower limit.
250  1, // Not zero if the parameter has upper limit.
251  100000, // Parameter's upper limit.
252  "2500" // Parameter's typical (default) value.
253  }
254 };
255 
256 /************************************/
257 /*** Algorithm's general metadata ***/
258 
260 
261  "DG_GARP_BS", // Id.
262  "GARP with best subsets - DesktopGARP implementation", // Name.
263  "3.0.1 alpha", // Version.
264 
265  // Overview.
266  "GARP is a genetic algorithm that creates ecological niche \
267 models for species. The models describe environmental conditions \
268 under which the species should be able to maintain populations. \
269 For input, GARP uses a set of point localities where the species \
270 is known to occur and a set of geographic layers representing \
271 the environmental parameters that might limit the species' \
272 capabilities to survive.",
273 
274  // Description.
275  "GARP is a genetic algorithm that creates ecological niche \
276 models for species. The models describe environmental conditions \
277 under which the species should be able to maintain populations. \
278 For input, GARP uses a set of point localities where the species \
279 is known to occur and a set of geographic layers representing \
280 the environmental parameters that might limit the species' \
281 capabilities to survive.",
282 
283  // Author
284  "Anderson, R. P., D. Lew, D. and A. T. Peterson.",
285 
286  // Bibliography.
287  "Anderson, R. P., D. Lew, and A. T. Peterson. 2003. \
288 Evaluating predictive models of species' distributions: criteria \
289 for selecting optimal models.Ecological Modelling, v. 162, p. 211 232.",
290 
291  "Ricardo Scachetti Pereira", // Code author.
292  "rpereira [at] ku.edu", // Code author's contact.
293 
294  0, // Does not accept categorical data.
295  1, // Does not need (pseudo)absence points.
296 
297  NUM_PARAM, // Algorithm's parameters.
298  parameters_bs
299 };
300 
301 
302 /****************************************************************/
303 /****************** Algorithm's factory function ****************/
304 
305 OM_ALG_DLL_EXPORT
306 AlgorithmImpl *
308 {
309  return new DgGarpBestSubsets();
310 }
311 
312 OM_ALG_DLL_EXPORT
313 AlgMetadata const *
315 {
316  return &metadata_bs;
317 }
318 
319 /****************************************************************/
320 /****************** Garp class **********************************/
321 
323  : BestSubsets(& metadata_bs)
324 {
325  _normalizerPtr = new ScaleNormalizer( 1.0, 253.0, true );
326 }
327 
328 // ****************************************************************
330 {
331 }
332 
333 // ****************************************************************
335 {
336  return new GarpAlgorithm();
337 }
338 
339 // ****************************************************************
340 // ************* initialize ***************************************
341 
343 {
344  // GARP parameters
345  if (!getParameter("MaxGenerations", &_max_gen))
346  Log::instance()->error(1, "Parameter MaxGenerations not set properly.\n");
347 
348  if (!getParameter("ConvergenceLimit", &_conv_limit))
349  Log::instance()->error(1, "Parameter ConvergenceLimit not set properly.\n");
350 
351  if (!getParameter("PopulationSize", &_popsize))
352  Log::instance()->error(1, "Parameter PopulationSize not set properly.\n");
353 
354  if (!getParameter("Resamples", &_resamples))
355  Log::instance()->error(1, "Parameter Resamples not set properly.\n");
356 
357  if (_alg_params)
358  delete[] _alg_params;
359 
360  _nparam = 4;
362 
363  char buffer[1024];
364  sprintf(buffer, "%d", _max_gen);
365  _alg_params[0].setId("MaxGenerations");
366  _alg_params[0].setValue(buffer);
367 
368  sprintf(buffer, "%f", _conv_limit);
369  _alg_params[1].setId("ConvergenceLimit");
370  _alg_params[1].setValue(buffer);
371 
372  sprintf(buffer, "%d", _popsize);
373  _alg_params[2].setId("PopulationSize");
374  _alg_params[2].setValue(buffer);
375 
376  sprintf(buffer, "%d", _resamples);
377  _alg_params[3].setId("Resamples");
378  _alg_params[3].setValue(buffer);
379 
380  return 1;
381 }
382 
int transferParametersToAlgorithm()
Definition: dg_garp_bs.cpp:342
#define NUM_PARAM
Definition: dg_garp_bs.cpp:49
AlgParamMetadata parameters_bs[NUM_PARAM]
Definition: dg_garp_bs.cpp:54
void setValue(std::string const val)
Definition: AlgParameter.hh:68
static Log * instance()
Returns the instance pointer, creating the object on the first call.
Definition: Log.cpp:45
OM_ALG_DLL_EXPORT AlgMetadata const * algorithmMetadata()
Definition: dg_garp_bs.cpp:314
AlgorithmImpl * getBSAlgorithm()
Definition: dg_garp_bs.cpp:334
void error(const char *format,...)
'Error' level.
Definition: Log.cpp:290
int getParameter(std::string const &name, std::string *value)
OM_ALG_DLL_EXPORT AlgorithmImpl * algorithmFactory()
Definition: dg_garp_bs.cpp:307
void setId(std::string const id)
Definition: AlgParameter.hh:59
AlgMetadata metadata_bs
Definition: dg_garp_bs.cpp:259
AlgParameter * _alg_params