openModeller  Version 1.5.0
Sampler.hh
Go to the documentation of this file.
1 
28 #ifndef _SAMPLERHH_
29 #define _SAMPLERHH_
30 
31 #include <openmodeller/om_defs.hh>
38 
39 #include <openmodeller/refcount.hh>
40 
41 class ModelImpl;
43 
44 /****************************************************************/
45 /*************************** Sampler ****************************/
46 
50 
55 dllexp SamplerPtr createSampler(const EnvironmentPtr& env,
56  const OccurrencesPtr& presence,
57  const OccurrencesPtr& absence = OccurrencesPtr() );
58 
59 dllexp SamplerPtr createSampler( const ConstConfigurationPtr& config );
60 
67 dllexp void splitSampler(const SamplerPtr& orig, SamplerPtr *train, SamplerPtr *test, double propTrain);
68 
72 dllexp SamplerPtr cloneSampler(const SamplerPtr& orig);
73 
81 class dllexp SamplerImpl : public Configurable, public Normalizable, private ReferenceCountedObject
82 {
84  friend class ReferenceCountedPointer<const SamplerImpl>;
85 
86 public:
87 
88  SamplerImpl();
89  SamplerImpl( const EnvironmentPtr& env,
90  const OccurrencesPtr& presences,
91  const OccurrencesPtr& absence,
92  bool isNormalized=false);
93  ~SamplerImpl();
94 
95  EnvironmentPtr getEnvironment() { return _env; }
96  ConstEnvironmentPtr getEnvironment() const { return _env; }
97 
98  OccurrencesPtr getPresences() { return _presence; }
99  ConstOccurrencesPtr getPresences() const { return _presence; }
100 
101  OccurrencesPtr getAbsences() { return _absence; }
102  ConstOccurrencesPtr getAbsences() const { return _absence; }
103 
108  void getMinMax( Sample * min, Sample * max ) const;
109 
111  void normalize( Normalizer * normalizerPtr );
112 
115  bool isNormalized() const { return _normalized; }
116 
118  void resetNormalization();
119 
121  int numIndependent() const;
122 
126  int numDependent() const;
127 
129  int numPresence() const;
130 
132  int numAbsence() const;
133 
145  ConstOccurrencePtr getOneSample( ) const;
146 
151  { return getRandomOccurrence( _presence ); }
152 
156  ConstOccurrencePtr getPresence( int index ) const
157  { return _presence->operator[]( index ); }
158 
163  { return getRandomOccurrence( _absence ); }
164 
168  ConstOccurrencePtr getAbsence( int index ) const
169  { return _absence->operator[]( index ); }
170 
174  OccurrencePtr generateRandomSample( Scalar abundance=1.0 ) const;
175 
179  OccurrencePtr getPseudoAbsence() const;
180 
184  OccurrencePtr getPseudoPresence() const;
185 
189  OccurrencePtr getPseudoAbsence( const Model& model, const Scalar threshold ) const;
190 
194  OccurrencePtr getPseudoPresence( const Model& model, const Scalar threshold ) const;
195 
199  OccurrencePtr getPseudoAbsenceOutsideInterval( const Sample * minimum, const Sample * maximum ) const;
200 
204  OccurrencePtr getPseudoPresenceInsideInterval( const Sample * minimum, const Sample * maximum ) const;
205 
209  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;
210 
214  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;
215 
219  OccurrencesPtr getPseudoAbsences( const int& numPoints, const Sample * minimum, const Sample * maximum, const bool geoUnique=false, const bool envUnique=false, const int idSequenceStart=1) const;
220 
224  OccurrencesPtr getPseudoPresences( const int& numPoints, const Sample * minimum, const Sample * maximum, const bool geoUnique=false, const bool envUnique=false, const int idSequenceStart=1) const;
225 
229  int isCategorical( int i );
230 
234  void environmentallyUnique( );
235 
239  bool isEnvironmentallyUnique( const OccurrencesPtr& occurrences, const OccurrencePtr& point ) const;
240 
246  void spatiallyUnique( );
247 
253  bool isSpatiallyUnique( const OccurrencesPtr& occurrences, const OccurrencePtr& point ) const;
254 
256 
257  void setConfiguration ( const ConstConfigurationPtr& );
258 
259  void dump() const;
260 
261 private:
262 
263  ConstOccurrencePtr getRandomOccurrence( const OccurrencesPtr& occur ) const;
264 
265  // this was former method ::initialize()
266  void setEnvironmentInOccurrences();
267 
268  // Remove sample duplicates accross the environment given one of the occurrences
269  // type (presence / absence)
270  void environmentallyUnique( OccurrencesPtr& occurrencesPtr, const char *type );
271 
272  // Remove sample duplicates accross the geographic space given one of the occurrences
273  // type (presence / absence)
274  void spatiallyUnique( OccurrencesPtr& occurrencesPtr, const char *type );
275 
280 };
281 
282 
283 #endif
EnvironmentPtr getEnvironment()
Definition: Sampler.hh:95
ReferenceCountedPointer< OccurrencesImpl > OccurrencesPtr
Definition: Occurrences.hh:47
ConstOccurrencePtr getAbsence() const
Definition: Sampler.hh:162
double Scalar
Type of map values.
Definition: om_defs.hh:39
OccurrencesPtr getPresences()
Definition: Sampler.hh:98
virtual ConfigurationPtr getConfiguration() const =0
OccurrencesPtr getAbsences()
Definition: Sampler.hh:101
ConstEnvironmentPtr getEnvironment() const
Definition: Sampler.hh:96
OccurrencesPtr _presence
Definition: Sampler.hh:276
dllexp void splitSampler(const SamplerPtr &orig, SamplerPtr *train, SamplerPtr *test, double propTrain)
Definition: Sampler.cpp:1171
ConstOccurrencePtr getPresence() const
Definition: Sampler.hh:150
EnvironmentPtr _env
Definition: Sampler.hh:278
dllexp SamplerPtr cloneSampler(const SamplerPtr &orig)
Definition: Sampler.cpp:1219
ConstOccurrencePtr getAbsence(int index) const
Definition: Sampler.hh:168
ReferenceCountedPointer< const SamplerImpl > ConstSamplerPtr
Definition: Sampler.hh:49
ReferenceCountedPointer< SamplerImpl > SamplerPtr
Definition: Sampler.hh:47
ConstOccurrencesPtr getPresences() const
Definition: Sampler.hh:99
ConstOccurrencePtr getPresence(int index) const
Definition: Sampler.hh:156
bool isNormalized() const
Definition: Sampler.hh:115
virtual void getMinMax(Sample *min, Sample *max) const =0
OccurrencesPtr _absence
Definition: Sampler.hh:277
virtual void setConfiguration(const ConstConfigurationPtr &)=0
virtual void normalize(Normalizer *normalizerPtr)=0
ReferenceCountedPointer< ModelImpl > Model
Definition: Sampler.hh:41
ConstOccurrencesPtr getAbsences() const
Definition: Sampler.hh:102
dllexp SamplerPtr createSampler(const EnvironmentPtr &env, const OccurrencesPtr &presence, const OccurrencesPtr &absence=OccurrencesPtr())
Definition: Sampler.cpp:52
bool _normalized
Definition: Sampler.hh:279
int min(int v1, int v2)
Definition: rules_base.cpp:56
Definition: Sample.hh:25