23 #define _SCL_SECURE_NO_DEPRECATE
98 char * strXML, *strXMLRule;
101 strXML =
new char[
size];
106 strcpy(strXML,
"<RuleSet>\n");
108 sprintf(strXML,
"<RuleSet Id=\"%s\">\n",
id);
113 sprintf(strXML,
"%s%s\n", strXML, strXMLRule);
116 strcat(strXML,
"</RuleSet>");
119 if (strlen(strXML) >
size_t(size))
120 throw GarpException(82,
"String size exceeded in RuleSet::toXML()");
132 if (strcmp(strSaveFilename,
"") == 0)
133 throw GarpException(3,
"Cannot save rule set with an empty filename");
135 outf = fopen(strSaveFilename,
"w");
140 fprintf(outf,
"%s\n",
objRules[i]->toString());
147 sprintf(msg,
"Rule set file <%s> could not be opened for writing", strSaveFilename);
182 for (
int i = intMaxRules; i < intInitialRules; i++)
202 throw GarpException(1,
"The actual and calculated significance values of this rule do not match.");
204 if (
objRules[i]->dblPerformance[iPerfIndex] < dValue)
234 objRules[i]->blnNeedsEvaluation = value;
267 for (i = 0; i < this->
intRules; i++)
268 dSum +=
objRules[i]->dblPerformance[9];
270 for (i = 0; i < intRules - 1; i++)
271 for (j = intRules - 1; j > i; j--)
272 if (
objRules[j]->dblPerformance[intPerfIndex] >
objRules[j - 1]->dblPerformance[intPerfIndex])
284 int iRuleIndex, iPredictedValue, iActualValue;
290 for (i = 0; i < this->
intRules; i++)
291 dSum +=
objRules[i]->dblPerformance[9];
296 n = objTestDataset->
count();
297 for (i = 0; i < n; i++)
300 cell = objTestDataset->
get(i);
307 iActualValue = cell->
values[0];
314 for (i = 0; i < this->
intRules; i++)
315 dSum +=
objRules[i]->dblPerformance[9];
332 if ((iActualValue < 0) || (iActualValue > 1) || (iPredictedValue < 0) || (iPredictedValue > 1))
333 throw GarpException(1,
"Confusion matrix index out of range");
341 if ((iActualValue < 0) || (iActualValue > 1) || (iPredictedValue < 0) || (iPredictedValue > 1))
342 throw GarpException(1,
"Confusion matrix index out of range");
378 throw GarpException(131,
"Method RuleSet::updateRuleUsage not implemented yet");
385 double dResult, dWeight, dWSum;
389 dWeight = (double) iFirstRulesToBeIncluded;
391 for (i = 0; i < iFirstRulesToBeIncluded; i++)
418 for (
int i = 1; i <
_dim; i++)
422 Scalar value = sample[i - 1];
423 if (value > 253.0) value = 253.0;
424 if (value < 1.0) value = 1.0;
426 bytes[i] = (
BYTE) value;
441 for (
int i = 0; i <
intRules; i++ )
443 printf(
"%2d] ", i );
624 int i, maxi, ruleIndex;
626 int b_membership[256];
628 for (i = 0; i < 256; i++)
637 while ((i <
intRules) && (ruleIndex == -1))
640 u = (int)(255.0 *
objRules[i]->dblPerformance[5]);
642 if (
objRules[i]->dblPerformance[5] >= Accuracylimit)
651 if (b_membership[
objRules[i]->Gene[0]] < u)
895 for (
int i = 0; i < 3; i++)
899 case 0: type =
'd';
break;
900 case 1: type =
'!';
break;
901 case 2: type =
'r';
break;
912 if (rule->
type() == type)
916 pres += (int) rule->
Gene[0];
917 if (max < rule->dblPerformance[0])
925 printf(
"%c %2d %+7.2f %+7.2f %2d|", type, ct, max, sum / ct, pres);
void sort(int intPerfIndex)
double Scalar
Type of map values.
void saveText(char *strFilename)
Scalar getValue(const Sample &sample) const
static bool equalEps(double x, double y, double eps)
void verify(EnvCellSet *objTestDataset, double dAccLimit)
void setEvaluation(bool value)
void resetConfMatrix(EnvCellSet *objTestDataset)
double getOveralPerformance(int iPerfIndex, int iFirstRulesToBeIncluded)
int applyRulesToCell(EnvCell *cell, double Accuracylimit) const
void gatherRuleSetStats(int gen)
void setActiveGenes(bool *bGeneIsActivePtr, int *iGeneIndexPtr, int iActiveGenesAux)
void addConfMatrix(int iPredictedValue, int iActualValue)
BYTE * Gene
BYTE vector containing the genes (representation of the variables in a Genetic Algorithm.
virtual char type() const
double getOverallAccuracy()
int getConfMatrix(int iPredictedValue, int iActualValue)
double dblPerformance[10]
Vector for storing the performance values for the rule.
void discardRules(int iPerfIndex, double dValue)
int getUnpredictedPoints()
Rule * objRules[MAX_RULES]
void trim(int intMaxRules)
void set(int index, Rule *objRule)