openModeller
Version 1.4.0
|
00001 00028 #ifndef _SAMPLERHH_ 00029 #define _SAMPLERHH_ 00030 00031 #include <openmodeller/om_defs.hh> 00032 #include <openmodeller/Occurrences.hh> 00033 #include <openmodeller/Occurrence.hh> 00034 #include <openmodeller/Environment.hh> 00035 #include <openmodeller/Configurable.hh> 00036 #include <openmodeller/Normalizable.hh> 00037 #include <openmodeller/Normalizer.hh> 00038 00039 #include <openmodeller/refcount.hh> 00040 00041 class ModelImpl; 00042 typedef ReferenceCountedPointer<ModelImpl> Model; 00043 00044 /****************************************************************/ 00045 /*************************** Sampler ****************************/ 00046 00047 class SamplerImpl; 00048 typedef ReferenceCountedPointer<SamplerImpl> SamplerPtr; 00049 typedef ReferenceCountedPointer<const SamplerImpl> ConstSamplerPtr; 00050 00055 dllexp SamplerPtr createSampler(const EnvironmentPtr& env, 00056 const OccurrencesPtr& presence, 00057 const OccurrencesPtr& absence = OccurrencesPtr() ); 00058 00059 dllexp SamplerPtr createSampler( const ConstConfigurationPtr& config ); 00060 00067 dllexp void splitSampler(const SamplerPtr& orig, SamplerPtr *train, SamplerPtr *test, double propTrain); 00068 00072 dllexp SamplerPtr cloneSampler(const SamplerPtr& orig); 00073 00081 class dllexp SamplerImpl : public Configurable, public Normalizable, private ReferenceCountedObject 00082 { 00083 friend class ReferenceCountedPointer<SamplerImpl>; 00084 friend class ReferenceCountedPointer<const SamplerImpl>; 00085 00086 public: 00087 00088 SamplerImpl(); 00089 SamplerImpl( const EnvironmentPtr& env, 00090 const OccurrencesPtr& presences, 00091 const OccurrencesPtr& absence, 00092 bool isNormalized=false); 00093 ~SamplerImpl(); 00094 00095 EnvironmentPtr getEnvironment() { return _env; } 00096 ConstEnvironmentPtr getEnvironment() const { return _env; } 00097 00098 OccurrencesPtr getPresences() { return _presence; } 00099 ConstOccurrencesPtr getPresences() const { return _presence; } 00100 00101 OccurrencesPtr getAbsences() { return _absence; } 00102 ConstOccurrencesPtr getAbsences() const { return _absence; } 00103 00108 void getMinMax( Sample * min, Sample * max ) const; 00109 00111 void normalize( Normalizer * normalizerPtr ); 00112 00115 bool isNormalized() const { return _normalized; } 00116 00118 void resetNormalization(); 00119 00121 int numIndependent() const; 00122 00126 int numDependent() const; 00127 00129 int numPresence() const; 00130 00132 int numAbsence() const; 00133 00145 ConstOccurrencePtr getOneSample( ) const; 00146 00150 ConstOccurrencePtr getPresence() const 00151 { return getRandomOccurrence( _presence ); } 00152 00156 ConstOccurrencePtr getPresence( int index ) const 00157 { return _presence->operator[]( index ); } 00158 00162 ConstOccurrencePtr getAbsence() const 00163 { return getRandomOccurrence( _absence ); } 00164 00168 ConstOccurrencePtr getAbsence( int index ) const 00169 { return _absence->operator[]( index ); } 00170 00174 OccurrencePtr generateRandomSample( Scalar abundance=1.0 ) const; 00175 00179 OccurrencePtr getPseudoAbsence() const; 00180 00184 OccurrencePtr getPseudoPresence() const; 00185 00189 OccurrencePtr getPseudoAbsence( const Model& model, const Scalar threshold ) const; 00190 00194 OccurrencePtr getPseudoPresence( const Model& model, const Scalar threshold ) const; 00195 00199 OccurrencePtr getPseudoAbsenceOutsideInterval( const Sample * minimum, const Sample * maximum ) const; 00200 00204 OccurrencePtr getPseudoPresenceInsideInterval( const Sample * minimum, const Sample * maximum ) const; 00205 00209 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; 00210 00214 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; 00215 00219 OccurrencesPtr getPseudoAbsences( const int& numPoints, const Sample * minimum, const Sample * maximum, const bool geoUnique=false, const bool envUnique=false, const int idSequenceStart=1) const; 00220 00224 OccurrencesPtr getPseudoPresences( const int& numPoints, const Sample * minimum, const Sample * maximum, const bool geoUnique=false, const bool envUnique=false, const int idSequenceStart=1) const; 00225 00229 int isCategorical( int i ); 00230 00234 void environmentallyUnique( ); 00235 00239 bool isEnvironmentallyUnique( const OccurrencesPtr& occurrences, const OccurrencePtr& point ) const; 00240 00246 void spatiallyUnique( ); 00247 00253 bool isSpatiallyUnique( const OccurrencesPtr& occurrences, const OccurrencePtr& point ) const; 00254 00255 ConfigurationPtr getConfiguration() const; 00256 00257 void setConfiguration ( const ConstConfigurationPtr& ); 00258 00259 void dump() const; 00260 00261 private: 00262 00263 ConstOccurrencePtr getRandomOccurrence( const OccurrencesPtr& occur ) const; 00264 00265 // this was former method ::initialize() 00266 void setEnvironmentInOccurrences(); 00267 00268 // Remove sample duplicates accross the environment given one of the occurrences 00269 // type (presence / absence) 00270 void environmentallyUnique( OccurrencesPtr& occurrencesPtr, const char *type ); 00271 00272 // Remove sample duplicates accross the geographic space given one of the occurrences 00273 // type (presence / absence) 00274 void spatiallyUnique( OccurrencesPtr& occurrencesPtr, const char *type ); 00275 00276 OccurrencesPtr _presence; 00277 OccurrencesPtr _absence; 00278 EnvironmentPtr _env; 00279 bool _normalized; 00280 }; 00281 00282 00283 #endif