source: trunk/CrossPare/src/de/ugoe/cs/cpdp/training/RandomClass.java @ 48

Last change on this file since 48 was 41, checked in by sherbold, 9 years ago
  • formatted code and added copyrights
File size: 2.0 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.training;
16
17import java.util.Random;
18
19import weka.classifiers.AbstractClassifier;
20import weka.classifiers.Classifier;
21import weka.core.Instance;
22import weka.core.Instances;
23
24/**
25 * Assigns a random class label to the instance it is evaluated on.
26 *
27 * The range of class labels are hardcoded in fixedClassValues. This can later be extended to take
28 * values from the XML configuration.
29 */
30public class RandomClass extends AbstractClassifier implements ITrainingStrategy,
31    IWekaCompatibleTrainer
32{
33
34    private static final long serialVersionUID = 1L;
35
36    private double[] fixedClassValues =
37        { 0.0d, 1.0d };
38
39    @Override
40    public void setParameter(String parameters) {
41        // do nothing, maybe take percentages for distribution later
42    }
43
44    @Override
45    public void buildClassifier(Instances arg0) throws Exception {
46        // do nothing
47    }
48
49    @Override
50    public Classifier getClassifier() {
51        return this;
52    }
53
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    }
70}
Note: See TracBrowser for help on using the repository browser.