openModeller  Version 1.4.0
rules_range.cpp
Go to the documentation of this file.
00001 
00036 #include <openmodeller/Random.hh>
00037 #include <math.h>
00038 #include <string.h>
00039 
00040 #include <openmodeller/Log.hh>
00041 #include <openmodeller/Sample.hh>
00042 
00043 #include "rules_range.hh"
00044 #include "bioclim_histogram.hh"
00045 
00046 
00047 // ==========================================================================
00048 //  RangeRule implelentation
00049 // ==========================================================================
00050 RangeRule::RangeRule() : 
00051   GarpRule() 
00052 {}
00053 
00054 RangeRule::RangeRule(int numGenes) : 
00055   GarpRule(numGenes) 
00056 { }
00057 
00058 RangeRule::RangeRule(Scalar prediction, int numGenes, 
00059                      const Sample& chrom1, const Sample& chrom2, 
00060                      const double * performances) : 
00061   GarpRule(prediction, numGenes, chrom1, chrom2, performances) 
00062 {}
00063 
00064 // ==========================================================================
00065 RangeRule::~RangeRule() { }
00066 
00067 // ==========================================================================
00068 void RangeRule::initialize(const BioclimHistogram& histogram)
00069 {
00070   int i, j;
00071   Random rnd;
00072 
00073   // loop iterates through variables
00074   for(i = 0; i < _numGenes; i++)
00075     {
00076       j = rnd.get(_numGenes);
00077       
00078       Scalar a = 0 , b = 0;
00079       histogram.getBioclimRange(_prediction, j, a, b);
00080       _chrom1[j] = a;
00081       _chrom2[j] = b;
00082     }
00083 }
00084 
00085 // ==========================================================================
00086 bool RangeRule::applies(const Sample& sample) const
00087 {
00088   // visit each of the genes
00089   for (int i = 0; i < _numGenes; i++)
00090     {
00091       if (!(equalEps(_chrom1[i], -1.0) && equalEps(_chrom2[i], +1.0)))
00092         if (!between(sample[i], _chrom1[i], _chrom2[i]))
00093           return false;
00094     }
00095 
00096   return true;
00097 }
00098 
00099 // ==========================================================================
00100 int RangeRule::getStrength(const Sample& sample) const
00101 {
00102   //printf("GetStrength(%+7.3f)\n", _prediction);
00103   for (int i = 0; i < _numGenes; i++)
00104     {
00105       if (!membership(_chrom1[i], _chrom2[i], sample[i])) 
00106   { 
00107     //printf("Strength = 0\n"); 
00108     return 0; 
00109   }
00110     } 
00111   
00112   //printf("Strength = 1\n");
00113   return 1;
00114 }
00115 
00116 // ==========================================================================
00117 void RangeRule::log()
00118 {
00119   Log::instance()->info( "Range: " );
00120   GarpRule::log();
00121 }
00122 
00123 // ==========================================================================