openModeller  Version 1.5.0
niche_mosaic.cpp
Go to the documentation of this file.
1 
27 #include "niche_mosaic.hh"
28 
30 
31 #include <openmodeller/Random.hh>
32 
33 #include <stdio.h>
34 #include <math.h>
35 #include <stdlib.h>
36 #include <time.h>
37 
38 /****************************************************************/
39 /********************** Algorithm's Metadata ********************/
40 
41 #define NUM_PARAM 1
42 
43 #define NUMITERATIONS_ID "NumberOfIterations"
44 
45 /*************************************/
46 /*** Algorithm parameters metadata ***/
47 
49 
50  // Metadata of the first parameter.
51  {
52  NUMITERATIONS_ID, // Id
53  "Number of iterations", // Name.
54  Integer, // Type.
55 
56  // Overview
57  "Number of iterations.",
58 
59  // Description.
60  "Number of iterations.",
61 
62  1, // Not zero if the parameter has lower limit.
63  1000, // Parameter's lower limit.
64  0, // Not zero if the parameter has upper limit.
65  0, // Parameter's upper limit.
66  "2000" // Parameter's typical (default) value.
67  },
68 };
69 
70 /************************************/
71 /*** Algorithm's general metadata ***/
72 
74 
75  "NICHE_MOSAIC", // Id.
76  "Niche Mosaic", // Name.
77  "0.1", // Version.
78 
79  // Overview
80  "This algorithm uses tabu search metaheuristic to find a collection of multidimensional niche envelopes, each envelope is centered at one of the selected presence points and consists of a suitability interval for each environmental variable.",
81 
82  // Description.
83  "This algorithm uses tabu search metaheuristic to find a collection of multidimensional niche envelopes, each envelope is centered at one of the selected presence points and consists of a suitability interval for each environmental variable. Presence points are initially filtered to remove possible outliers and then split into a calibration set and a testing set. Pseudo-absence points are also used for internal model testing, and are generated outside the environmental envelope determined by all presence points. During each iteration the algorithm modifies the envelope intervals until the best solution is found.",
84 
85  "Missae Yamamoto", // Author
86 
87  // Bibliography.
88  "Glover, F. (1989). Tabu Search - part I, ORSA Journal in Computing 1: 190-206. Glover, F. (1989). Tabu Search - part II, ORSA Journal in Computing 2: 4-32.",
89 
90  "Missae Yamamoto", // Code author.
91  "missae [at] dpi.inpe.br", // Code author's contact.
92 
93  0, // Does not accept categorical data.
94  0, // Does not need (pseudo)absence points.
95 
96  NUM_PARAM, // Algorithm's parameters.
97  parameters
98 };
99 
100 /****************************************************************/
101 /****************** Algorithm's factory function ****************/
102 
103 OM_ALG_DLL_EXPORT
106 {
107  return new NicheMosaic();
108 }
109 
110 OM_ALG_DLL_EXPORT
111 AlgMetadata const *
113 {
114  return &metadata;
115 }
116 
117 /*************************************************************/
118 /************************ Niche Mosaic ***********************/
119 
121  AlgorithmImpl( &metadata ),
122  _num_iterations(0),
123  _num_points(0),
124  _num_points_test(0),
125  _num_points_absence_test(0),
126  _num_layers(0),
127  _minimum(),
128  _maximum(),
129  _delta(),
130  _my_presences(0),
131  _my_presences_test(0),
132  _my_absence_test(0),
133  _bestCost(0),
134  _done( false ),
135  _progress( 0.0 )
136 {
137 }
138 
140 {
141 }
142 
143 /******************/
144 /*** initialize ***/
145 int
147 {
148  // Check the number of presences
149  int num_presences = _samp->numPresence();
150 
151  if ( num_presences < 10 ) {
152 
153  Log::instance()->warn( "Niche Mosaic needs at least 10 presence points.\n" );
154  return 0;
155  }
156 
157  // Check number of layers
158  _num_layers = _samp->numIndependent();
159 
160  if ( _num_layers < 2 )
161  {
162  std::string msg = "Niche Mosaic needs at least 2 layers.\n";
163 
164  Log::instance()->error( msg.c_str() );
165  return 0;
166  }
167 
168  // Get parameters
170 
171  Log::instance()->error( "Parameter '" NUMITERATIONS_ID "' not passed.\n" );
172  return 0;
173  }
174 
175  if ( _num_iterations < 1000 ) {
176 
177  Log::instance()->error( "Parameter '" NUMITERATIONS_ID "' must be greater than 999.\n" );
178  return 0;
179  }
180 
181  // remove discrepancy presence points
182  OccurrencesPtr cleanPresences = cleanOccurrences( _samp->getPresences() );
183  _sampp = createSampler( _samp->getEnvironment(), cleanPresences, _samp->getAbsences() );
184 
185  // generate pseudo absence points using simple algorithm.
186  size_t num_abs = (size_t)(0.40 * num_presences);
187  if (num_abs < 10) num_abs = 10;
188  int dim = _sampp->numIndependent();
189  Sample minimum(dim), maximum(dim);
190  OccurrencesPtr pres = _sampp->getPresences();
191  pres->getMinMax( &minimum, &maximum );
192 
193  double delta;
194  for( unsigned int i=0; i<minimum.size(); i++) {
195  delta = (maximum[i] - minimum[i]) * 0.10;
196  minimum[i] = minimum[i] - delta;
197  maximum[i] = maximum[i] + delta;
198  }
199 
200  _my_absence_test = _sampp->getPseudoAbsences( num_abs, &minimum, &maximum );
201 
202  _num_points_absence_test = _my_absence_test->numOccurrences();
203 
204  _my_presences = new OccurrencesImpl( _my_absence_test->label(), _my_absence_test->coordSystem() );
205 
206  _my_presences_test = new OccurrencesImpl( _my_absence_test->label(), _my_absence_test->coordSystem() );
207 
208  return 1;
209 }
210 
211 /***************/
212 /*** iterate ***/
213 int
215 {
216  std::vector<Scalar> deltaBest( _num_layers );
217  size_t costBest, num_points_train_test, bestCost2=0;
218  int bestIter = 0;
219 
220  num_points_train_test = _sampp->getPresences()->numOccurrences();
221  _model_min_best.resize( num_points_train_test );
222  _model_max_best.resize( num_points_train_test );
223 
224  for ( unsigned int i = 0; i < _model_min_best.size(); i++ ) {
227  }//end for
228 
229 
230  // Split sampler in test/train
232  _num_points_test = _my_presences_test->numOccurrences();
233  _num_points = _my_presences->numOccurrences();
234 
235  if ( 0 == setMinMaxDelta() ) {return 0;}
236 
237  int endDo = _num_layers * 10;
238  do{
239  findSolution(costBest, deltaBest, bestIter, bestCost2);
240 
242  if (_num_iterations > 30000) break;
243  }while( (bestIter < endDo) || (costBest < (size_t)(_num_points_test*0.8)) );
244 
245  if ( (size_t)(_num_points_absence_test*0.6) > bestCost2 ){
246 
247  int dim = _sampp->numIndependent();
248  Sample minimum(dim), maximum(dim);
249  OccurrencesPtr pres = _sampp->getPresences();
250  pres->getMinMax( &minimum, &maximum );
251 
252  double delta;
253  for( unsigned int i=0; i<minimum.size(); i++) {
254  delta = (maximum[i] - minimum[i]) * 0.10;
255  minimum[i] = minimum[i] - delta;
256  maximum[i] = maximum[i] + delta;
257  }
258 
259  _my_absence_test = _sampp->getPseudoAbsences( 100, &minimum, &maximum );
260 
261 
262  _num_points_absence_test = _my_absence_test->numOccurrences();
263 
264  _num_iterations = 10000;
265  findSolution(costBest, deltaBest, bestIter, bestCost2);
266  }
267 
268  if (costBest < _num_points_test)
269  improveModel(deltaBest);
270 
271  _done = 1;
272 
273  return 1;
274 }
275 
276 float
278 {
279  if (done()) {
280 
281  return 1.0;
282  }
283  else {
284 
285  return _progress;
286  }
287 }
288 
289 /*****************/
290 /*** get Value ***/ /********matchRules classes******/
291 Scalar
292 NicheMosaic::getValue( const Sample& x ) const
293 {
294  int i, j, k = 0;
295  Scalar percent;
296 
297  //_num_points represents the number of rules
298  for (i = 0; i < _num_points; i++) {
299  for (j = 0; j < _num_layers; j++) {
300 
301  if ( ( _model_min_best[i][j] <= x[j] ) && ( x[j] <= _model_max_best[i][j] ) )
302  continue;
303  else
304  break;
305  }//end for
306 
307  if ( j == _num_layers ) {
308  k++;
309  }//end if
310  }//end for
311 
312  percent = (Scalar)k /(Scalar)_num_points;
313  if (percent == 0.0) return 0.0;
314  else if (percent < 0.10) return 0.5;
315  else if (percent < 0.25) return 0.7;
316  else if (percent < 0.90) return 0.9;
317  else return 1.0;
318 }
319 
320 
321 int
323 {
326 
327  Sample const & sample = (*oc)->environment();
328  _minimum = sample;
329  _maximum = sample;
330  ++oc;
331 
332  while ( oc != end ) {
333  Sample const& sample = (*oc)->environment();
334  _minimum &= sample;
335  _maximum |= sample;
336  ++oc;
337  }
338 
339  _delta = _maximum;
340  _delta -= _minimum;
341 
342  for ( int j = 0; j < _num_layers; j++ ) {
343  if (_delta[j] == 0.0) {
344  Log::instance()->error( "No delta for layer %d\n", j );
345  return 0;
346  }
347  }
348 
349  return 1;
350 }
351 
352 void
353 NicheMosaic::createModel( std::vector<ScalarVector> &model_min, std::vector<ScalarVector> &model_max, const std::vector<Scalar> &delta )
354 {
355  size_t i=0;
358 
359  while ( oc != end ) {
360  Sample const& sample = (*oc)->environment();
361 
362  for ( int j = 0; j < _num_layers; j++ ) {
363  model_min[i][j] = sample[j] - delta[j];
364  model_max[i][j] = sample[j] + delta[j];
365  }//end for
366 
367  ++oc;
368  ++i;
369  }//end while
370 }
371 
372 void
373 NicheMosaic::editModel( std::vector<ScalarVector> &model_min, std::vector<ScalarVector> &model_max, const std::vector<Scalar> &delta, size_t i_layer )
374 {
375  size_t i=0;
378 
379  while ( oc != end ) {
380  Sample const& sample = (*oc)->environment();
381 
382  model_min[i][i_layer] = sample[i_layer] - delta[i_layer];
383  model_max[i][i_layer] = sample[i_layer] + delta[i_layer];
384 
385  ++oc;
386  ++i;
387  }//end while
388 }
389 
390 size_t
391 NicheMosaic::calculateCostPres( const std::vector<ScalarVector> &model_min, const std::vector<ScalarVector> &model_max )
392 {
395 
396  int i, j, npresence = 0;
397 
398  //presence
399  while ( it != last ) {
400 
401  Sample const& sample = (*it)->environment();
402 
403  //_num_points eh o numero de regras do modelo
404  for (i = 0; i < _num_points; i++) {
405 
406  for (j = 0; j < _num_layers; j++) {
407 
408  if ( ( model_min[i][j] <= sample[j] ) && ( sample[j] <= model_max[i][j] ) )
409  continue;
410  else
411  break;
412  }//end for
413 
414  if ( j == _num_layers ) {
415  npresence++;
416  break;
417  }//end if
418  }//end for
419  ++it;
420  }//end while
421 
422  return npresence;
423 }
424 
425 size_t
426 NicheMosaic::calculateCostAus( const std::vector<ScalarVector> &model_min, const std::vector<ScalarVector> &model_max )
427 {
428  int i, j, nabsence = 0;
429 
430  //absence
431  OccurrencesImpl::iterator it_absence = _my_absence_test->begin();
432  OccurrencesImpl::iterator last_absence = _my_absence_test->end();
433 
434  while ( it_absence != last_absence )
435  {
436  Sample const& samp = (*it_absence)->environment();
437 
438  for (i = 0; i < _num_points; i++){ //_num_points eh o numero de regras do modelo
439 
440  for (j = 0; j < _num_layers; j++){
441 
442  if ( ( model_min[i][j] <= samp[j] ) && ( samp[j] <= model_max[i][j] ) )
443  continue;
444  else
445  break;
446  }//end for
447 
448  if ( j == _num_layers )
449  break;
450  }//end for
451 
452  if ( i == _num_points)
453  nabsence++;
454 
455  ++it_absence;
456  }//end while
457 
458  return nabsence;
459 }
460 
461 size_t
463 {
464  Random random;
465 
466  return random( 0, _num_layers );
467 }
468 
469 Scalar
470 NicheMosaic::getRandomPercent(const std::vector<Scalar> &delta, const size_t i_layer, size_t &costPres)
471 {
472  int size = 100, r;
473 
474  double min_percent = 0.12, max_percent = 0.4;
475 
476  double new_percent, half_percent = (max_percent - min_percent) / 2 + min_percent;
477 
478  Random random;
479 
480  r = random( 0, size );
481  new_percent = (max_percent - min_percent) * ( (double) r / (double) size ) + min_percent;
482 
483  if ( (costPres < _num_points_test) && (new_percent < half_percent) ){
484 
485  new_percent = new_percent + half_percent - min_percent;
486  }
487 
488  return new_percent;
489 }
490 
491 void
492 NicheMosaic::renewTabuDegree(std::vector<size_t> &tabuDegree)
493 {
494  for (int i = 0; i < _num_layers; i++) {
495 
496  if (tabuDegree[i] > 0)
497  tabuDegree[i] = tabuDegree[i] - 1;
498  }
499 }
500 
501 void
502 NicheMosaic::saveBestModel(const std::vector<ScalarVector> &model_min, const std::vector<ScalarVector> &model_max)
503 {
504  for (int i = 0; i < _num_points; i++) {
505  for (int j = 0; j < _num_layers; j++) {
506  _model_min_best[i][j] = model_min[i][j];
507  _model_max_best[i][j] = model_max[i][j];
508  }
509  }
510 }
511 
512 void
513 NicheMosaic::improveModel( const std::vector<Scalar> &deltaBest )
514 {
517 
518  int i, j, flag = 0, n = _num_points;
519 
520  while ( it != last ) {
521 
522  Sample const& sample = (*it)->environment();
523 
524  //_num_points eh o numero de regras do modelo
525  for (i = 0; i < n; i++) {
526 
527  for (j = 0; j < _num_layers; j++) {
528 
529  if ( ( _model_min_best[i][j] <= sample[j] ) && ( sample[j] <= _model_max_best[i][j] ) )
530  continue;
531  else
532  break;
533  }//end for
534 
535  if ( j == _num_layers ) {
536  flag = 1;
537  break;
538  }//end if
539  }//end for
540  if (flag){
541  flag = 0;
542  }else {
543  for (j = 0; j < _num_layers; j++) {
544  _model_min_best[n][j] = sample[j] - deltaBest[j];
545  _model_max_best[n][j] = sample[j] + deltaBest[j];
546 
547  }//end for
548  n++;
549  }//end if
550  ++it;
551  }//end while
552  _num_points = n;
553 }
554 
555 void
556 NicheMosaic::findSolution(size_t &costBest, std::vector<Scalar> &deltaBest, int &bestIter, size_t &bestCost2)
557 {
558  size_t cost1, cost2, i_layer;
559  Scalar importance = 1.0, cost, deltaIni=0.4;
560  std::vector<Scalar> delta( _num_layers );
561 
562  size_t nTabu = (size_t)floor(sqrt((double)(_num_layers)));
563  std::vector<size_t> tabuDegree( _num_layers );
564 
565  for( int l = 0; l < _num_layers; l++ )
566  tabuDegree[l] = 0;
567 
568  //model
569  std::vector<ScalarVector> model_min( _num_points );
570  std::vector<ScalarVector> model_max( _num_points );
571 
572  for ( unsigned int i = 0; i < model_min.size(); i++ ) {
573  model_min[i] = ScalarVector( _num_layers );
574  model_max[i] = ScalarVector( _num_layers );
575  }//end for
576 
577  for ( int j = 0; j < _num_layers; j++ ){
578 
579  delta[j] = _delta[j] * deltaIni;
580  deltaBest[j] = delta[j];
581  }//end for
582 
583  createModel( model_min, model_max, delta );
584  cost1 = calculateCostPres( model_min, model_max );
585  costBest = cost1;
586  cost2 = calculateCostAus( model_min, model_max );
587  cost = (Scalar)cost1*importance + (Scalar)cost2;
588 
589  _bestCost = cost;
590  saveBestModel(model_min, model_max);
592  return;
593 
594  for (int iter=0; iter < _num_iterations; iter++) {
595 
596  _progress = (float)iter/(float)_num_iterations;
597  i_layer = getRandomLayerNumber();
598 
599  Scalar deltaAux = delta[i_layer];
600  delta[i_layer] = _delta[i_layer] * getRandomPercent(delta, i_layer, cost1);
601  editModel( model_min, model_max, delta, i_layer );
602  cost1 = calculateCostPres( model_min, model_max );
603  cost2 = calculateCostAus( model_min, model_max );
604  cost = (Scalar)cost1*importance + (Scalar)cost2;
605 
606  if ( (cost > _bestCost) || ( (cost == _bestCost) && (cost1 >= costBest) ) ) {
607  renewTabuDegree(tabuDegree);
608  tabuDegree[i_layer] = nTabu;
609  costBest = cost1;
610  _bestCost = cost;
611  deltaBest[i_layer] = delta[i_layer];
612  saveBestModel(model_min, model_max);
613  bestIter = iter;
614  bestCost2=cost2;
615 
616  if (_bestCost == ((Scalar)_num_points_test*importance + (Scalar)_num_points_absence_test) )
617  break;
618  }else {
619  if (tabuDegree[i_layer] == 0) {
620  renewTabuDegree(tabuDegree);
621  tabuDegree[i_layer] = nTabu;
622  }else{
623  delta[i_layer] = deltaAux;
624  editModel( model_min, model_max, delta, i_layer );
625  }//end if
626  }//end if
627  }//end for
628 }
629 
630 /****************************************************************/
631 /****************** configuration *******************************/
632 void
634 {
635 
636  if ( !_done )
637  return;
638 
639  ConfigurationPtr model_config( new ConfigurationImpl( "NicheMosaic" ) );
640  config->addSubsection( model_config );
641 
642  model_config->addNameValue( "NumLayers", _num_layers );
643  model_config->addNameValue( "NumPoints", _num_points );
644 
645  for (int i = 0; i < _num_points; i++) {
646 
647  ConfigurationPtr rule_config( new ConfigurationImpl( "Rule" ) );
648  model_config->addSubsection( rule_config );
649 
650  Sample min_best( _model_min_best[i] );
651  Sample max_best( _model_max_best[i] );
652 
653  rule_config->addNameValue( "Min", min_best );
654  rule_config->addNameValue( "Max", max_best );
655 
656  }
657 }
658 
659 void
661 {
662  ConstConfigurationPtr model_config = config->getSubsection( "NicheMosaic" );
663 
664  if (!model_config)
665  return;
666 
667  _num_layers = model_config->getAttributeAsInt( "NumLayers", 0 );
668  _num_points = model_config->getAttributeAsInt( "NumPoints", 0 );
669 
670  _model_min_best.resize( _num_points );
671  _model_max_best.resize( _num_points );
672 
673  Configuration::subsection_list subelements = model_config->getAllSubsections();
674 
675  Configuration::subsection_list::iterator subelement = subelements.begin();
676  Configuration::subsection_list::iterator last_subelement = subelements.end();
677 
678  int i = 0;
679 
680  for ( ; subelement != last_subelement; ++subelement ) {
681 
682  if ( (*subelement)->getName() == "Rule" ) {
683 
684  _model_min_best[i] = (*subelement)->getAttributeAsVecDouble( "Min" );
685  _model_max_best[i] = (*subelement)->getAttributeAsVecDouble( "Max" );
686 
687  ++i;
688  }
689  }
690 
691  _done = true;
692 
693  return;
694 }
695 
698 {
699  OccurrencesPtr presence( new OccurrencesImpl(0.0) );
700  OccurrencesPtr presenceAux( new OccurrencesImpl(0.0) );
701 
702  double dist, distLimit=8.0, x, y, xmin, xmax, ymin, ymax, deltax, deltay;
703  unsigned int flag = 0, i = 0, itrain=0, ktrain=0, ioccur=0;
704  std::vector<double> occurTransformx( occurrences->numOccurrences() );
705  std::vector<double> occurTransformy( occurrences->numOccurrences() );
706  std::vector<int> testId( occurrences->numOccurrences() );
707 
708  OccurrencesImpl::const_iterator it = occurrences->begin();
709  OccurrencesImpl::const_iterator fin = occurrences->end();
710 
711  xmin = xmax = (*it)->x();
712  ymin = ymax = (*it)->y();
713 
714  ++it;
715  while( it != fin ) {
716  if ( (*it)->x() < xmin ) xmin = (*it)->x();
717  else if ( (*it)->x() > xmax) xmax = (*it)->x();
718  if ( (*it)->y() < ymin) ymin = (*it)->y();
719  else if ( (*it)->y() > ymax) ymax = (*it)->y();
720  ++it;
721  }
722  deltax = xmax - xmin;
723  deltay = ymax - ymin;
724 
725  it = occurrences->begin();
726  while( it != fin ) {
727  occurTransformx[i] = 100 * ( (*it)->x() - xmin ) / deltax;
728  occurTransformy[i] = 100 * ( (*it)->y() - ymin ) / deltay;
729  i++;
730  ++it;
731  }
732 
733  flag = 0, itrain=0, ktrain=0, ioccur=0;
734 
735  it = occurrences->begin();
736 
737  presenceAux->insert( new OccurrenceImpl( *(*it) ) );
738 
739  ++it;
740  testId[ktrain] = ioccur;
741  ktrain++;
742  ioccur++;
743 
744  while( it != fin ) {
745 
746  for ( i = 0; i < ktrain; i++ ) {
747  itrain = testId[i];
748  x = occurTransformx[ioccur] - occurTransformx[itrain];
749  y = occurTransformy[ioccur] - occurTransformy[itrain];
750  dist = sqrt( (x*x) + (y*y) );
751 
752  if ( dist < distLimit) {
753  presence->insert( new OccurrenceImpl( *(*it) ) );
754  flag = 1;
755  break;
756  }
757  }
758 
759  if (!flag){
760  presenceAux->insert( new OccurrenceImpl( *(*it) ) );
761  testId[ktrain] = ioccur;
762  ktrain++;
763  }else{
764  flag = 0;
765  }
766  ioccur++;
767  ++it;
768  }
769 
770  //verify presenceAux points
771  SamplerPtr samp = createSampler( _samp->getEnvironment(), presence, _samp->getAbsences() );
772  Sample mean;
773  Sample deviation;
774  computeMeanDeviation( presence, mean, deviation );
775 
776  OccurrencesImpl::const_iterator itt = presenceAux->begin();
777  OccurrencesImpl::const_iterator finn = presenceAux->end();
778 
779  double prob;
780  OccurrencePtr occ;
781  while( itt != finn ) {
782  occ = (*itt);
783 
784  Sample dif = occ->environment();
785  dif -= mean;
786  prob = 1.0;
787  for( unsigned int i=0; i<dif.size(); i++) {
788  Scalar cutoff = deviation[i];
789 
790  if ( dif[i] > cutoff || dif[i] < -cutoff ) {
791  prob = 0.0;
792  break;
793  }
794  }
795 
796  if ( prob == 1.0 ){
797  presence->insert( new OccurrenceImpl( *(*itt) ) );
798  }
799  ++itt;
800  }
801 
802  return presence;
803 }
804 
805 void
807 {
808  // compute mean
809  OccurrencesImpl::const_iterator oc = occs->begin();
810  OccurrencesImpl::const_iterator end = occs->end();
811 
812  Sample min, max;
813 
814  Sample const & sample = (*oc)->environment();
815  min = sample;
816  max = sample;
817  mean = sample;
818  ++oc;
819 
820  while ( oc != end ) {
821 
822  Sample const& sample = (*oc)->environment();
823 
824  mean += sample;
825  min &= sample;
826  max |= sample;
827 
828  ++oc;
829  }
830  mean /= Scalar( occs->numOccurrences() );
831 
832  // compute the std deviation
833  deviation.resize( mean.size() );
834  oc = occs->begin();
835 
836  // compute the variance.
837  while ( oc != end ) {
838  Sample tmp( (*oc)->environment() );
839  tmp -= mean;
840  tmp *= tmp;
841  deviation += tmp;
842  ++oc;
843  }
844 
845  // divide by (npnt - 1)
846  Scalar npts = Scalar( occs->numOccurrences() - 1 );
847  deviation /= npts;
848  deviation.sqrt();
849  deviation *= 5.0;
850 }
size_t calculateCostAus(const std::vector< ScalarVector > &_model_min, const std::vector< ScalarVector > &_model_max)
static AlgMetadata metadata
std::vector< OccurrencePtr >::iterator iterator
Definition: Occurrences.hh:86
void warn(const char *format,...)
'Warn' level.
Definition: Log.cpp:273
float getProgress() const
std::vector< ConfigurationPtr > subsection_list
OM_ALG_DLL_EXPORT AlgorithmImpl * algorithmFactory()
void editModel(std::vector< ScalarVector > &model_min, std::vector< ScalarVector > &model_max, const std::vector< Scalar > &delta, size_t i_layer)
void findSolution(size_t &costBest, std::vector< Scalar > &deltaBest, int &bestIter, size_t &bestCost2)
OccurrencesPtr _my_absence_test
Definition: niche_mosaic.hh:49
double Scalar
Type of map values.
Definition: om_defs.hh:39
static AlgParamMetadata parameters[NUM_PARAM]
float _progress
Definition: niche_mosaic.hh:52
void computeMeanDeviation(const OccurrencesPtr &occs, Sample &mean, Sample &deviation)
int done() const
Definition: niche_mosaic.hh:69
static Log * instance()
Returns the instance pointer, creating the object on the first call.
Definition: Log.cpp:45
SamplerPtr _sampp
Definition: niche_mosaic.hh:53
int setMinMaxDelta()
size_t _num_points_absence_test
Definition: niche_mosaic.hh:42
SamplerPtr createSampler(const EnvironmentPtr &env, const OccurrencesPtr &presence, const OccurrencesPtr &absence)
Definition: Sampler.cpp:52
Sample _maximum
Definition: niche_mosaic.hh:45
void error(const char *format,...)
'Error' level.
Definition: Log.cpp:290
void saveBestModel(const std::vector< ScalarVector > &model_min, const std::vector< ScalarVector > &model_max)
void improveModel(const std::vector< Scalar > &deltaBest)
Definition: Random.hh:44
void createModel(std::vector< ScalarVector > &_model_min, std::vector< ScalarVector > &_model_max, const std::vector< Scalar > &delta)
int getParameter(std::string const &name, std::string *value)
size_t _num_points_test
Definition: niche_mosaic.hh:41
Sample _minimum
Definition: niche_mosaic.hh:44
void resize(std::size_t size)
Definition: Sample.cpp:153
void splitOccurrences(const OccurrencesPtr &occurrences, OccurrencesPtr &trainOccurrences, OccurrencesPtr &testOccurrences, double propTrain)
int _num_iterations
Definition: niche_mosaic.hh:39
OM_ALG_DLL_EXPORT AlgMetadata const * algorithmMetadata()
std::vector< Scalar > ScalarVector
Definition: niche_mosaic.hh:33
void renewTabuDegree(std::vector< size_t > &tabuDegree)
#define NUM_PARAM
Scalar getValue(const Sample &x) const
std::size_t size() const
Definition: Sample.hh:70
void _setConfiguration(const ConstConfigurationPtr &)
Sample & sqrt()
Definition: Sample.cpp:445
Sample _delta
Definition: niche_mosaic.hh:46
SamplerPtr _samp
Definition: Algorithm.hh:245
OccurrencesPtr cleanOccurrences(const OccurrencesPtr &occurrences)
std::vector< ScalarVector > _model_max_best
Definition: niche_mosaic.hh:55
Scalar _bestCost
Definition: niche_mosaic.hh:50
std::vector< OccurrencePtr >::const_iterator const_iterator
Definition: Occurrences.hh:85
size_t calculateCostPres(const std::vector< ScalarVector > &_model_min, const std::vector< ScalarVector > &_model_max)
std::vector< ScalarVector > _model_min_best
Definition: niche_mosaic.hh:54
void _getConfiguration(ConfigurationPtr &) const
OccurrencesPtr _my_presences_test
Definition: niche_mosaic.hh:48
OccurrencesPtr _my_presences
Definition: niche_mosaic.hh:47
int min(int v1, int v2)
Definition: rules_base.cpp:56
size_t getRandomLayerNumber()
Scalar getRandomPercent(const std::vector< Scalar > &delta, const size_t i_layer, size_t &cost1)
#define NUMITERATIONS_ID
Definition: Sample.hh:25