openModeller  Version 1.5.0
Occurrences.hh
Go to the documentation of this file.
1 
29 #ifndef _OCCURRENCESHH_
30 #define _OCCURRENCESHH_
31 
32 #include <openmodeller/om_defs.hh>
38 #include <openmodeller/refcount.hh>
40 
41 #include <vector>
42 #include <string>
43 
44 /****************************************************************/
45 /************************* Occurrences **************************/
46 
50 
51 typedef std::vector<Scalar> ScalarVector;
52 
59 dllexp void splitOccurrences(const OccurrencesPtr& occurrences,
60  OccurrencesPtr& trainOccurrences,
61  OccurrencesPtr& testOccurrences,
62  double propTrain);
63 
69 dllexp void splitOccurrences(const OccurrencesPtr& occurrences,
70  OccurrencesPtr& trainOccurrences,
71  OccurrencesPtr& testOccurrences);
72 
73 
78 class dllexp OccurrencesImpl : public Configurable, private ReferenceCountedObject
79 {
82 
83 public:
84 
85  typedef std::vector<OccurrencePtr>::const_iterator const_iterator;
86  typedef std::vector<OccurrencePtr>::iterator iterator;
87 
91  inline OccurrencesImpl( double default_abundance ) :
92  default_abundance_( default_abundance ),
93  label_( ),
94  cs_( GeoTransform::getDefaultCS() ),
95  gt_( 0 ),
96  occur_( )
97  {
98  initGeoTransform();
99  };
100 
106  inline OccurrencesImpl( const std::string& label,
107  const std::string& coord_system=GeoTransform::getDefaultCS() ) :
108  default_abundance_( 0.0 ),
109  label_( label ),
110  cs_( coord_system ),
111  gt_( 0 ),
112  occur_()
113  {
114  initGeoTransform();
115  };
116 
117  ~OccurrencesImpl();
118 
120  OccurrencesImpl* clone() const;
121 
123  void reserve( int estimate ) { occur_.reserve( estimate ); }
124 
126  char const * label() const { return label_.c_str(); }
127 
129  char const * coordSystem() const { return cs_.c_str(); }
130 
131  /* Indicates whether the object contains environmental samples
132  * that can be used instead of a full blown Environment object
133  */
134  bool hasEnvironment() const;
135 
136  /* Dimension of environmental space in samples stored in this object
137  */
138  int dimension() const;
139 
142  void setLabel( const std::string& label );
143 
149  void setCoordinateSystem( const std::string& cs );
150 
165  void createOccurrence( const std::string& id,
166  Coord longitude, Coord latitude,
167  Scalar error, Scalar abundance,
168  int num_attributes = 0, Scalar *attributes = 0,
169  int num_env = 0, Scalar *env = 0 );
170 
174  void createOccurrence( const std::string& id,
175  Coord longitude, Coord latitude,
176  Scalar error, Scalar abundance,
177  std::vector<double> attributes,
178  std::vector<double> env);
179 
181  void insert( const OccurrencePtr& );
182 
184  iterator erase( const iterator& it );
185 
192  int numAttributes() const { return 0; }
193 
195  int numOccurrences() const { return occur_.size(); }
196 
198  bool isEmpty() const { return occur_.empty(); }
199 
201  ConstOccurrencePtr operator[]( int i ) const { return occur_[i]; }
202 
204  const_iterator begin() const { return occur_.begin(); }
205  const_iterator end() const { return occur_.end(); }
206  iterator begin() { return occur_.begin(); }
207  iterator end() { return occur_.end(); }
208 
210  ConstOccurrencePtr getRandom() const;
211 
213  void getMinMax( Sample * min, Sample * max ) const;
214 
216  void normalize( Normalizer * normalizerPtr, size_t categoricalThreshold=0 );
217 
219  void resetNormalization();
220 
223  void setEnvironment( const EnvironmentPtr& env,
224  const char *type = "Sample" );
225 
230  void appendFrom(const OccurrencesPtr& source);
231 
233  std::vector<ScalarVector> getEnvironmentMatrix();
234 
236  void dump( std::string msg="" ) const;
237 
238  virtual ConfigurationPtr getConfiguration() const;
239 
240  virtual void setConfiguration( const ConstConfigurationPtr & );
241 
242 private:
243 
244  void initGeoTransform();
245 
247 
248  std::string label_; // Label for the list of occurrences (e.g. species name)
249  std::string cs_; // Coordinate system name
250 
251  GeoTransform *gt_; // Object to transform between different coordinate systems
252 
253  std::vector< OccurrencePtr > occur_; // Occurrences
254 };
255 
256 
257 #endif
ReferenceCountedPointer< OccurrencesImpl > OccurrencesPtr
Definition: Occurrences.hh:47
std::vector< OccurrencePtr >::iterator iterator
Definition: Occurrences.hh:86
bool isEmpty() const
Definition: Occurrences.hh:198
double Scalar
Type of map values.
Definition: om_defs.hh:39
const_iterator begin() const
Definition: Occurrences.hh:204
virtual ConfigurationPtr getConfiguration() const =0
void reserve(int estimate)
Definition: Occurrences.hh:123
OccurrencesImpl(double default_abundance)
Definition: Occurrences.hh:91
OccurrencesImpl(const std::string &label, const std::string &coord_system=GeoTransform::getDefaultCS())
Definition: Occurrences.hh:106
std::vector< OccurrencePtr > occur_
Definition: Occurrences.hh:253
std::string label_
Definition: Occurrences.hh:248
const_iterator end() const
Definition: Occurrences.hh:205
double default_abundance_
Definition: Occurrences.hh:246
std::vector< Scalar > ScalarVector
Definition: Occurrences.hh:51
GeoTransform * gt_
Definition: Occurrences.hh:251
static char const * getDefaultCS()
ConstOccurrencePtr operator[](int i) const
Definition: Occurrences.hh:201
iterator end()
Definition: Occurrences.hh:207
ReferenceCountedPointer< const OccurrencesImpl > ConstOccurrencesPtr
Definition: Occurrences.hh:49
int numAttributes() const
Definition: Occurrences.hh:192
virtual void setConfiguration(const ConstConfigurationPtr &)=0
iterator begin()
Definition: Occurrences.hh:206
double Coord
Type of map coordinates.
Definition: om_defs.hh:38
std::vector< OccurrencePtr >::const_iterator const_iterator
Definition: Occurrences.hh:85
char const * coordSystem() const
Definition: Occurrences.hh:129
dllexp void splitOccurrences(const OccurrencesPtr &occurrences, OccurrencesPtr &trainOccurrences, OccurrencesPtr &testOccurrences, double propTrain)
char const * label() const
Definition: Occurrences.hh:126
std::string cs_
Definition: Occurrences.hh:249
int min(int v1, int v2)
Definition: rules_base.cpp:56
Definition: Sample.hh:25
int numOccurrences() const
Definition: Occurrences.hh:195
static char error[256]
Definition: FileParser.cpp:42