openModeller  Version 1.5.0
environmental_distance.hh
Go to the documentation of this file.
1 //
2 // Generic environmental distance algorithm
3 //
4 // Description: Generic algorithm based on distances.
5 //
6 // Author: Danilo J. S. Bellini <danilo.estagio@gmail.com>
7 // Copyright: See COPYING file that comes with this distribution
8 // Date: 2006-09-18
9 //
10 
11 #ifndef _DISTANCESH_
12 #define _DISTANCESH_
13 
14 #include <openmodeller/om.hh>
15 
16 // Matrix burocracy
17 #include "matrix.hh"
18 #ifndef _NO_NAMESPACE
19 using namespace std;
20 using namespace math;
21 #define STD std
22 #else
23 #define STD
24 #endif
25 #ifndef _NO_EXCEPTION
26 # define TRYBEGIN() try {
27 # define CATCHERROR() } catch (const STD::exception& e) { \
28  cerr << "Error: " << e.what() << endl; }
29 #else
30 # define TRYBEGIN()
31 # define CATCHERROR()
32 #endif
33 typedef matrix<Scalar> Matrix; // Now we have the matrix free for use
34 
35 #define FIRST_DISTANCE_TYPE 1
36 #define AMOUNT_DISTANCE_TYPES 4
37 
39 
40  public: // All methods here are inherited from AlgorithmImpl
41  EnvironmentalDistance(); // Constructor, don't have init algorithm routines
42  ~EnvironmentalDistance(); // Destructor
43 
44  int initialize(); // Called by oM to initialize the algorithm
45  int done() const { return _done; } // Tell oM when the algorithm finished its work
46  Scalar getValue(const Sample& x) const; // Returns the occurence probability
47 
48  private:
49  // Common-use attributes
50  bool _done; // Flag to indicate when the work is finished;
51  int _layer_count; // Amount of layers used (dimension of environmental space)
52  int _presence_count; // Amount of presence points
53  std::vector<Sample> _presence_points; // Have the presence points data
54 
55  // Parameters
59 
60  bool _use_chisq; // Flag indicating when chi-square probabilities should be returned (used only for Mahalanobis distance!)
61 
62  // Algorithm-specific methods and attributes
63  void _calc_covariance_matrix();
64  inline Scalar _distance(const Sample& x, const Sample& y) const;
65  bool _init_distance_type();
66  Matrix * _cov_matrix; // Covariance matrix
67  Matrix * _cov_matrix_inv; // Inverse of covariance matrix
68  Sample _average_point; // Average of all presence points
69 
70  // Alias for the distance types
71  typedef enum{
72  EuclideanDistance = FIRST_DISTANCE_TYPE,
76  } DistanceType;
77 
91  Scalar _poz(Scalar z) const;
92 
106  Scalar _pochisq(Scalar x, int df) const;
107 
108  protected:
109  virtual void _getConfiguration(ConfigurationPtr&) const;
110  virtual void _setConfiguration(const ConstConfigurationPtr&);
111 };
112 
113 #endif
matrix< Scalar > Matrix
double Scalar
Type of map values.
Definition: om_defs.hh:39
#define FIRST_DISTANCE_TYPE
std::vector< Sample > _presence_points
Definition: Sample.hh:25