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 // Rule.h: interface for the Rule class. 00019 // 00021 00022 #ifndef __RULE_H_ 00023 #define __RULE_H_ 00024 00025 #include "EnvCell.h" 00026 #include "Utilities.h" 00027 00028 class EnvCellSet; 00029 class EnvLayerSet; 00030 class RuleSet; 00031 00032 // ==================================================================== 00033 00037 class Rule 00038 { 00039 // friend classes 00040 friend class RuleSet; 00041 friend class GarpAlgorithm; 00042 friend class CJobResultValidator; 00043 00044 protected: 00046 BYTE * Gene; 00048 int intGenes; 00049 00051 double dblPerformance[10]; 00052 bool blnNeedsEvaluation; 00053 int intGens; 00054 int intTrials; 00055 int intScreener; 00056 int intScreen; 00057 int intLength; 00058 int intNumber; 00059 int intConclusion; 00060 char chrOrigin; 00061 char chrPad; 00062 int lId; 00063 int iOrigGen; 00064 00065 double _pXYs; 00066 int _no; 00067 double _dA; 00068 double _dSig; 00069 00070 // global properties coming from RuleSet 00071 bool * bGeneIsActive; 00072 int * iGeneIndex; 00073 int iActiveGenes; 00074 00075 public: 00077 Rule(); 00079 virtual ~Rule(); 00080 virtual Rule * objFactory() = 0; 00081 virtual Rule * clone(); 00082 virtual void copy(Rule * fromRule); 00083 00085 void RestoreRule( double *perf, unsigned char *genes, int arry_len, int *gene_index ); 00086 00087 virtual void log(); 00088 virtual char type() const { return 'v'; } 00089 00090 virtual char * toString(); 00091 virtual void fromString(char * strRule) = 0; 00092 virtual char * toXML(); 00093 00094 virtual void initialize(EnvCellSet * objEnvCellSet, const RuleSet * objRuleSet, 00095 bool * geneIsActivePtr, int * geneIndexPtr, int iActGenes) = 0; 00096 virtual bool applyToCell(EnvCell * cell) = 0; 00097 00098 virtual double getCertainty(EnvCell * cell); 00099 virtual double getError(BYTE pred, EnvCell * cell); 00100 virtual double getStrength(EnvCell * cell) = 0; 00101 00102 virtual bool similar(Rule * objOtherRule); 00103 00104 virtual void mutate(int intTemperature); 00105 00106 double testWithData(EnvCellSet * objTrainSet); 00107 00108 bool needsEvaluation() 00109 { 00110 return blnNeedsEvaluation; 00111 } 00112 00113 }; 00114 00115 // ==================================================================== 00116 class GarpRule : public Rule 00117 { 00118 public: 00119 GarpRule(); 00120 virtual ~GarpRule(); 00121 00122 virtual char type() const { return 'v'; } 00123 }; 00124 00125 // ==================================================================== 00126 class RangeRule : public GarpRule 00127 { 00128 public: 00129 RangeRule(); 00130 virtual ~RangeRule(); 00131 virtual Rule * objFactory() { return new RangeRule; } 00132 00133 virtual char type() const { return 'd'; } 00134 00135 virtual void fromString(char * strRule); 00136 virtual void initialize(EnvCellSet * objEnvCellSet, const RuleSet * objRuleSet, 00137 bool * geneIsActivePtr, int * geneIndexPtr, int iActGenes); 00138 virtual bool applyToCell(EnvCell * cell); 00139 00140 virtual double getStrength(EnvCell * cell); 00141 00142 void bioclimRange(EnvCellSet * objEnvCellSet, BYTE pred, double level, int var); 00143 }; 00144 00145 // ==================================================================== 00146 class NegatedRangeRule : public RangeRule 00147 { 00148 public: 00149 NegatedRangeRule(); 00150 virtual ~NegatedRangeRule(); 00151 virtual Rule * objFactory() { return new NegatedRangeRule; } 00152 00153 virtual char type() const { return '!'; } 00154 00155 virtual void fromString(char * strRule); 00156 virtual bool applyToCell(EnvCell * cell); 00157 00158 virtual double getStrength(EnvCell * cell); 00159 }; 00160 00161 // ==================================================================== 00162 class AtomicRule : public GarpRule 00163 { 00164 public: 00165 AtomicRule(); 00166 virtual ~AtomicRule(); 00167 virtual Rule * objFactory() { return new AtomicRule; } 00168 00169 virtual char type() const { return 'a'; } 00170 00171 virtual void fromString(char * strRule); 00172 virtual void initialize(EnvCellSet * objEnvCellSet, const RuleSet * objRuleSet, 00173 bool * geneIsActivePtr, int * geneIndexPtr, int iActGenes); 00174 virtual bool applyToCell(EnvCell * cell); 00175 00176 virtual double getStrength(EnvCell * cell); 00177 }; 00178 00179 // ==================================================================== 00180 class LogitRule : public GarpRule 00181 { 00182 public: 00183 LogitRule(); 00184 virtual ~LogitRule(); 00185 virtual Rule * objFactory() { return new LogitRule; } 00186 00187 virtual char type() const { return 'r'; } 00188 00189 virtual void fromString(char * strRule); 00190 virtual void initialize(EnvCellSet * objEnvCellSet, const RuleSet * objRuleSet, 00191 bool * geneIsActivePtr, int * geneIndexPtr, int iActGenes); 00192 virtual bool applyToCell(EnvCell * cell); 00193 00194 virtual bool similar(Rule * objOtherRule); 00195 00196 virtual double getStrength(EnvCell * cell); 00197 00198 virtual void mutate(int intTemperature); 00199 00200 int regression(EnvCellSet * objEnvCellSet, int dep, 00201 double& constant, double& coef1, double& coef2); 00202 }; 00203 00204 // ==================================================================== 00205 00206 #endif