package de.ugoe.cs.cpdp.dataprocessing; import org.apache.commons.math3.ml.distance.EuclideanDistance; import weka.core.Instances; // normalization selected according to TCA+ rules (TCA has to be applied separately public class TCAPlusNormalization implements IProcessesingStrategy { private class DistChar { private final double mean; private final double std; private final double min; private final double max; private int num; private DistChar(double mean, double std, double min, double max, int num) { this.mean = mean; this.std = std; this.min = min; this.max = max; this.num = num; } } /** * Does not have parameters. String is ignored. * * @param parameters * ignored */ @Override public void setParameter(String parameters) { // TODO Auto-generated method stub } @Override public void apply(Instances testdata, Instances traindata) { applyTCAPlus(testdata, traindata); } private void applyTCAPlus(Instances testdata, Instances traindata) { DistChar dcTest = datasetDistance(testdata); DistChar dcTrain = datasetDistance(traindata); // RULE 1: if( 0.9*dcTrain.mean<=dcTest.mean && 1.1*dcTrain.mean>=dcTest.mean && 0.9*dcTrain.std<=dcTest.std && 1.1*dcTrain.std>=dcTest.std) { // do nothing } // RULE 2: else if((0.4*dcTrain.min>dcTest.min || 1.6*dcTrain.mindcTest.max || 1.6*dcTrain.mindcTest.num || 1.6*dcTrain.mindcTest.std && dcTrain.numdcTest.num) { NormalizationUtil.zScoreTraining(testdata, traindata); } // RULE 4: else if((0.4*dcTrain.std>dcTest.std && dcTrain.num>dcTest.num) || (1.6*dcTrain.std max ) { max = distance; } } } double mean = sumAll / numCmp; double std = Math.sqrt((sumAllQ-(sumAll*sumAll)/numCmp) * (1.0d / (numCmp - 1))); return new DistChar(mean, std, min, max, data.numInstances()); } }