source: trunk/CrossPare/src/de/ugoe/cs/cpdp/dataprocessing/TCAPlusNormalization.java @ 135

Last change on this file since 135 was 135, checked in by sherbold, 8 years ago
  • code documentation and formatting
  • Property svn:mime-type set to text/plain
File size: 3.1 KB
Line 
1// Copyright 2015 Georg-August-Universität Göttingen, Germany
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
15package de.ugoe.cs.cpdp.dataprocessing;
16
17import de.ugoe.cs.cpdp.util.WekaUtils;
18import de.ugoe.cs.cpdp.util.WekaUtils.DistChar;
19import weka.core.Instances;
20
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 */
28public 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) {
38        // dummy, paramters not used
39    }
40
41    /*
42     * (non-Javadoc)
43     *
44     * @see de.ugoe.cs.cpdp.dataprocessing.IProcessesingStrategy#apply(weka.core.Instances,
45     * weka.core.Instances)
46     */
47    @Override
48    public void apply(Instances testdata, Instances traindata) {
49        applyTCAPlus(testdata, traindata);
50    }
51
52    private void applyTCAPlus(Instances testdata, Instances traindata) {
53        DistChar dcTest = WekaUtils.datasetDistance(testdata);
54        DistChar dcTrain = WekaUtils.datasetDistance(traindata);
55
56        // RULE 1:
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        {
60            // do nothing
61        }
62        // RULE 2:
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        {
67            NormalizationUtil.minMax(testdata);
68            NormalizationUtil.minMax(traindata);
69        }
70        // RULE 3:
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        {
74            NormalizationUtil.zScoreTraining(testdata, traindata);
75        }
76        // RULE 4:
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        {
80            NormalizationUtil.zScoreTarget(testdata, traindata);
81        }
82        // RULE 5:
83        else {
84            NormalizationUtil.zScore(testdata);
85            NormalizationUtil.zScore(traindata);
86        }
87    }
88}
Note: See TracBrowser for help on using the repository browser.