source: src/main/java/weka/attributeSelection/CostSensitiveAttributeEval.java @ 7

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

Import di weka.

File size: 4.7 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 *    CostSensitiveAttributeEval.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.ReliefFAttributeEval)</pre>
60 *
61 * <pre>
62 * Options specific to evaluator weka.attributeSelection.ReliefFAttributeEval:
63 * </pre>
64 *
65 * <pre> -M &lt;num instances&gt;
66 *  Specify the number of instances to
67 *  sample when estimating attributes.
68 *  If not specified, then all instances
69 *  will be used.</pre>
70 *
71 * <pre> -D &lt;seed&gt;
72 *  Seed for randomly sampling instances.
73 *  (Default = 1)</pre>
74 *
75 * <pre> -K &lt;number of neighbours&gt;
76 *  Number of nearest neighbours (k) used
77 *  to estimate attribute relevances
78 *  (Default = 10).</pre>
79 *
80 * <pre> -W
81 *  Weight nearest neighbours by distance</pre>
82 *
83 * <pre> -A &lt;num&gt;
84 *  Specify sigma value (used in an exp
85 *  function to control how quickly
86 *  weights for more distant instances
87 *  decrease. Use in conjunction with -W.
88 *  Sensible value=1/5 to 1/10 of the
89 *  number of nearest neighbours.
90 *  (Default = 2)</pre>
91 *
92 <!-- options-end -->
93 *
94 * @author Mark Hall (mhall{[at]}pentaho{[dot]}com)
95 * @version $Revision: 5563 $
96 */
97public class CostSensitiveAttributeEval
98  extends CostSensitiveASEvaluation
99  implements Serializable, AttributeEvaluator, OptionHandler {
100
101  /** For serialization */
102  static final long serialVersionUID = 4484876541145458447L;
103
104  /**
105   * Default constructor.
106   */
107  public CostSensitiveAttributeEval() {
108    setEvaluator(new ReliefFAttributeEval());
109  }
110 
111  /**
112   * Return the name of the default evaluator.
113   *
114   * @return the name of the default evaluator
115   */
116  public String defaultEvaluatorString() {
117    return "weka.attributeSelection.ReliefFAttributeEval";
118  }
119
120  /**
121   * Set the base evaluator.
122   *
123   * @param newEvaluator the evaluator to use.
124   * @throws IllegalArgumentException if the evaluator is not an instance of AttributeEvaluator
125   */
126  public void setEvaluator(ASEvaluation newEvaluator) throws IllegalArgumentException {
127    if (!(newEvaluator instanceof AttributeEvaluator)) {
128      throw new IllegalArgumentException("Evaluator must be an AttributeEvaluator!");
129    }
130
131    m_evaluator = newEvaluator;
132  }
133
134  /**
135   * Evaluates an individual attribute. Delegates the actual evaluation to the
136   * base attribute evaluator.
137   *
138   * @param attribute the index of the attribute to be evaluated
139   * @return the "merit" of the attribute
140   * @exception Exception if the attribute could not be evaluated
141   */
142  public double evaluateAttribute(int attribute) throws Exception {
143    return ((AttributeEvaluator)m_evaluator).evaluateAttribute(attribute);
144  }
145
146  /**
147   * Returns the revision string.
148   *
149   * @return            the revision
150   */
151  public String getRevision() {
152    return RevisionUtils.extract("$Revision: 5563 $");
153  }
154
155  /**
156   * Main method for testing this class.
157   *
158   * @param args the options
159   */
160  public static void main (String[] args) {
161    runEvaluator(new CostSensitiveAttributeEval(), args);
162  }
163}
164
Note: See TracBrowser for help on using the repository browser.