source: branches/MetisMQI/src/test/java/weka/classifiers/meta/ThresholdSelectorDummyClassifier.java

Last change on this file was 29, checked in by gnappo, 14 years ago

Taggata versione per la demo e aggiunto branch.

File size: 2.8 KB
Line 
1/*
2 *    This program is free software; you can redistribute it and/or modify
3 *    it under the terms of the GNU General Public License as published by
4 *    the Free Software Foundation; either version 2 of the License, or
5 *    (at your option) any later version.
6 *
7 *    This program is distributed in the hope that it will be useful,
8 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 *    GNU General Public License for more details.
11 *
12 *    You should have received a copy of the GNU General Public License
13 *    along with this program; if not, write to the Free Software
14 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 */
16
17/*
18 * Copyright (C) 2002 University of Waikato
19 */
20
21package weka.classifiers.meta;
22
23import weka.core.Capabilities;
24import weka.core.Capabilities.Capability;
25import weka.core.Instance;
26import weka.core.Instances;
27import weka.core.RevisionUtils;
28import weka.classifiers.Classifier;
29import weka.classifiers.AbstractClassifier;
30
31/**
32 * Dummy classifier - used in ThresholdSelectorTest.
33 *
34 * @author <a href="mailto:len@reeltwo.com">Len Trigg</a>
35 * @author FracPete (fracpet at waikato dor ac dot nz)
36 * @version $Revision: 5928 $
37 * @see ThresholdSelectorTest
38 */
39public class ThresholdSelectorDummyClassifier 
40  extends AbstractClassifier {
41
42  /** for serialization */
43  private static final long serialVersionUID = -2040984810834943903L;
44 
45  private double[] m_Preds;
46  private int m_Pos;
47
48  public ThresholdSelectorDummyClassifier(double[] preds) {
49    m_Preds = new double[preds.length];
50    for (int i = 0; i < preds.length; i++)
51      m_Preds[i] = preds[i];
52  }
53
54  /**
55   * Returns default capabilities of the classifier.
56   *
57   * @return      the capabilities of this classifier
58   */
59  public Capabilities getCapabilities() {
60    Capabilities result = super.getCapabilities();
61
62    // attribute
63    result.enableAllAttributes();
64    result.disable(Capability.STRING_ATTRIBUTES);
65    result.disable(Capability.RELATIONAL_ATTRIBUTES);
66
67    // class
68    result.enable(Capability.NOMINAL_CLASS);
69   
70    return result;
71  }
72
73  public void buildClassifier(Instances train) { 
74  }
75
76  public double[] distributionForInstance(Instance test) throws Exception {
77    double[] result = new double[test.numClasses()];
78    int pred = 0;
79    result[pred] = m_Preds[m_Pos];
80    double residual = (1.0 - result[pred]) / (result.length - 1);
81    for (int i = 0; i < result.length; i++) {
82      if (i != pred) {
83        result[i] = residual;
84      }
85    }
86    m_Pos = (m_Pos + 1) % m_Preds.length;
87    return result;
88  }
89 
90  /**
91   * Returns the revision string.
92   *
93   * @return            the revision
94   */
95  public String getRevision() {
96    return RevisionUtils.extract("$Revision: 5928 $");
97  }
98}
99
Note: See TracBrowser for help on using the repository browser.