Ignore:
Timestamp:
09/24/15 10:59:05 (9 years ago)
Author:
sherbold
Message:
  • formatted code and added copyrights
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 
    115package de.ugoe.cs.cpdp.training; 
    216 
     
    1125 * Assigns a random class label to the instance it is evaluated on. 
    1226 *  
    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. 
    1529 */ 
    16 public class RandomClass extends AbstractClassifier implements ITrainingStrategy, IWekaCompatibleTrainer { 
     30public class RandomClass extends AbstractClassifier implements ITrainingStrategy, 
     31    IWekaCompatibleTrainer 
     32{ 
    1733 
    18         private static final long serialVersionUID = 1L; 
     34    private static final long serialVersionUID = 1L; 
    1935 
    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 }; 
    2638 
    27         @Override 
    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    } 
    3143 
    32         @Override 
    33         public Classifier getClassifier() { 
    34                 return this; 
    35         } 
     44    @Override 
     45    public void buildClassifier(Instances arg0) throws Exception { 
     46        // do nothing 
     47    } 
    3648 
    37         @Override 
    38         public void apply(Instances traindata) { 
    39                 // nothing to do 
    40         } 
     49    @Override 
     50    public Classifier getClassifier() { 
     51        return this; 
     52    } 
    4153 
    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    } 
    5370} 
Note: See TracChangeset for help on using the changeset viewer.