62 samp->setConfiguration( config );
86 _presence( presence ),
89 _normalized( isNormalized )
134 config->addSubsection(
_env->getConfiguration() );
141 cfg->setName(
"Presence" );
142 config->addSubsection( cfg );
148 cfg->setName(
"Absence" );
149 config->addSubsection( cfg );
162 env->setConfiguration( env_config );
169 presence->setConfiguration( config->getSubsection(
"Presence" ) );
177 absence->setConfiguration( absence_config );
180 if ( ! presence->numOccurrences() ) {
182 std::string msg =
"No presence points available.\n";
191 int num_absences = 0;
195 num_absences = absence->numOccurrences();
228 allOccs->getMinMax( min, max );
243 std::string msg =
"Cannot normalize sampler without an Environment.\n";
253 _env->normalize( normalizerPtr );
260 _presence->normalize( normalizerPtr,
_env->numCategoricalLayers() );
265 _absence->normalize( normalizerPtr,
_env->numCategoricalLayers() );
277 _env->resetNormalization();
300 return _env->numLayers();
352 std::string msg =
"No presence points available for sampling.\n";
361 std::string msg =
"Cannot use zero presence points for sampling.\n";
391 std::string msg =
"Cannot generate random samples without an Environment object.\n";
444 prob = model->getValue( occ->environment() );
449 }
while ( ( prob >= threshold ) && ( loop < max_loop ) );
451 if ( loop == max_loop ) {
453 std::string msg =
"Exceeded maximum number of attempts to generate point outside model.\n";
482 prob = model->getValue( occ->environment() );
487 }
while ( ( prob < threshold ) && ( loop < max_loop ) );
489 if ( loop == max_loop ) {
491 std::string msg =
"Exceeded maximum number of attempts to generate point inside model.\n";
506 bool not_found =
true;
518 x = occ->environment();
520 for (
unsigned int i = 0; i < x.
size(); i++ ) {
525 if ( x[i] < (*minimum)[i] || x[i] > (*maximum)[i] ) {
534 }
while ( ( not_found ) && ( loop < max_loop ) );
536 if ( loop == max_loop ) {
538 std::string msg =
"Exceeded maximum number of attempts to generate point outside interval.\n";
553 bool not_found =
true;
565 x = occ->environment();
567 for (
unsigned int i = 0; i < x.
size(); i++ ) {
572 if ( x[i] >= (*minimum)[i] && x[i] <= (*maximum)[i] ) {
581 }
while ( ( not_found ) && ( loop < max_loop ) );
583 if ( loop == max_loop ) {
585 std::string msg =
"Exceeded maximum number of attempts to generate point inside interval.\n";
625 std::ostringstream oss;
626 oss << idSequenceStart+i;
627 point->setId( oss.str() );
628 occurrences->insert( point );
638 std::ostringstream oss;
639 oss << idSequenceStart+i;
640 point->setId( oss.str() );
641 occurrences->insert( point );
654 std::ostringstream oss;
655 oss << idSequenceStart+i;
656 point->setId( oss.str() );
657 occurrences->insert( point );
663 std::ostringstream oss;
664 oss << idSequenceStart+i;
665 point->setId( oss.str() );
666 occurrences->insert( point );
671 }
while ( i < numPoints );
706 std::ostringstream oss;
707 oss << idSequenceStart+i;
708 point->setId( oss.str() );
709 occurrences->insert( point );
719 std::ostringstream oss;
720 oss << idSequenceStart+i;
721 point->setId( oss.str() );
722 occurrences->insert( point );
735 std::ostringstream oss;
736 oss << idSequenceStart+i;
737 point->setId( oss.str() );
738 occurrences->insert( point );
744 std::ostringstream oss;
745 oss << idSequenceStart+i;
746 point->setId( oss.str() );
747 occurrences->insert( point );
752 }
while ( i < numPoints );
780 std::ostringstream oss;
781 oss << idSequenceStart+i;
782 point->setId( oss.str() );
783 occurrences->insert( point );
793 std::ostringstream oss;
794 oss << idSequenceStart+i;
795 point->setId( oss.str() );
796 occurrences->insert( point );
809 std::ostringstream oss;
810 oss << idSequenceStart+i;
811 point->setId( oss.str() );
812 occurrences->insert( point );
818 std::ostringstream oss;
819 oss << idSequenceStart+i;
820 point->setId( oss.str() );
821 occurrences->insert( point );
826 }
while ( i < numPoints );
854 std::ostringstream oss;
855 oss << idSequenceStart+i;
856 point->setId( oss.str() );
857 occurrences->insert( point );
867 std::ostringstream oss;
868 oss << idSequenceStart+i;
869 point->setId( oss.str() );
870 occurrences->insert( point );
883 std::ostringstream oss;
884 oss << idSequenceStart+i;
885 point->setId( oss.str() );
886 occurrences->insert( point );
892 std::ostringstream oss;
893 oss << idSequenceStart+i;
894 point->setId( oss.str() );
895 occurrences->insert( point );
900 }
while ( i < numPoints );
912 return _env->isCategorical( i );
944 if ( ! ( occurrencesPtr && occurrencesPtr->numOccurrences() ) ) {
952 while ( it != last ) {
954 Sample sample =
_env->getUnnormalized( (*it)->x(), (*it)->y() );
958 while ( next != last ) {
960 Sample nextSample =
_env->getUnnormalized( (*next)->x(), (*next)->y() );
962 if ( sample.
equals( nextSample ) ) {
964 Log::instance()->
info(
"%s Point \"%s\" at (%f,%f) has no unique environment. It will be discarded.\n", type, ((*next)->id()).c_str(), (*next)->x(), (*next)->y() );
967 next = occurrencesPtr->erase( next );
968 last = occurrencesPtr->end();
971 (*it)->setAbundance( (*it)->abundance() + 1 );
1007 if ( ! ( occurrencesPtr && occurrencesPtr->numOccurrences() ) ) {
1017 mask =
_env->getLayer( 0 );
1023 while ( it != last ) {
1027 mask->
getRowColumn( (*it)->x(), (*it)->y(), &row, &col );
1031 while ( next != last ) {
1033 int nextRow, nextCol;
1035 mask->
getRowColumn( (*next)->x(), (*next)->y(), &nextRow, &nextCol );
1037 if ( row == nextRow && col == nextCol ) {
1039 Log::instance()->
info(
"%s Point \"%s\" at (%f,%f) has no unique geography. It will be discarded.\n", type, ((*next)->id()).c_str(), (*next)->x(), (*next)->y() );
1042 next = occurrencesPtr->erase( next );
1043 last = occurrencesPtr->end();
1046 (*it)->setAbundance( (*it)->abundance() + 1 );
1067 if ( ! ( occurrences && occurrences->numOccurrences() ) ) {
1075 Sample sample =
_env->getUnnormalized( point->x(), point->y() );
1077 while ( it != last ) {
1079 Sample nextSample =
_env->getUnnormalized( (*it)->x(), (*it)->y() );
1081 if ( sample.
equals( nextSample ) ) {
1099 if ( ! ( occurrences && occurrences->numOccurrences() ) ) {
1109 mask =
_env->getLayer( 0 );
1116 mask->
getRowColumn( point->x(), point->y(), &row, &col );
1118 while ( it != last ) {
1120 int next_row, next_col;
1122 mask->
getRowColumn( (*it)->x(), (*it)->y(), &next_row, &next_col );
1124 if ( row == next_row && col == next_col ) {
1148 return occur->getRandom();
1185 test_presence =
new OccurrencesImpl( presence->label(), presence->coordSystem() );
1187 train_presence =
new OccurrencesImpl( presence->label(), presence->coordSystem() );
1200 test_absence =
new OccurrencesImpl( absence->label(), absence->coordSystem() );
1202 train_absence =
new OccurrencesImpl( absence->label(), absence->coordSystem() );
1208 train_presence, train_absence,
1209 orig->isNormalized() );
1212 test_presence, test_absence,
1213 orig->isNormalized() );
1224 if ( orig->numPresence() ) {
1226 presences = orig->getPresences()->clone();
1229 if ( orig->numAbsence() ) {
1231 absences = orig->getAbsences()->clone();
1238 return fresh_sampler;
OccurrencePtr getPseudoAbsence() const
OccurrencePtr generateRandomSample(Scalar abundance=1.0) const
void resetNormalization()
std::vector< OccurrencePtr >::iterator iterator
ConstOccurrencePtr getAbsence() const
void getMinMax(Sample *min, Sample *max) const
double Scalar
Type of map values.
OccurrencesPtr getPseudoAbsences(const int &numPoints, const Model &model, const Scalar threshold=0.5, const bool geoUnique=false, const bool envUnique=false, const int idSequenceStart=1) const
SamplerPtr cloneSampler(const SamplerPtr &orig)
static Log * instance()
Returns the instance pointer, creating the object on the first call.
bool equals(const Sample &) const
EnvironmentPtr createEnvironment(const std::vector< std::string > &categs, const std::vector< std::string > &maps, const std::string &mask_file)
SamplerPtr createSampler(const EnvironmentPtr &env, const OccurrencesPtr &presence, const OccurrencesPtr &absence)
ConstOccurrencePtr getPresence() const
void error(const char *format,...)
'Error' level.
ConstOccurrencePtr getOneSample() const
bool isSpatiallyUnique(const OccurrencesPtr &occurrences, const OccurrencePtr &point) const
ConstOccurrencePtr getRandomOccurrence(const OccurrencesPtr &occur) const
OccurrencePtr getPseudoAbsenceOutsideInterval(const Sample *minimum, const Sample *maximum) const
void splitSampler(const SamplerPtr &orig, SamplerPtr *train, SamplerPtr *test, double propTrain)
ConfigurationPtr getConfiguration() const
ReferenceCountedPointer< SamplerImpl > SamplerPtr
void setConfiguration(const ConstConfigurationPtr &)
void splitOccurrences(const OccurrencesPtr &occurrences, OccurrencesPtr &trainOccurrences, OccurrencesPtr &testOccurrences, double propTrain)
void setEnvironmentInOccurrences()
OccurrencesPtr getPseudoPresences(const int &numPoints, const Model &model, const Scalar threshold=0.5, const bool geoUnique=false, const bool envUnique=false, const int idSequenceStart=1) const
void info(const char *format,...)
'Info' level.
OccurrencePtr getPseudoPresenceInsideInterval(const Sample *minimum, const Sample *maximum) const
void normalize(Normalizer *normalizerPtr)
double Coord
Type of map coordinates.
bool isEnvironmentallyUnique(const OccurrencesPtr &occurrences, const OccurrencePtr &point) const
int numIndependent() const
void environmentallyUnique()
void debug(const char *format,...)
'Debug' level.
int getRowColumn(Coord x, Coord y, int *row, int *col)
OccurrencePtr getPseudoPresence() const