| 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 | |
|---|
| 15 | package de.ugoe.cs.cpdp.wekaclassifier; |
|---|
| 16 | |
|---|
| 17 | import java.util.Random; |
|---|
| 18 | |
|---|
| 19 | import weka.classifiers.AbstractClassifier; |
|---|
| 20 | import weka.core.Instance; |
|---|
| 21 | import weka.core.Instances; |
|---|
| 22 | |
|---|
| 23 | /** |
|---|
| 24 | * Assigns a random class label to the instance it is evaluated on. |
|---|
| 25 | * |
|---|
| 26 | * The range of class labels are hardcoded in fixedClassValues. This can later be extended to take |
|---|
| 27 | * values from the XML configuration. |
|---|
| 28 | */ |
|---|
| 29 | public class RandomClass extends AbstractClassifier { |
|---|
| 30 | |
|---|
| 31 | private static final long serialVersionUID = 1L; |
|---|
| 32 | |
|---|
| 33 | private double[] fixedClassValues = |
|---|
| 34 | { 0.0d, 1.0d }; |
|---|
| 35 | |
|---|
| 36 | @Override |
|---|
| 37 | public void buildClassifier(Instances arg0) throws Exception { |
|---|
| 38 | // do nothing |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | @Override |
|---|
| 42 | public double classifyInstance(Instance instance) { |
|---|
| 43 | Random rand = new Random(); |
|---|
| 44 | int randomNum = rand.nextInt(this.fixedClassValues.length); |
|---|
| 45 | return this.fixedClassValues[randomNum]; |
|---|
| 46 | } |
|---|
| 47 | } |
|---|