[86] | 1 | // Copyright 2015 Georg-August-Universität Göttingen, Germany
|
---|
[52] | 2 | //
|
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 4 | // you may not use this file except in compliance with the License.
|
---|
| 5 | // You may obtain a copy of the License at
|
---|
| 6 | //
|
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 8 | //
|
---|
| 9 | // Unless required by applicable law or agreed to in writing, software
|
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 12 | // See the License for the specific language governing permissions and
|
---|
| 13 | // limitations under the License.
|
---|
| 14 |
|
---|
[51] | 15 | package de.ugoe.cs.cpdp.dataprocessing;
|
---|
| 16 |
|
---|
[64] | 17 | import de.ugoe.cs.cpdp.util.WekaUtils;
|
---|
| 18 | import de.ugoe.cs.cpdp.util.WekaUtils.DistChar;
|
---|
[51] | 19 | import weka.core.Instances;
|
---|
| 20 |
|
---|
[135] | 21 | /**
|
---|
| 22 | * <p>
|
---|
| 23 | * Normalization selected according to the TCA+ rules after Nam et al. (Transfer Defect Learning).
|
---|
| 24 | * </p>
|
---|
| 25 | *
|
---|
| 26 | * @author Steffen Herbold
|
---|
| 27 | */
|
---|
[51] | 28 | public class TCAPlusNormalization implements IProcessesingStrategy {
|
---|
| 29 |
|
---|
| 30 | /**
|
---|
| 31 | * Does not have parameters. String is ignored.
|
---|
| 32 | *
|
---|
| 33 | * @param parameters
|
---|
| 34 | * ignored
|
---|
| 35 | */
|
---|
| 36 | @Override
|
---|
| 37 | public void setParameter(String parameters) {
|
---|
[135] | 38 | // dummy, paramters not used
|
---|
[51] | 39 | }
|
---|
| 40 |
|
---|
[135] | 41 | /*
|
---|
| 42 | * (non-Javadoc)
|
---|
| 43 | *
|
---|
| 44 | * @see de.ugoe.cs.cpdp.dataprocessing.IProcessesingStrategy#apply(weka.core.Instances,
|
---|
| 45 | * weka.core.Instances)
|
---|
| 46 | */
|
---|
[51] | 47 | @Override
|
---|
| 48 | public void apply(Instances testdata, Instances traindata) {
|
---|
| 49 | applyTCAPlus(testdata, traindata);
|
---|
| 50 | }
|
---|
[135] | 51 |
|
---|
[51] | 52 | private void applyTCAPlus(Instances testdata, Instances traindata) {
|
---|
[64] | 53 | DistChar dcTest = WekaUtils.datasetDistance(testdata);
|
---|
| 54 | DistChar dcTrain = WekaUtils.datasetDistance(traindata);
|
---|
[135] | 55 |
|
---|
[51] | 56 | // RULE 1:
|
---|
[135] | 57 | if (0.9 * dcTrain.mean <= dcTest.mean && 1.1 * dcTrain.mean >= dcTest.mean &&
|
---|
| 58 | 0.9 * dcTrain.std <= dcTest.std && 1.1 * dcTrain.std >= dcTest.std)
|
---|
| 59 | {
|
---|
[51] | 60 | // do nothing
|
---|
| 61 | }
|
---|
| 62 | // RULE 2:
|
---|
[135] | 63 | else if ((0.4 * dcTrain.min > dcTest.min || 1.6 * dcTrain.min < dcTest.min) &&
|
---|
| 64 | (0.4 * dcTrain.max > dcTest.max || 1.6 * dcTrain.min < dcTest.max) &&
|
---|
| 65 | (0.4 * dcTrain.min > dcTest.num || 1.6 * dcTrain.min < dcTest.num))
|
---|
| 66 | {
|
---|
[51] | 67 | NormalizationUtil.minMax(testdata);
|
---|
| 68 | NormalizationUtil.minMax(traindata);
|
---|
| 69 | }
|
---|
| 70 | // RULE 3:
|
---|
[135] | 71 | else if ((0.4 * dcTrain.std > dcTest.std && dcTrain.num < dcTest.num) ||
|
---|
| 72 | (1.6 * dcTrain.std < dcTest.std) && dcTrain.num > dcTest.num)
|
---|
| 73 | {
|
---|
[51] | 74 | NormalizationUtil.zScoreTraining(testdata, traindata);
|
---|
| 75 | }
|
---|
| 76 | // RULE 4:
|
---|
[135] | 77 | else if ((0.4 * dcTrain.std > dcTest.std && dcTrain.num > dcTest.num) ||
|
---|
| 78 | (1.6 * dcTrain.std < dcTest.std) && dcTrain.num < dcTest.num)
|
---|
| 79 | {
|
---|
[51] | 80 | NormalizationUtil.zScoreTarget(testdata, traindata);
|
---|
| 81 | }
|
---|
[135] | 82 | // RULE 5:
|
---|
[51] | 83 | else {
|
---|
| 84 | NormalizationUtil.zScore(testdata);
|
---|
| 85 | NormalizationUtil.zScore(traindata);
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 | }
|
---|