openModeller  Version 1.5.0
Rule.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 // Rule.h: interface for the Rule class.
19 //
21 
22 #ifndef __RULE_H_
23 #define __RULE_H_
24 
25 #include "EnvCell.h"
26 #include "Utilities.h"
27 
28 class EnvCellSet;
29 class EnvLayerSet;
30 class RuleSet;
31 
32 // ====================================================================
33 
37 class Rule
38 {
39  // friend classes
40  friend class RuleSet;
41  friend class GarpAlgorithm;
42  friend class CJobResultValidator;
43 
44 protected:
48  int intGenes;
49 
51  double dblPerformance[10];
53  int intGens;
54  int intTrials;
56  int intScreen;
57  int intLength;
58  int intNumber;
60  char chrOrigin;
61  char chrPad;
62  int lId;
63  int iOrigGen;
64 
65  double _pXYs;
66  int _no;
67  double _dA;
68  double _dSig;
69 
70  // global properties coming from RuleSet
71  bool * bGeneIsActive;
72  int * iGeneIndex;
74 
75 public:
77  Rule();
79  virtual ~Rule();
80  virtual Rule * objFactory() = 0;
81  virtual Rule * clone();
82  virtual void copy(Rule * fromRule);
83 
85  void RestoreRule( double *perf, unsigned char *genes, int arry_len, int *gene_index );
86 
87  virtual void log();
88  virtual char type() const { return 'v'; }
89 
90  virtual char * toString();
91  virtual void fromString(char * strRule) = 0;
92  virtual char * toXML();
93 
94  virtual void initialize(EnvCellSet * objEnvCellSet, const RuleSet * objRuleSet,
95  bool * geneIsActivePtr, int * geneIndexPtr, int iActGenes) = 0;
96  virtual bool applyToCell(EnvCell * cell) = 0;
97 
98  virtual double getCertainty(EnvCell * cell);
99  virtual double getError(BYTE pred, EnvCell * cell);
100  virtual double getStrength(EnvCell * cell) = 0;
101 
102  virtual bool similar(Rule * objOtherRule);
103 
104  virtual void mutate(int intTemperature);
105 
106  double testWithData(EnvCellSet * objTrainSet);
107 
109  {
110  return blnNeedsEvaluation;
111  }
112 
113 };
114 
115 // ====================================================================
116 class GarpRule : public Rule
117 {
118 public:
119  GarpRule();
120  virtual ~GarpRule();
121 
122  virtual char type() const { return 'v'; }
123 };
124 
125 // ====================================================================
126 class RangeRule : public GarpRule
127 {
128 public:
129  RangeRule();
130  virtual ~RangeRule();
131  virtual Rule * objFactory() { return new RangeRule; }
132 
133  virtual char type() const { return 'd'; }
134 
135  virtual void fromString(char * strRule);
136  virtual void initialize(EnvCellSet * objEnvCellSet, const RuleSet * objRuleSet,
137  bool * geneIsActivePtr, int * geneIndexPtr, int iActGenes);
138  virtual bool applyToCell(EnvCell * cell);
139 
140  virtual double getStrength(EnvCell * cell);
141 
142  void bioclimRange(EnvCellSet * objEnvCellSet, BYTE pred, double level, int var);
143 };
144 
145 // ====================================================================
147 {
148 public:
150  virtual ~NegatedRangeRule();
151  virtual Rule * objFactory() { return new NegatedRangeRule; }
152 
153  virtual char type() const { return '!'; }
154 
155  virtual void fromString(char * strRule);
156  virtual bool applyToCell(EnvCell * cell);
157 
158  virtual double getStrength(EnvCell * cell);
159 };
160 
161 // ====================================================================
162 class AtomicRule : public GarpRule
163 {
164 public:
165  AtomicRule();
166  virtual ~AtomicRule();
167  virtual Rule * objFactory() { return new AtomicRule; }
168 
169  virtual char type() const { return 'a'; }
170 
171  virtual void fromString(char * strRule);
172  virtual void initialize(EnvCellSet * objEnvCellSet, const RuleSet * objRuleSet,
173  bool * geneIsActivePtr, int * geneIndexPtr, int iActGenes);
174  virtual bool applyToCell(EnvCell * cell);
175 
176  virtual double getStrength(EnvCell * cell);
177 };
178 
179 // ====================================================================
180 class LogitRule : public GarpRule
181 {
182 public:
183  LogitRule();
184  virtual ~LogitRule();
185  virtual Rule * objFactory() { return new LogitRule; }
186 
187  virtual char type() const { return 'r'; }
188 
189  virtual void fromString(char * strRule);
190  virtual void initialize(EnvCellSet * objEnvCellSet, const RuleSet * objRuleSet,
191  bool * geneIsActivePtr, int * geneIndexPtr, int iActGenes);
192  virtual bool applyToCell(EnvCell * cell);
193 
194  virtual bool similar(Rule * objOtherRule);
195 
196  virtual double getStrength(EnvCell * cell);
197 
198  virtual void mutate(int intTemperature);
199 
200  int regression(EnvCellSet * objEnvCellSet, int dep,
201  double& constant, double& coef1, double& coef2);
202 };
203 
204 // ====================================================================
205 
206 #endif
Rule()
Default constructor.
Definition: Rule.cpp:33
int intScreen
Definition: Rule.h:56
virtual ~NegatedRangeRule()
Definition: Rule.cpp:622
virtual void fromString(char *strRule)
Definition: Rule.cpp:624
int intGenes
Number of genes stored by the rule.
Definition: Rule.h:48
RangeRule()
Definition: Rule.cpp:500
virtual Rule * clone()
Definition: Rule.cpp:73
double _pXYs
Definition: Rule.h:65
virtual void fromString(char *strRule)
Definition: Rule.cpp:506
char chrOrigin
Definition: Rule.h:60
bool * bGeneIsActive
Definition: Rule.h:71
virtual bool applyToCell(EnvCell *cell)
Definition: Rule.cpp:810
int intScreener
Definition: Rule.h:55
virtual char type() const
Definition: Rule.h:153
virtual double getStrength(EnvCell *cell)=0
virtual Rule * objFactory()
Definition: Rule.h:151
virtual ~AtomicRule()
Definition: Rule.cpp:666
friend class CJobResultValidator
Definition: Rule.h:42
double testWithData(EnvCellSet *objTrainSet)
Definition: Rule.cpp:387
virtual char type() const
Definition: Rule.h:187
virtual double getStrength(EnvCell *cell)
Definition: Rule.cpp:650
int iActiveGenes
Definition: Rule.h:73
virtual void initialize(EnvCellSet *objEnvCellSet, const RuleSet *objRuleSet, bool *geneIsActivePtr, int *geneIndexPtr, int iActGenes)=0
Definition: Rule.cpp:180
virtual char * toString()
Definition: Rule.cpp:224
virtual void initialize(EnvCellSet *objEnvCellSet, const RuleSet *objRuleSet, bool *geneIsActivePtr, int *geneIndexPtr, int iActGenes)
Definition: Rule.cpp:669
unsigned char BYTE
Definition: Utilities.h:36
virtual void mutate(int intTemperature)
Definition: Rule.cpp:313
virtual bool applyToCell(EnvCell *cell)=0
virtual char * toXML()
Definition: Rule.cpp:254
AtomicRule()
Definition: Rule.cpp:663
virtual void initialize(EnvCellSet *objEnvCellSet, const RuleSet *objRuleSet, bool *geneIsActivePtr, int *geneIndexPtr, int iActGenes)
Definition: Rule.cpp:511
double _dSig
Definition: Rule.h:68
virtual char type() const
Definition: Rule.h:169
int iOrigGen
Definition: Rule.h:63
virtual double getStrength(EnvCell *cell)
Definition: Rule.cpp:588
int regression(EnvCellSet *objEnvCellSet, int dep, double &constant, double &coef1, double &coef2)
Definition: Rule.cpp:767
LogitRule()
Definition: Rule.cpp:728
virtual Rule * objFactory()
Definition: Rule.h:131
virtual double getStrength(EnvCell *cell)
Definition: Rule.cpp:714
GarpRule()
Definition: Rule.cpp:492
int intGens
Definition: Rule.h:53
virtual double getStrength(EnvCell *cell)
Definition: Rule.cpp:814
Definition: Rule.h:37
int * iGeneIndex
Definition: Rule.h:72
int intNumber
Definition: Rule.h:58
virtual ~LogitRule()
Definition: Rule.cpp:733
BYTE * Gene
BYTE vector containing the genes (representation of the variables in a Genetic Algorithm.
Definition: Rule.h:46
virtual void mutate(int intTemperature)
Definition: Rule.cpp:854
virtual void initialize(EnvCellSet *objEnvCellSet, const RuleSet *objRuleSet, bool *geneIsActivePtr, int *geneIndexPtr, int iActGenes)
Definition: Rule.cpp:743
virtual char type() const
Definition: Rule.h:88
void RestoreRule(double *perf, unsigned char *genes, int arry_len, int *gene_index)
Restore Model.
Definition: Rule.cpp:156
int _no
Definition: Rule.h:66
virtual ~GarpRule()
Definition: Rule.cpp:495
double dblPerformance[10]
Vector for storing the performance values for the rule.
Definition: Rule.h:51
virtual ~Rule()
Default destructor.
Definition: Rule.cpp:66
virtual Rule * objFactory()=0
int intLength
Definition: Rule.h:57
int lId
Definition: Rule.h:62
virtual char type() const
Definition: Rule.h:122
bool blnNeedsEvaluation
Definition: Rule.h:52
virtual void fromString(char *strRule)
Definition: Rule.cpp:693
void bioclimRange(EnvCellSet *objEnvCellSet, BYTE pred, double level, int var)
Definition: Rule.cpp:534
virtual double getCertainty(EnvCell *cell)
Definition: Rule.cpp:305
Definition: Rule.h:116
virtual char type() const
Definition: Rule.h:133
virtual bool applyToCell(EnvCell *cell)
Definition: Rule.cpp:629
virtual bool applyToCell(EnvCell *cell)
Definition: Rule.cpp:698
int intConclusion
Definition: Rule.h:59
virtual void fromString(char *strRule)
Definition: Rule.cpp:738
int intTrials
Definition: Rule.h:54
virtual Rule * objFactory()
Definition: Rule.h:185
bool needsEvaluation()
Definition: Rule.h:108
virtual void fromString(char *strRule)=0
virtual Rule * objFactory()
Definition: Rule.h:167
virtual bool applyToCell(EnvCell *cell)
Definition: Rule.cpp:574
virtual bool similar(Rule *objOtherRule)
Definition: Rule.cpp:873
char chrPad
Definition: Rule.h:61
virtual ~RangeRule()
Definition: Rule.cpp:503
virtual double getError(BYTE pred, EnvCell *cell)
Definition: Rule.cpp:309
virtual void log()
Definition: Rule.cpp:904
virtual void copy(Rule *fromRule)
Definition: Rule.cpp:115
virtual bool similar(Rule *objOtherRule)
Definition: Rule.cpp:349
double _dA
Definition: Rule.h:67