source: src/main/java/weka/attributeSelection/CostSensitiveSubsetEval.java @ 27

Last change on this file since 27 was 4, checked in by gnappo, 14 years ago

Import di weka.

File size: 3.8 KB
RevLine 
[4]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 *    CostSensitiveSubsetEval.java
19 *    Copyright (C) 2008 University of Waikato, Hamilton, New Zealand
20 *
21 */
22
23package  weka.attributeSelection;
24
25import weka.core.OptionHandler;
26import weka.core.RevisionUtils;
27
28import java.util.BitSet;
29import java.io.Serializable;
30
31/**
32 <!-- globalinfo-start -->
33 * A meta subset evaluator that makes its base subset evaluator cost-sensitive.
34 * <p/>
35 <!-- globalinfo-end -->
36 *
37 <!-- options-start -->
38 * Valid options are: <p/>
39 *
40 * <pre> -C &lt;cost file name&gt;
41 *  File name of a cost matrix to use. If this is not supplied,
42 *  a cost matrix will be loaded on demand. The name of the
43 *  on-demand file is the relation name of the training data
44 *  plus ".cost", and the path to the on-demand file is
45 *  specified with the -N option.</pre>
46 *
47 * <pre> -N &lt;directory&gt;
48 *  Name of a directory to search for cost files when loading
49 *  costs on demand (default current directory).</pre>
50 *
51 * <pre> -cost-matrix &lt;matrix&gt;
52 *  The cost matrix in Matlab single line format.</pre>
53 *
54 * <pre> -S &lt;integer&gt;
55 *  The seed to use for random number generation.</pre>
56 *
57 * <pre> -W
58 *  Full name of base evaluator.
59 *  (default: weka.attributeSelection.CfsSubsetEval)</pre>
60 *
61 * <pre>
62 * Options specific to evaluator weka.attributeSelection.CfsSubsetEval:
63 * </pre>
64 *
65 * <pre> -M
66 *  Treat missing values as a seperate value.</pre>
67 *
68 * <pre> -L
69 *  Don't include locally predictive attributes.</pre>
70 *
71 <!-- options-end -->
72 *
73 * @author Mark Hall (mhall{[at]}pentaho{[dot]}com)
74 * @version $Revision: 5563 $
75 */
76public class CostSensitiveSubsetEval
77  extends CostSensitiveASEvaluation
78  implements Serializable, SubsetEvaluator, OptionHandler {
79
80  /** For serialization */
81  static final long serialVersionUID = 2924546096103426700L;
82
83  /**
84   * Default constructor.
85   */
86  public CostSensitiveSubsetEval() {
87    setEvaluator(new CfsSubsetEval());
88  }
89
90  /**
91   * Set the base evaluator.
92   *
93   * @param newEvaluator the evaluator to use.
94   * @throws IllegalArgumentException if the evaluator is not an instance of SubsetEvaluator
95   */
96  public void setEvaluator(ASEvaluation newEvaluator) throws IllegalArgumentException {
97    if (!(newEvaluator instanceof SubsetEvaluator)) {
98      throw new IllegalArgumentException("Evaluator must be an SubsetEvaluator!");
99    }
100
101    m_evaluator = newEvaluator;
102  }
103
104  /**
105   * Evaluates a subset of attributes. Delegates the actual evaluation to
106   * the base subset evaluator.
107   *
108   * @param subset a bitset representing the attribute subset to be
109   * evaluated
110   * @return the "merit" of the subset
111   * @exception Exception if the subset could not be evaluated
112   */
113  public double evaluateSubset(BitSet subset) throws Exception {
114    return ((SubsetEvaluator)m_evaluator).evaluateSubset(subset);
115  }
116
117  /**
118   * Returns the revision string.
119   *
120   * @return            the revision
121   */
122  public String getRevision() {
123    return RevisionUtils.extract("$Revision: 5563 $");
124  }
125
126  /**
127   * Main method for testing this class.
128   *
129   * @param args the options
130   */
131  public static void main (String[] args) {
132    runEvaluator(new CostSensitiveSubsetEval(), args);
133  }
134}
135
Note: See TracBrowser for help on using the repository browser.