Esempio n. 1
0
void classifier_hyperrect_list::initiateEval()
{
	int i;
	JVector<int> discrete;
	JVector<int> real;

	for(i=0;i<numAtt;i++) {
		int att=whichAtt[i];
		if (ai.getTypeOfAttribute(att) == REAL) {
			real.addElement(i);
		} else {
			discrete.addElement(i);
		}
	}

	numReal=real.size();
	listRealPos = new int[numReal];
	listRealAtt = new int[numReal];
	for(i=0;i<numReal;i++) {
		listRealPos[i]=real[i];
		listRealAtt[i]=whichAtt[listRealPos[i]];
	}

	numDiscrete=discrete.size();
	listDiscretePos = new int[numDiscrete];
	listDiscreteAtt = new int[numDiscrete];
	for(i=0;i<numDiscrete;i++) {
		listDiscretePos[i]=discrete[i];
		listDiscreteAtt[i]=whichAtt[listDiscretePos[i]];
	}
}
Esempio n. 2
0
void classifier_hyperrect_list::initializeChromosome()
{
	int i,j,base;

	instance *ins=NULL;
	if(tGlobals->smartInit) {
		if(tGlobals->defaultClassPolicy!=DISABLED) {
			ins=is->getInstanceInit(tGlobals->defaultClass);
		} else {
			ins=is->getInstanceInit(ai.getNumClasses());
		}
	}

	JVector<int> selectedAtts;
	ruleSize=0;
	for(i=0;i<tGlobals->numAttributesMC;i++) {
		if(!rnd>=tReal->probIrr) {
			selectedAtts.addElement(i);
			ruleSize+=tReal->attributeSize[i];
		}
	}

	numAtt=selectedAtts.size();
	whichAtt = new int[numAtt];
	offsetPredicates = new int[numAtt];
	predicates = new float[ruleSize];

	for(i=0,base=0;i<numAtt;i++) {
		offsetPredicates[i]=base;
		int att=selectedAtts[i];
		whichAtt[i]=att;

		if (ai.getTypeOfAttribute(att) == REAL) {
			float max,min;
			float sizeD=ai.getSizeDomain(att);
			float minD=ai.getMinDomain(att);
			float maxD=ai.getMaxDomain(att);
			float size=(!rnd * tReal->rangeIntervalSizeInit + tReal->minIntervalSizeInit)*sizeD;

			if(ins) {
				float val=ins->realValues[att];
				min=val-size/2.0;
				max=val+size/2.0;
				if(min<minD) {
					max+=(minD-min);
					min=minD;
				}
				if(max>maxD) {
					min-=(max-maxD);
					max=maxD;
				}
			} else {
				min=!rnd*(sizeD-size)+minD;
				max=min+size;
			}
	
			predicates[base]=min;
			predicates[base+1]=max;
		} else {
			int value;
			if(ins) value=(unsigned char)ins->realValues[att];
			else value=-1;
			for(j=0;j<tReal->attributeSize[att];j++) {
				if(j!=value) {
					if(!rnd<tGlobals->probOne) {
						predicates[base+j]=1;
					} else {
						predicates[base+j]=0;
					}
				} else {
					predicates[base+j]=1;
				}
			}
		}

		base+=tReal->attributeSize[att];
	}

	if(ins) {
		classValue=ins->getClass();
	} else {
		do {
			classValue=rnd(0,ai.getNumClasses()-1);
		} while(tGlobals->defaultClassPolicy!=DISABLED && classValue==tGlobals->defaultClass);
	}
}