/** It's the new reduction algorithm. (Experimental phase) */ private void reductInTrain() { double averageUseful = 0.0, stdUseful = 0.0; int i = 0; int numSum = 0; // A reference to the population is gotten. Population pop = this.getParentRef().getParentRef(); while (i < macroClSum) { if (!set[i].couldComp()) { numSum += set[i].getNumerosity(); set[i].setNumerosity(0); // The classifier is removed from the [A] set[i] = set[macroClSum - 1]; macroClSum--; ///// numAplicacions++; } else { averageUseful += set[i].getUsefulTimes(); stdUseful += (set[i].getUsefulTimes() * set[i].getUsefulTimes()); i++; } } if (macroClSum > 0) { if (macroClSum > 1) stdUseful = Math.sqrt( (stdUseful - ((averageUseful * averageUseful) / macroClSum)) / (macroClSum - 1)); averageUseful = averageUseful / (double) macroClSum; // With the "thres" parameter you can control the compactation pressure (add or substract the // stdUseful) int thres = (int) (averageUseful - stdUseful); i = 0; averageUseful = 0; while (i < macroClSum) { if (set[i].getUsefulTimes() < thres && set[i].getPrediction() > Config.Preduct) { numSum += set[i].getNumerosity(); set[i].setNumerosity(0); set[i] = set[macroClSum - 1]; macroClSum--; ///// numAplicacions++; } else { // We add the contribuion of each classifier to distribute the numerosity at the end averageUseful += set[i].getUsefulTimes(); i++; } } // The numerosity of classifiers deleted are set to other classifiers in the population. int addNum = 0; int discount = 0; for (i = 0; i < macroClSum - 1; i++) { addNum = (int) (((double) set[i].getUsefulTimes() / averageUseful) * (double) numSum); set[i].increaseNumerosity(addNum); discount += addNum; } if (macroClSum > 0) set[macroClSum - 1].increaseNumerosity(numSum - discount); } else { microClSum -= numSum; pop.microClSum -= numSum; } pop.deleteClWithZeroNum(); }