openModeller
Version 1.4.0
|
00001 00027 #ifndef NICHEMOSAIC_HH 00028 #define NICHEMOSAIC_HH 00029 00030 #include <openmodeller/om.hh> 00031 #include <openmodeller/Exceptions.hh> 00032 00033 typedef std::vector<Scalar> ScalarVector; 00034 00035 class NicheMosaic : public AlgorithmImpl 00036 { 00037 private: 00038 00039 int _num_iterations; // number of iterations 00040 int _num_points; // number of points. 00041 size_t _num_points_test; // number of points (test). 00042 size_t _num_points_absence_test; // number of points (absence test). 00043 int _num_layers; // number of layers. 00044 Sample _minimum; // minimum of sampled points. 00045 Sample _maximum; // maximum of sampled points. 00046 Sample _delta; // delta of sampled points. 00047 OccurrencesPtr _my_presences; // occurrence points of species. 00048 OccurrencesPtr _my_presences_test; // occurrence points of species (test). 00049 OccurrencesPtr _my_absence_test; // occurrence points of species (absence test). 00050 Scalar _bestCost; // best cost 00051 bool _done; // is true if the algorithm is finished. 00052 float _progress; // iteration progress 00053 SamplerPtr _sampp; 00054 std::vector<ScalarVector> _model_min_best; 00055 std::vector<ScalarVector> _model_max_best; 00056 00057 protected: 00058 00059 void _getConfiguration( ConfigurationPtr& ) const; 00060 void _setConfiguration( const ConstConfigurationPtr & ); 00061 00062 public: 00063 00064 NicheMosaic(); //constructor 00065 ~NicheMosaic(); //destructor 00066 00067 int initialize(); 00068 int iterate(); 00069 int done() const { return _done; } 00070 float getProgress() const; 00071 00072 Scalar getValue( const Sample& x ) const; 00073 00074 //set minimum, maximum and delta for each layer. 00075 int setMinMaxDelta(); 00076 00077 //create rules 00078 void createModel( std::vector<ScalarVector> &_model_min, std::vector<ScalarVector> &_model_max, const std::vector<Scalar> &delta ); 00079 00080 //edit rules 00081 void editModel( std::vector<ScalarVector> &model_min, std::vector<ScalarVector> &model_max, const std::vector<Scalar> &delta, size_t i_layer ); 00082 00083 //verify test data for presence 00084 size_t calculateCostPres( const std::vector<ScalarVector> &_model_min, const std::vector<ScalarVector> &_model_max ); 00085 00086 //verify test data for absence 00087 size_t calculateCostAus( const std::vector<ScalarVector> &_model_min, const std::vector<ScalarVector> &_model_max ); 00088 00089 //generate random layer number. 00090 size_t getRandomLayerNumber(); 00091 00092 //return random percent. 00093 Scalar getRandomPercent(const std::vector<Scalar> &delta, const size_t i_layer, size_t &cost1); 00094 00095 //renew tabu degree list 00096 void renewTabuDegree(std::vector<size_t> &tabuDegree); 00097 00098 //save best model 00099 void saveBestModel(const std::vector<ScalarVector> &model_min, const std::vector<ScalarVector> &model_max); 00100 00101 //improve model 00102 void improveModel(const std::vector<Scalar> &deltaBest); 00103 00104 //Find solution. 00105 void findSolution(size_t &costBest, std::vector<Scalar> &deltaBest, int &bestIter, size_t &bestCost2); 00106 00107 //remove discrepancy points 00108 OccurrencesPtr cleanOccurrences( const OccurrencesPtr& occurrences ); 00109 00110 //compute mean and deviation 00111 void computeMeanDeviation( const OccurrencesPtr& occs, Sample& mean, Sample& deviation ); 00112 00113 }; 00114 00115 00116 #endif 00117