- Timestamp:
- 09/24/15 10:59:05 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CrossPare/src/de/ugoe/cs/cpdp/training/RandomClass.java
r38 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.training; 2 16 … … 11 25 * Assigns a random class label to the instance it is evaluated on. 12 26 * 13 * The range of class labels are hardcoded in fixedClassValues. 14 * This can later be extended to take values from the XML configuration.27 * The range of class labels are hardcoded in fixedClassValues. This can later be extended to take 28 * values from the XML configuration. 15 29 */ 16 public class RandomClass extends AbstractClassifier implements ITrainingStrategy, IWekaCompatibleTrainer { 30 public class RandomClass extends AbstractClassifier implements ITrainingStrategy, 31 IWekaCompatibleTrainer 32 { 17 33 18 34 private static final long serialVersionUID = 1L; 19 35 20 private double[] fixedClassValues = {0.0d, 1.0d}; 21 22 @Override 23 public void setParameter(String parameters) { 24 // do nothing, maybe take percentages for distribution later 25 } 36 private double[] fixedClassValues = 37 { 0.0d, 1.0d }; 26 38 27 28 public void buildClassifier(Instances arg0) throws Exception{29 // do nothing 30 39 @Override 40 public void setParameter(String parameters) { 41 // do nothing, maybe take percentages for distribution later 42 } 31 43 32 33 public Classifier getClassifier(){34 return this; 35 44 @Override 45 public void buildClassifier(Instances arg0) throws Exception { 46 // do nothing 47 } 36 48 37 38 public void apply(Instances traindata) {39 // nothing to do 40 49 @Override 50 public Classifier getClassifier() { 51 return this; 52 } 41 53 42 @Override 43 public String getName() { 44 return "RandomClass"; 45 } 46 47 @Override 48 public double classifyInstance(Instance instance) { 49 Random rand = new Random(); 50 int randomNum = rand.nextInt(this.fixedClassValues.length); 51 return this.fixedClassValues[randomNum]; 52 } 54 @Override 55 public void apply(Instances traindata) { 56 // nothing to do 57 } 58 59 @Override 60 public String getName() { 61 return "RandomClass"; 62 } 63 64 @Override 65 public double classifyInstance(Instance instance) { 66 Random rand = new Random(); 67 int randomNum = rand.nextInt(this.fixedClassValues.length); 68 return this.fixedClassValues[randomNum]; 69 } 53 70 }
Note: See TracChangeset
for help on using the changeset viewer.