[86] | 1 | // Copyright 2015 Georg-August-Universität Göttingen, Germany |
---|
[41] | 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 | |
---|
[79] | 15 | package de.ugoe.cs.cpdp.wekaclassifier; |
---|
[34] | 16 | |
---|
| 17 | import java.util.Random; |
---|
| 18 | |
---|
| 19 | import weka.classifiers.AbstractClassifier; |
---|
| 20 | import weka.core.Instance; |
---|
| 21 | import weka.core.Instances; |
---|
| 22 | |
---|
| 23 | /** |
---|
[135] | 24 | * <p> |
---|
[34] | 25 | * Assigns a random class label to the instance it is evaluated on. |
---|
[135] | 26 | * </p> |
---|
[41] | 27 | * The range of class labels are hardcoded in fixedClassValues. This can later be extended to take |
---|
| 28 | * values from the XML configuration. |
---|
[135] | 29 | * </p> |
---|
| 30 | * |
---|
| 31 | * @author Alexander Trautsch |
---|
[34] | 32 | */ |
---|
[78] | 33 | public class RandomClass extends AbstractClassifier { |
---|
[34] | 34 | |
---|
[135] | 35 | /** |
---|
| 36 | * default serialization id |
---|
| 37 | */ |
---|
[41] | 38 | private static final long serialVersionUID = 1L; |
---|
[34] | 39 | |
---|
[135] | 40 | /** |
---|
| 41 | * class values |
---|
| 42 | */ |
---|
[41] | 43 | private double[] fixedClassValues = |
---|
| 44 | { 0.0d, 1.0d }; |
---|
[34] | 45 | |
---|
[135] | 46 | /* |
---|
| 47 | * (non-Javadoc) |
---|
| 48 | * |
---|
| 49 | * @see weka.classifiers.Classifier#buildClassifier(weka.core.Instances) |
---|
| 50 | */ |
---|
[41] | 51 | @Override |
---|
| 52 | public void buildClassifier(Instances arg0) throws Exception { |
---|
| 53 | // do nothing |
---|
| 54 | } |
---|
[34] | 55 | |
---|
[135] | 56 | /* |
---|
| 57 | * (non-Javadoc) |
---|
| 58 | * |
---|
| 59 | * @see weka.classifiers.AbstractClassifier#classifyInstance(weka.core.Instance) |
---|
| 60 | */ |
---|
[41] | 61 | @Override |
---|
| 62 | public double classifyInstance(Instance instance) { |
---|
| 63 | Random rand = new Random(); |
---|
| 64 | int randomNum = rand.nextInt(this.fixedClassValues.length); |
---|
| 65 | return this.fixedClassValues[randomNum]; |
---|
| 66 | } |
---|
[34] | 67 | } |
---|