- Timestamp:
- 09/24/15 10:59:05 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CrossPare/src/de/ugoe/cs/cpdp/dataprocessing/LogarithmTransform.java
r40 r41 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 1 15 package de.ugoe.cs.cpdp.dataprocessing; 2 16 … … 8 22 9 23 /** 10 * Logarithm transformation after Carmargo Cruz and Ochimizu: Towards Logistic Regression Models for Predicting Fault-prone Code across Software Projects. 11 * <br><br> 12 * Transform each attribute value x into log(x+1). 24 * Logarithm transformation after Carmargo Cruz and Ochimizu: Towards Logistic Regression Models for 25 * Predicting Fault-prone Code across Software Projects. <br> 26 * <br> 27 * Transform each attribute value x into log(x+1). 28 * 13 29 * @author Steffen Herbold 14 30 */ 15 31 public class LogarithmTransform implements ISetWiseProcessingStrategy, IProcessesingStrategy { 16 32 17 /** 18 * Does not have parameters. String is ignored. 19 * @param parameters ignored 20 */ 21 @Override 22 public void setParameter(String parameters) { 23 // dummy 24 } 33 /** 34 * Does not have parameters. String is ignored. 35 * 36 * @param parameters 37 * ignored 38 */ 39 @Override 40 public void setParameter(String parameters) { 41 // dummy 42 } 25 43 26 /** 27 * @see de.ugoe.cs.cpdp.dataprocessing.SetWiseProcessingStrategy#apply(weka.core.Instances, org.apache.commons.collections4.list.SetUniqueList) 28 */ 29 @Override 30 public void apply(Instances testdata, SetUniqueList<Instances> traindataSet) { 31 final Attribute classAttribute = testdata.classAttribute(); 32 33 // preprocess testdata 34 for( int i=0 ; i<testdata.numInstances() ; i++ ) { 35 Instance instance = testdata.instance(i); 36 for( int j=0 ; j<testdata.numAttributes() ; j++ ) { 37 if( testdata.attribute(j)!=classAttribute && testdata.attribute(j).isNumeric() ) { 38 if( instance.value(j) < 0 ) { 39 instance.setValue(j, (-1*(Math.log(-1*instance.value(j))))); 40 }else { 41 instance.setValue(j, Math.log(1+instance.value(j))); 42 } 43 } 44 } 45 } 46 47 // preprocess training data 48 for( Instances traindata : traindataSet ) { 49 for( int i=0 ; i<traindata.numInstances() ; i++ ) { 50 Instance instance = traindata.instance(i); 51 for( int j=0 ; j<testdata.numAttributes() ; j++ ) { 52 if( traindata.attribute(j)!=classAttribute && traindata.attribute(j).isNumeric() ) { 53 if( instance.value(j) < 0 ) { 54 instance.setValue(j, (-1*(Math.log(-1*instance.value(j))))); 55 }else { 56 instance.setValue(j, Math.log(1+instance.value(j))); 57 } 58 } 59 } 60 } 61 } 62 } 44 /** 45 * @see de.ugoe.cs.cpdp.dataprocessing.SetWiseProcessingStrategy#apply(weka.core.Instances, 46 * org.apache.commons.collections4.list.SetUniqueList) 47 */ 48 @Override 49 public void apply(Instances testdata, SetUniqueList<Instances> traindataSet) { 50 final Attribute classAttribute = testdata.classAttribute(); 63 51 64 /** 65 * @see de.ugoe.cs.cpdp.dataprocessing.ProcessesingStrategy#apply(weka.core.Instances, weka.core.Instances) 66 */ 67 @Override 68 public void apply(Instances testdata, Instances traindata) { 69 final Attribute classAttribute = testdata.classAttribute(); 70 71 // preprocess testdata 72 for( int i=0 ; i<testdata.numInstances() ; i++ ) { 73 Instance instance = testdata.instance(i); 74 for( int j=0 ; j<testdata.numAttributes() ; j++ ) { 75 if( testdata.attribute(j)!=classAttribute && testdata.attribute(j).isNumeric() ) { 76 if( instance.value(j) < 0 ) { 77 instance.setValue(j, (-1*(Math.log(-1*instance.value(j))))); 78 }else { 79 instance.setValue(j, Math.log(1+instance.value(j))); 80 } 81 } 82 } 83 } 84 85 // preprocess training data 86 for( int i=0 ; i<traindata.numInstances() ; i++ ) { 87 Instance instance = traindata.instance(i); 88 for( int j=0 ; j<testdata.numAttributes() ; j++ ) { 89 if( traindata.attribute(j)!=classAttribute && traindata.attribute(j).isNumeric() ) { 90 if( instance.value(j) < 0 ) { 91 instance.setValue(j, (-1*(Math.log(-1*instance.value(j))))); 92 }else { 93 instance.setValue(j, Math.log(1+instance.value(j))); 94 } 95 } 96 } 97 } 98 } 52 // preprocess testdata 53 for (int i = 0; i < testdata.numInstances(); i++) { 54 Instance instance = testdata.instance(i); 55 for (int j = 0; j < testdata.numAttributes(); j++) { 56 if (testdata.attribute(j) != classAttribute && testdata.attribute(j).isNumeric()) { 57 if (instance.value(j) < 0) { 58 instance.setValue(j, (-1 * (Math.log(-1 * instance.value(j))))); 59 } 60 else { 61 instance.setValue(j, Math.log(1 + instance.value(j))); 62 } 63 } 64 } 65 } 66 67 // preprocess training data 68 for (Instances traindata : traindataSet) { 69 for (int i = 0; i < traindata.numInstances(); i++) { 70 Instance instance = traindata.instance(i); 71 for (int j = 0; j < testdata.numAttributes(); j++) { 72 if (traindata.attribute(j) != classAttribute && 73 traindata.attribute(j).isNumeric()) 74 { 75 if (instance.value(j) < 0) { 76 instance.setValue(j, (-1 * (Math.log(-1 * instance.value(j))))); 77 } 78 else { 79 instance.setValue(j, Math.log(1 + instance.value(j))); 80 } 81 } 82 } 83 } 84 } 85 } 86 87 /** 88 * @see de.ugoe.cs.cpdp.dataprocessing.ProcessesingStrategy#apply(weka.core.Instances, 89 * weka.core.Instances) 90 */ 91 @Override 92 public void apply(Instances testdata, Instances traindata) { 93 final Attribute classAttribute = testdata.classAttribute(); 94 95 // preprocess testdata 96 for (int i = 0; i < testdata.numInstances(); i++) { 97 Instance instance = testdata.instance(i); 98 for (int j = 0; j < testdata.numAttributes(); j++) { 99 if (testdata.attribute(j) != classAttribute && testdata.attribute(j).isNumeric()) { 100 if (instance.value(j) < 0) { 101 instance.setValue(j, (-1 * (Math.log(-1 * instance.value(j))))); 102 } 103 else { 104 instance.setValue(j, Math.log(1 + instance.value(j))); 105 } 106 } 107 } 108 } 109 110 // preprocess training data 111 for (int i = 0; i < traindata.numInstances(); i++) { 112 Instance instance = traindata.instance(i); 113 for (int j = 0; j < testdata.numAttributes(); j++) { 114 if (traindata.attribute(j) != classAttribute && traindata.attribute(j).isNumeric()) 115 { 116 if (instance.value(j) < 0) { 117 instance.setValue(j, (-1 * (Math.log(-1 * instance.value(j))))); 118 } 119 else { 120 instance.setValue(j, Math.log(1 + instance.value(j))); 121 } 122 } 123 } 124 } 125 } 99 126 }
Note: See TracChangeset
for help on using the changeset viewer.