43 #define NUMITERATIONS_ID "NumberOfIterations"
53 "Number of iterations",
57 "Number of iterations.",
60 "Number of iterations.",
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.",
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.",
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.",
91 "missae [at] dpi.inpe.br",
125 _num_points_absence_test(0),
131 _my_presences_test(0),
149 int num_presences =
_samp->numPresence();
151 if ( num_presences < 10 ) {
162 std::string msg =
"Niche Mosaic needs at least 2 layers.\n";
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);
191 pres->getMinMax( &minimum, &maximum );
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;
200 _my_absence_test = _sampp->getPseudoAbsences( num_abs, &minimum, &maximum );
217 size_t costBest, num_points_train_test, bestCost2=0;
220 num_points_train_test =
_sampp->getPresences()->numOccurrences();
243 }
while( (bestIter < endDo) || (costBest < (
size_t)(_num_points_test*0.8)) );
247 int dim =
_sampp->numIndependent();
248 Sample minimum(dim), maximum(dim);
250 pres->getMinMax( &minimum, &maximum );
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;
268 if (costBest < _num_points_test)
307 if ( j == _num_layers ) {
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;
327 Sample const & sample = (*oc)->environment();
332 while ( oc != end ) {
333 Sample const& sample = (*oc)->environment();
353 NicheMosaic::createModel( std::vector<ScalarVector> &model_min, std::vector<ScalarVector> &model_max,
const std::vector<Scalar> &delta )
359 while ( oc != end ) {
360 Sample const& sample = (*oc)->environment();
363 model_min[i][j] = sample[j] - delta[j];
364 model_max[i][j] = sample[j] + delta[j];
373 NicheMosaic::editModel( std::vector<ScalarVector> &model_min, std::vector<ScalarVector> &model_max,
const std::vector<Scalar> &delta,
size_t i_layer )
379 while ( oc != end ) {
380 Sample const& sample = (*oc)->environment();
382 model_min[i][i_layer] = sample[i_layer] - delta[i_layer];
383 model_max[i][i_layer] = sample[i_layer] + delta[i_layer];
396 int i, j, npresence = 0;
399 while ( it != last ) {
401 Sample const& sample = (*it)->environment();
408 if ( ( model_min[i][j] <= sample[j] ) && ( sample[j] <= model_max[i][j] ) )
414 if ( j == _num_layers ) {
428 int i, j, nabsence = 0;
434 while ( it_absence != last_absence )
436 Sample const& samp = (*it_absence)->environment();
442 if ( ( model_min[i][j] <= samp[j] ) && ( samp[j] <= model_max[i][j] ) )
448 if ( j == _num_layers )
452 if ( i == _num_points)
474 double min_percent = 0.12, max_percent = 0.4;
476 double new_percent, half_percent = (max_percent - min_percent) / 2 + min_percent;
480 r = random( 0, size );
481 new_percent = (max_percent - min_percent) * ( (
double) r / (double) size ) + min_percent;
485 new_percent = new_percent + half_percent - min_percent;
496 if (tabuDegree[i] > 0)
497 tabuDegree[i] = tabuDegree[i] - 1;
520 while ( it != last ) {
522 Sample const& sample = (*it)->environment();
525 for (i = 0; i < n; i++) {
535 if ( j == _num_layers ) {
558 size_t cost1, cost2, i_layer;
559 Scalar importance = 1.0, cost, deltaIni=0.4;
562 size_t nTabu = (size_t)floor(sqrt((
double)(
_num_layers)));
569 std::vector<ScalarVector> model_min(
_num_points );
570 std::vector<ScalarVector> model_max(
_num_points );
572 for (
unsigned int i = 0; i < model_min.size(); i++ ) {
579 delta[j] =
_delta[j] * deltaIni;
580 deltaBest[j] = delta[j];
599 Scalar deltaAux = delta[i_layer];
601 editModel( model_min, model_max, delta, i_layer );
608 tabuDegree[i_layer] = nTabu;
611 deltaBest[i_layer] = delta[i_layer];
619 if (tabuDegree[i_layer] == 0) {
621 tabuDegree[i_layer] = nTabu;
623 delta[i_layer] = deltaAux;
624 editModel( model_min, model_max, delta, i_layer );
640 config->addSubsection( model_config );
642 model_config->addNameValue(
"NumLayers",
_num_layers );
643 model_config->addNameValue(
"NumPoints",
_num_points );
648 model_config->addSubsection( rule_config );
653 rule_config->addNameValue(
"Min", min_best );
654 rule_config->addNameValue(
"Max", max_best );
667 _num_layers = model_config->getAttributeAsInt(
"NumLayers", 0 );
668 _num_points = model_config->getAttributeAsInt(
"NumPoints", 0 );
675 Configuration::subsection_list::iterator subelement = subelements.begin();
676 Configuration::subsection_list::iterator last_subelement = subelements.end();
680 for ( ; subelement != last_subelement; ++subelement ) {
682 if ( (*subelement)->getName() ==
"Rule" ) {
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() );
711 xmin = xmax = (*it)->x();
712 ymin = ymax = (*it)->y();
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();
722 deltax = xmax - xmin;
723 deltay = ymax - ymin;
725 it = occurrences->begin();
727 occurTransformx[i] = 100 * ( (*it)->x() - xmin ) / deltax;
728 occurTransformy[i] = 100 * ( (*it)->y() - ymin ) / deltay;
733 flag = 0, itrain=0, ktrain=0, ioccur=0;
735 it = occurrences->begin();
740 testId[ktrain] = ioccur;
746 for ( i = 0; i < ktrain; i++ ) {
748 x = occurTransformx[ioccur] - occurTransformx[itrain];
749 y = occurTransformy[ioccur] - occurTransformy[itrain];
750 dist = sqrt( (x*x) + (y*y) );
752 if ( dist < distLimit) {
761 testId[ktrain] = ioccur;
781 while( itt != finn ) {
784 Sample dif = occ->environment();
787 for(
unsigned int i=0; i<dif.
size(); i++) {
788 Scalar cutoff = deviation[i];
790 if ( dif[i] > cutoff || dif[i] < -cutoff ) {
814 Sample const & sample = (*oc)->environment();
820 while ( oc != end ) {
822 Sample const& sample = (*oc)->environment();
830 mean /=
Scalar( occs->numOccurrences() );
837 while ( oc != end ) {
838 Sample tmp( (*oc)->environment() );
size_t calculateCostAus(const std::vector< ScalarVector > &_model_min, const std::vector< ScalarVector > &_model_max)
static AlgMetadata metadata
std::vector< OccurrencePtr >::iterator iterator
void warn(const char *format,...)
'Warn' level.
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
double Scalar
Type of map values.
static AlgParamMetadata parameters[NUM_PARAM]
void computeMeanDeviation(const OccurrencesPtr &occs, Sample &mean, Sample &deviation)
static Log * instance()
Returns the instance pointer, creating the object on the first call.
size_t _num_points_absence_test
SamplerPtr createSampler(const EnvironmentPtr &env, const OccurrencesPtr &presence, const OccurrencesPtr &absence)
void error(const char *format,...)
'Error' level.
void saveBestModel(const std::vector< ScalarVector > &model_min, const std::vector< ScalarVector > &model_max)
void improveModel(const std::vector< Scalar > &deltaBest)
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)
void resize(std::size_t size)
void splitOccurrences(const OccurrencesPtr &occurrences, OccurrencesPtr &trainOccurrences, OccurrencesPtr &testOccurrences, double propTrain)
OM_ALG_DLL_EXPORT AlgMetadata const * algorithmMetadata()
std::vector< Scalar > ScalarVector
void renewTabuDegree(std::vector< size_t > &tabuDegree)
Scalar getValue(const Sample &x) const
void _setConfiguration(const ConstConfigurationPtr &)
OccurrencesPtr cleanOccurrences(const OccurrencesPtr &occurrences)
std::vector< ScalarVector > _model_max_best
std::vector< OccurrencePtr >::const_iterator const_iterator
size_t calculateCostPres(const std::vector< ScalarVector > &_model_min, const std::vector< ScalarVector > &_model_max)
std::vector< ScalarVector > _model_min_best
void _getConfiguration(ConfigurationPtr &) const
OccurrencesPtr _my_presences_test
OccurrencesPtr _my_presences
size_t getRandomLayerNumber()
Scalar getRandomPercent(const std::vector< Scalar > &delta, const size_t i_layer, size_t &cost1)