openModeller  Version 1.5.0
GarpAlgorithm.h
Go to the documentation of this file.
1 /* **************************************
2  * GARP Modeling Package
3  *
4  * **************************************
5  *
6  * Copyright (c), The Center for Research, University of Kansas, 2385 Irving Hill Road, Lawrence, KS 66044-4755, USA.
7  * Copyright (C), David R.B. Stockwell of Symbiotik Pty. Ltd.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the license that is distributed with the software.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * license.txt file included with this software for more details.
16  */
17 
18 // GarpAlgorithm.h : Declaration of the Algorithm class
19 
20 #ifndef __GARPALGORITHM_H_
21 #define __GARPALGORITHM_H_
22 
23 #include "RuleSet.h"
24 #include "Utilities.h"
25 
26 #include <openmodeller/om.hh>
27 
28 class EnvCellSet;
29 
30 // ========================================================================
31 // GarpAlgorithm
32 // ========================================================================
34 {
35 private:
36  // current ruleset
38 
39  // best model so far
41 
42  // data points used for training
44 
45 
46 public:
47  // OM Algorithm virtual methods
48  int initialize();
49  int iterate();
50  int done() const;
51  float getProgress() const;
52  Scalar getValue( const Sample& x ) const;
53  int getConvergence( Scalar * const val ) const;
54  int getGeneration() { return Gen; }
55 
56 
57  GarpAlgorithm();
58  virtual ~GarpAlgorithm();
59 
60  RuleSet * getBestSet() { return &objBest; }
61  void getInitialModel(int intSize, EnvCellSet * objTrainSet);
62  void updateRuleUsage();
63 
65  { return objBest.size(); }
66 
67  char * getParameter2(char * sParamName);
68  void setParameter(char * sParamName, char * sParamValue);
69 
71  void setSelectedLayers(char * strParamValue);
72 
73  protected:
74  void _getConfiguration( ConfigurationPtr& ) const;
76 
77 private:
78  // private methods
79  void initializeProperties();
80 
81  // Garp algorithm
82  void DisplayStatus();
83  void colonize(RuleSet * objRules, EnvCellSet * objTrainSet, int intNewRules);
84  void evaluate(RuleSet * objRules, EnvCellSet * objTrainSet);
85  int saveRule(int iIndex);
86  void measure();
87  double converge();
88  void select();
89 
90  void mutate();
91  void crossover();
92  void join();
93 
94  void updateHeuOpPerformance(char chrType);
95 
96  void generate(EnvCellSet * objTestDataset);
97 
98  // deprecated methods
99  void saveBestRules(RuleSet * toRuleSet, RuleSet * fromRuleSet);
100  void concatenateRuleSets(RuleSet * toRuleSet, RuleSet * fromRuleSet);
101 
102 
103 private:
104 
105  long lVersion;
106 
107  // flags
108  int Sigflag;
109  int Postflag;
110  int Compflag;
112 
119 
123 
124  // timming
125  int iCPUTime; // accumulated CPU time used for processing the model (in miliseconds)
126 
127  // algorithm variables
129 
130  double Accuracylimit; // The minimium post prob of a rule
131  double MinUsage;
132  double Mortality;
133 
134  int Totalgens; // generations per experiment
135  int Totaltrials; // trials per experiment
136  int Popsize; // population size
137  double C_rate; // crossover rate
138  double M_rate; // mutation rate
139  double J_rate; // join rate
140  double I_rate;
141  double Gapsize; // fraction of pop generated from archive
142  int Trials; // trial counter
143  int Maxspin; // max gens without evals
144  double Resampling_f;
145  double Significance; // the minimum level for inc in best
146  double Conv_limit; // the fractional addition of rules
147  double Cutval;
148 
149 
150  // data collection and loop control variables
151  double Ave_current_perf;/* ave perf in current generation */
152  double Best; /* best performance seen so far */
153  double Best_current_perf;/* best perf in current generation */
154  int Best_guy; /* index of best_current_perf */
155  int Conv; /* number of partially coverged genes */
156  mutable bool Doneflag; /* set when termination conditions hold */
157  int Experiment; /* experiment counter */
158  int Gen; /* generation counter */
159  int Lost; /* number of totally coverged positions */
160  int Spin; /* number of gens since eval occurred */
161  double Worst; /* worst performance seen so far */
162  double Worst_current_perf;/* worst perf in current generation */
163  int Heuristic[2][5]; /* successes of heuristic operators */
164  double Convergence; /* the stability of rule set */
165  int Improvements; /* the number of times the best set has been
166  improved by addition or alteration */
167  int Resample;
168 
169  mutable float _maxProgress;
170 
171 };
172 
173 // ========================================================================
174 
175 #endif //__GarpAlgorithm_H_
EnvCellSet * objTrainSet
Definition: GarpAlgorithm.h:43
double Scalar
Type of map values.
Definition: om_defs.hh:39
int size()
Definition: RuleSet.cpp:157
int saveRule(int iIndex)
int Heuristic[2][5]
double Convergence
void setSelectedLayers(char *strParamValue)
void getInitialModel(int intSize, EnvCellSet *objTrainSet)
bool bGeneIsActive[MAX_ENV_LAYERS]
RuleSet objNew
Definition: GarpAlgorithm.h:37
double Worst_current_perf
virtual ~GarpAlgorithm()
double Best_current_perf
void evaluate(RuleSet *objRules, EnvCellSet *objTrainSet)
void concatenateRuleSets(RuleSet *toRuleSet, RuleSet *fromRuleSet)
void updateRuleUsage()
RuleSet * getBestSet()
Definition: GarpAlgorithm.h:60
int done() const
char * getParameter2(char *sParamName)
void _setConfiguration(const ConstConfigurationPtr &)
const int MAX_ENV_LAYERS
Definition: Utilities.h:53
double Accuracylimit
Scalar getValue(const Sample &x) const
void setParameter(char *sParamName, char *sParamValue)
double Ave_current_perf
int getGeneration()
Definition: GarpAlgorithm.h:54
void generate(EnvCellSet *objTestDataset)
char * getSelectedLayersAsString()
RuleSet objBest
Definition: GarpAlgorithm.h:40
float getProgress() const
void colonize(RuleSet *objRules, EnvCellSet *objTrainSet, int intNewRules)
int getConvergence(Scalar *const val) const
void saveBestRules(RuleSet *toRuleSet, RuleSet *fromRuleSet)
void initializeProperties()
void updateHeuOpPerformance(char chrType)
double Resampling_f
void _getConfiguration(ConfigurationPtr &) const
int iGeneIndex[MAX_ENV_LAYERS]
double Significance
Definition: Sample.hh:25