50 #ifndef INFINITY //in mingw this is already defined in math.h
51 #define INFINITY 1000000000
56 int min(
int v1,
int v2)
58 return (v1 < v2)? v1 : v2;
64 return (fabs(v1 - v2) < 0.000001);
70 return ((value >= min) && (value <= max));
73 int membership(
double value1,
double value2,
double value)
77 else if (value < value1 || value > value2)
92 _needsEvaluation(true)
95 for (
int i = 0; i < 10; i++)
96 _performance[i] = 0.0;
100 _chrom1(numGenes, -1.0),
101 _chrom2(numGenes, +1.0),
104 _needsEvaluation(true)
108 for (
int i = 0; i < 10; i++)
115 const double * performances) :
118 _prediction(prediction),
120 _needsEvaluation(true),
124 for (
int i = 0; i < 10; i++)
142 for (
int i = 0; i < 10; i++)
165 for (
int i = 0; i < 10; i++)
191 return (
double) fabs(predefinedValue - pred);
197 if (v1 > +1.0) v1 = +1.0;
198 if (v2 > +1.0) v2 = +1.0;
199 if (v1 < -1.0) v1 = -1.0;
200 if (v2 < -1.0) v2 = -1.0;
225 for ( i = xpt1; i < xpt2; i++)
258 rnd1 = rnd.
get(-temperature, +temperature);
259 rnd2 = rnd.
get(-temperature, +temperature);
306 int n = occs->numOccurrences();
344 pXs = pYs = pXYs = no = 0;
348 for (i = 1; i < 10; i++)
361 Scalar pointValue = ( (*it)->abundance() > 0.0 ) ? 1.0 : 0.0;
362 Sample sample = (*it)->environment();
376 pYcXs +=
getError(error, pointValue);
399 utility[1] = pXs / (double) n;
400 utility[2] = pYs / (double) n;
401 utility[3] = pYcs / (double) n;
403 priorProb = utility[2];
407 utility[4] = no / (double) n;
408 utility[5] = pXYs / (double) no;
409 utility[6] = pYcXs / no;
410 utility[7] = no / (double) n;
414 if ( (no >=
MIN_SIG_NO) && (priorProb > 0) && (priorProb < 1.0))
416 utility[8] = (pXYs - priorProb * no) /
417 sqrt( no * priorProb * (1.0 - priorProb));
422 utility[0] *= utility[5];
425 utility[0] *= utility[8];
435 for (i = 0; i < 10; i++)
471 for (
int i = 0; i <
_numGenes * 2; i += 2)
virtual void crossover(GarpRule *rule, int xpt1, int xpt2)
double get(double min, double max)
double _performance[10]
Vector for storing the performance values for the rule.
double Scalar
Type of map values.
static Log * instance()
Returns the instance pointer, creating the object on the first call.
void error(const char *format,...)
'Error' level.
Sample _chrom1
BYTE vector containing the genes (representation of the variables in a Genetic Algorithm.
double evaluate(const OccurrencesPtr &occs)
void adjustRange(Scalar &v1, Scalar &v2) const
bool between(double value, double min, double max)
int membership(double value1, double value2, double value)
virtual GarpRule * objFactory() const =0
int _numGenes
Number of genes stored by the rule.
virtual GarpRule * clone() const
virtual int copy(const GarpRule *fromRule)
bool equalEps(double v1, double v2)
virtual void mutate(double temperature)
virtual int getStrength(const Sample &sample) const =0
virtual char type() const
virtual int getCertainty(const Scalar pred) const
void info(const char *format,...)
'Info' level.
double getPerformance(PerfIndex perfIndex) const
virtual double getError(const Scalar predefinedValue, const Scalar prediction) const
std::vector< OccurrencePtr >::const_iterator const_iterator
virtual bool similar(const GarpRule *compareToRule) const