openModeller
Version 1.4.0
|
00001 /* ************************************** 00002 * GARP Modeling Package 00003 * 00004 * ************************************** 00005 * 00006 * Copyright (c), The Center for Research, University of Kansas, 2385 Irving Hill Road, Lawrence, KS 66044-4755, USA. 00007 * Copyright (C), David R.B. Stockwell of Symbiotik Pty. Ltd. 00008 * 00009 * This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the license that is distributed with the software. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * license.txt file included with this software for more details. 00016 */ 00017 00018 // GarpAlgorithm.h : Declaration of the Algorithm class 00019 00020 #ifndef __GARPALGORITHM_H_ 00021 #define __GARPALGORITHM_H_ 00022 00023 #include "RuleSet.h" 00024 #include "Utilities.h" 00025 00026 #include <openmodeller/om.hh> 00027 00028 class EnvCellSet; 00029 00030 // ======================================================================== 00031 // GarpAlgorithm 00032 // ======================================================================== 00033 class GarpAlgorithm : public AlgorithmImpl 00034 { 00035 private: 00036 // current ruleset 00037 RuleSet objNew; 00038 00039 // best model so far 00040 RuleSet objBest; 00041 00042 // data points used for training 00043 EnvCellSet * objTrainSet; 00044 00045 00046 public: 00047 // OM Algorithm virtual methods 00048 int initialize(); 00049 int iterate(); 00050 int done() const; 00051 float getProgress() const; 00052 Scalar getValue( const Sample& x ) const; 00053 int getConvergence( Scalar * const val ) const; 00054 int getGeneration() { return Gen; } 00055 00056 00057 GarpAlgorithm(); 00058 virtual ~GarpAlgorithm(); 00059 00060 RuleSet * getBestSet() { return &objBest; } 00061 void getInitialModel(int intSize, EnvCellSet * objTrainSet); 00062 void updateRuleUsage(); 00063 00064 int ruleSetSize() 00065 { return objBest.size(); } 00066 00067 char * getParameter2(char * sParamName); 00068 void setParameter(char * sParamName, char * sParamValue); 00069 00070 char * getSelectedLayersAsString(); 00071 void setSelectedLayers(char * strParamValue); 00072 00073 protected: 00074 void _getConfiguration( ConfigurationPtr& ) const; 00075 void _setConfiguration( const ConstConfigurationPtr& ); 00076 00077 private: 00078 // private methods 00079 void initializeProperties(); 00080 00081 // Garp algorithm 00082 void DisplayStatus(); 00083 void colonize(RuleSet * objRules, EnvCellSet * objTrainSet, int intNewRules); 00084 void evaluate(RuleSet * objRules, EnvCellSet * objTrainSet); 00085 int saveRule(int iIndex); 00086 void measure(); 00087 double converge(); 00088 void select(); 00089 00090 void mutate(); 00091 void crossover(); 00092 void join(); 00093 00094 void updateHeuOpPerformance(char chrType); 00095 00096 void generate(EnvCellSet * objTestDataset); 00097 00098 // deprecated methods 00099 void saveBestRules(RuleSet * toRuleSet, RuleSet * fromRuleSet); 00100 void concatenateRuleSets(RuleSet * toRuleSet, RuleSet * fromRuleSet); 00101 00102 00103 private: 00104 00105 long lVersion; 00106 00107 // flags 00108 int Sigflag; 00109 int Postflag; 00110 int Compflag; 00111 int Adjustflag; 00112 00113 int BioclimOnlyFlag; 00114 int LogitOnlyFlag; 00115 int RangeRuleFlag; 00116 int NegatedRuleFlag; 00117 int AtomicRuleFlag; 00118 int LogitRuleFlag; 00119 00120 bool bGeneIsActive[MAX_ENV_LAYERS]; 00121 int iGeneIndex[MAX_ENV_LAYERS]; 00122 int iActiveGenes; 00123 00124 // timming 00125 int iCPUTime; // accumulated CPU time used for processing the model (in miliseconds) 00126 00127 // algorithm variables 00128 int Resamples; 00129 00130 double Accuracylimit; // The minimium post prob of a rule 00131 double MinUsage; 00132 double Mortality; 00133 00134 int Totalgens; // generations per experiment 00135 int Totaltrials; // trials per experiment 00136 int Popsize; // population size 00137 double C_rate; // crossover rate 00138 double M_rate; // mutation rate 00139 double J_rate; // join rate 00140 double I_rate; 00141 double Gapsize; // fraction of pop generated from archive 00142 int Trials; // trial counter 00143 int Maxspin; // max gens without evals 00144 double Resampling_f; 00145 double Significance; // the minimum level for inc in best 00146 double Conv_limit; // the fractional addition of rules 00147 double Cutval; 00148 00149 00150 // data collection and loop control variables 00151 double Ave_current_perf;/* ave perf in current generation */ 00152 double Best; /* best performance seen so far */ 00153 double Best_current_perf;/* best perf in current generation */ 00154 int Best_guy; /* index of best_current_perf */ 00155 int Conv; /* number of partially coverged genes */ 00156 mutable bool Doneflag; /* set when termination conditions hold */ 00157 int Experiment; /* experiment counter */ 00158 int Gen; /* generation counter */ 00159 int Lost; /* number of totally coverged positions */ 00160 int Spin; /* number of gens since eval occurred */ 00161 double Worst; /* worst performance seen so far */ 00162 double Worst_current_perf;/* worst perf in current generation */ 00163 int Heuristic[2][5]; /* successes of heuristic operators */ 00164 double Convergence; /* the stability of rule set */ 00165 int Improvements; /* the number of times the best set has been 00166 improved by addition or alteration */ 00167 int Resample; 00168 00169 mutable float _maxProgress; 00170 00171 }; 00172 00173 // ======================================================================== 00174 00175 #endif //__GarpAlgorithm_H_