source: trunk/CrossPare/src/de/ugoe/cs/cpdp/wekaclassifier/RandomClass.java @ 146

Last change on this file since 146 was 135, checked in by sherbold, 8 years ago
  • code documentation and formatting
File size: 1.9 KB
Line 
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
15package de.ugoe.cs.cpdp.wekaclassifier;
16
17import java.util.Random;
18
19import weka.classifiers.AbstractClassifier;
20import weka.core.Instance;
21import weka.core.Instances;
22
23/**
24 * <p>
25 * Assigns a random class label to the instance it is evaluated on.
26 * </p>
27 * The range of class labels are hardcoded in fixedClassValues. This can later be extended to take
28 * values from the XML configuration.
29 * </p>
30 *
31 * @author Alexander Trautsch
32 */
33public class RandomClass extends AbstractClassifier {
34
35    /**
36     * default serialization id
37     */
38    private static final long serialVersionUID = 1L;
39
40    /**
41     * class values
42     */
43    private double[] fixedClassValues =
44        { 0.0d, 1.0d };
45
46    /*
47     * (non-Javadoc)
48     *
49     * @see weka.classifiers.Classifier#buildClassifier(weka.core.Instances)
50     */
51    @Override
52    public void buildClassifier(Instances arg0) throws Exception {
53        // do nothing
54    }
55
56    /*
57     * (non-Javadoc)
58     *
59     * @see weka.classifiers.AbstractClassifier#classifyInstance(weka.core.Instance)
60     */
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    }
67}
Note: See TracBrowser for help on using the repository browser.