openModeller  Version 1.4.0
rules_base.hh
Go to the documentation of this file.
00001 
00036 #ifndef _RULES_BASE_HH_
00037 #define _RULES_BASE_HH_
00038 
00039 #include <openmodeller/om.hh>
00040 #include <openmodeller/Sample.hh>
00041 
00042 enum PerfIndex
00043 {
00045   PerfUtil = 0,
00046 
00048   PerfPrStr = 1,
00049 
00051   PerfPrProb = 2,
00052 
00054   PerfPrDist = 3,
00055 
00057   PerfPostStr = 4,
00058 
00060   PerfPostProb = 5,
00061 
00063   PerfPostDist = 6,
00064 
00066   PerfCov = 7,
00067 
00069   PerfSig = 8,
00070 
00072   PerfErr = 9
00073 
00086 };
00087 
00088 
00089 enum RuleOrigin
00090 {
00092   OriginColonization = 0,
00093   OriginMutation = 1,
00094   OriginJoin = 2,
00095   OriginCrossover = 3
00096 };
00097 
00098 
00099 enum RuleType
00100 {
00102   VirtualRuleType = -1,
00103   RangeRuleType = 0,
00104   NegatedRuleType = 1,
00105   LogitRuleType = 2,
00106   AtomicRuleType = 3
00107 };
00108 
00109 bool equalEps(double v1, double v2);
00110 bool between(double value, double min, double max);
00111 int membership(double value1, double value2, double value);
00112 
00113 
00114 /****************************************************************/
00115 /****************** GarpRule class hierarchy ********************/
00116 
00123 class GarpRule  
00124 {
00125 public:
00127   GarpRule();
00128 
00130   GarpRule(const int numGenes);
00131 
00133   GarpRule(Scalar prediction, int numGenes, 
00134      const Sample& chrom1, const Sample& chrom2, 
00135      const double * performances);
00136   
00138   virtual ~GarpRule();
00139 
00140 
00144   virtual GarpRule * clone() const;
00145 
00146   virtual GarpRule * objFactory() const = 0;
00147   
00148   virtual int copy(const GarpRule * fromRule);
00149 
00150   int numGenes() const { return _numGenes; }
00151 
00152   virtual char type() const       { return 'v'; }
00153   bool needsEvaluation() const    { return _needsEvaluation; } 
00154   void forceEvaluation() { _needsEvaluation = true; } 
00155   void evaluated()       { _needsEvaluation = false; } 
00156   void setPrediction(double pred) { _prediction = pred; }
00157 
00158   Scalar getPrediction() const    { return _prediction; }
00159   const Sample& getChrom1() const { return _chrom1; };
00160   const Sample& getChrom2() const { return _chrom2; };
00161   const double * getPerformanceArray() const { return static_cast<const double *>(_performance); }
00162   double getPerformance(PerfIndex perfIndex) const;
00163 
00164   virtual int getStrength(const Sample& sample) const = 0;
00165   virtual int getCertainty(const Scalar pred) const;
00166   virtual double getError(const Scalar predefinedValue, const Scalar prediction) const;
00167   
00168   virtual bool similar(const GarpRule * compareToRule) const;
00169   virtual void mutate(double temperature);
00170   virtual void crossover(GarpRule * rule, int xpt1, int xpt2);
00171 
00172   void adjustRange(Scalar& v1, Scalar& v2) const;
00173   virtual bool applies(const Sample& sample) const = 0;
00174   double evaluate(const OccurrencesPtr& occs);
00175   
00176   virtual void log();
00177 
00178 protected:
00180   Sample _chrom1;
00181   Sample _chrom2;
00182   Scalar _prediction;
00183   
00185   int _numGenes;
00186   
00188   double _performance[10];
00189   bool _needsEvaluation;
00190   char _origin;
00191 };
00192 
00193 // ====================================================================
00194 
00195 #endif