- Timestamp:
- 07/18/16 12:26:03 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CrossPare/src/de/ugoe/cs/cpdp/dataselection/LACE2.java
r120 r135 12 12 // See the License for the specific language governing permissions and 13 13 // limitations under the License. 14 15 14 16 15 package de.ugoe.cs.cpdp.dataselection; … … 39 38 public class LACE2 implements ISetWiseDataselectionStrategy { 40 39 40 /** 41 * percentage of data selected by the internal CLIFF. 42 */ 41 43 private double percentage = 0.10; 42 44 45 /* 46 * (non-Javadoc) 47 * 48 * @see de.ugoe.cs.cpdp.IParameterizable#setParameter(java.lang.String) 49 */ 43 50 @Override 44 51 public void setParameter(String parameters) { 45 if ( parameters!=null && !parameters.isEmpty()) {52 if (parameters != null && !parameters.isEmpty()) { 46 53 percentage = Double.parseDouble(parameters); 47 54 } 48 55 } 49 56 57 /* 58 * (non-Javadoc) 59 * 60 * @see de.ugoe.cs.cpdp.dataselection.ISetWiseDataselectionStrategy#apply(weka.core.Instances, 61 * org.apache.commons.collections4.list.SetUniqueList) 62 */ 50 63 @Override 51 64 public void apply(Instances testdata, SetUniqueList<Instances> traindataSet) { 52 65 Instances selectedData = new Instances(testdata); 53 66 selectedData.clear(); 54 67 55 68 LinkedList<Instances> traindataCopy = new LinkedList<>(traindataSet); 56 69 Collections.shuffle(traindataCopy); 57 70 58 71 CLIFF cliff = new CLIFF(); 59 72 cliff.setParameter(Double.toString(percentage)); … … 61 74 Median median = new Median(); 62 75 double minDist = Double.MIN_VALUE; 63 64 for ( Instances traindata : traindataCopy) {76 77 for (Instances traindata : traindataCopy) { 65 78 Instances cliffedData = cliff.applyCLIFF(traindata); 66 if ( minDist==Double.MIN_VALUE) {79 if (minDist == Double.MIN_VALUE) { 67 80 // determine distance for leader-follower algorithm 68 81 Instances sample; 69 if ( traindata.size()>100) {82 if (traindata.size() > 100) { 70 83 Resample resample = new Resample(); 71 resample.setSampleSizePercent(100.0 /traindata.size()*100.0);84 resample.setSampleSizePercent(100.0 / traindata.size() * 100.0); 72 85 resample.setBiasToUniformClass(0.0); 73 86 resample.setNoReplacement(true); … … 79 92 throw new RuntimeException(e); 80 93 } 81 } else { 94 } 95 else { 82 96 sample = new Instances(traindata); 83 97 } 84 98 double[] distances = new double[sample.size()]; 85 for ( int i=0; i<sample.size(); i++) {99 for (int i = 0; i < sample.size(); i++) { 86 100 Instance unlikeNeighbor = morph.getNearestUnlikeNeighbor(sample.get(i), sample); 87 distances[i] = MathArrays.distance(WekaUtils.instanceValues(sample.get(i)), WekaUtils.instanceValues(unlikeNeighbor)); 101 distances[i] = MathArrays.distance(WekaUtils.instanceValues(sample.get(i)), 102 WekaUtils.instanceValues(unlikeNeighbor)); 88 103 } 89 104 minDist = median.evaluate(distances); 90 105 } 91 for( int i=0; i<cliffedData.size(); i++ ) { 92 Instance unlikeNeighbor = morph.getNearestUnlikeNeighbor(cliffedData.get(i), selectedData); 93 if( unlikeNeighbor==null ) { 106 for (int i = 0; i < cliffedData.size(); i++) { 107 Instance unlikeNeighbor = 108 morph.getNearestUnlikeNeighbor(cliffedData.get(i), selectedData); 109 if (unlikeNeighbor == null) { 94 110 selectedData.add(cliffedData.get(i)); 95 } else { 96 double distance = MathArrays.distance(WekaUtils.instanceValues(cliffedData.get(i)), WekaUtils.instanceValues(unlikeNeighbor)); 97 if( distance>minDist ) { 111 } 112 else { 113 double distance = 114 MathArrays.distance(WekaUtils.instanceValues(cliffedData.get(i)), 115 WekaUtils.instanceValues(unlikeNeighbor)); 116 if (distance > minDist) { 98 117 morph.morphInstance(cliffedData.get(i), cliffedData); 99 118 selectedData.add(cliffedData.get(i)); … … 103 122 } 104 123 } 105 124 106 125 }
Note: See TracChangeset
for help on using the changeset viewer.