ASEvaluation.java
Upload User: rhdiban
Upload Date: 2013-08-09
Package Size: 15085k
Code Size: 4k
Category:

Windows Develop

Development Platform:

Java

  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.  *    ASEvaluation.java
  18.  *    Copyright (C) 1999 Mark Hall
  19.  *
  20.  */
  21. package weka.attributeSelection;
  22. import java.io.Serializable;
  23. import weka.core.Instance;
  24. import weka.core.Instances;
  25. import weka.core.SerializedObject;
  26. import weka.core.Utils;
  27. /** 
  28.  * Abstract attribute selection evaluation class
  29.  *
  30.  * @author Mark Hall (mhall@cs.waikato.ac.nz)
  31.  * @version $Revision: 1.8 $
  32.  */
  33. public abstract class ASEvaluation implements Serializable {
  34.   // ===============
  35.   // Public methods.
  36.   // ===============
  37.   /**
  38.    * Generates a attribute evaluator. Has to initialize all fields of the 
  39.    * evaluator that are not being set via options.
  40.    *
  41.    * @param data set of instances serving as training data 
  42.    * @exception Exception if the evaluator has not been 
  43.    * generated successfully
  44.    */
  45.   public abstract void buildEvaluator(Instances data) throws Exception;
  46.   /**
  47.    * Provides a chance for a attribute evaluator to do any special
  48.    * post processing of the selected attribute set.
  49.    *
  50.    * @param attributeSet the set of attributes found by the search
  51.    * @return a possibly ranked list of postprocessed attributes
  52.    * @exception Exception if postprocessing fails for some reason
  53.    */
  54.   public int [] postProcess(int [] attributeSet) 
  55.     throws Exception
  56.   {
  57.     return attributeSet;
  58.   }
  59.   /**
  60.    * Creates a new instance of an attribute/subset evaluator 
  61.    * given it's class name and
  62.    * (optional) arguments to pass to it's setOptions method. If the
  63.    * evaluator implements OptionHandler and the options parameter is
  64.    * non-null, the evaluator will have it's options set.
  65.    *
  66.    * @param evaluatorName the fully qualified class name of the evaluator
  67.    * @param options an array of options suitable for passing to setOptions. May
  68.    * be null.
  69.    * @return the newly created evaluator, ready for use.
  70.    * @exception Exception if the evaluator name is invalid, or the options
  71.    * supplied are not acceptable to the evaluator
  72.    */
  73.   public static ASEvaluation forName(String evaluatorName,
  74.      String [] options) throws Exception
  75.   {
  76.     return (ASEvaluation)Utils.forName(ASEvaluation.class,
  77.        evaluatorName,
  78.        options);
  79.   }
  80.   /**
  81.    * Creates copies of the current evaluator. Note that this method
  82.    * now uses Serialization to perform a deep copy, so the evaluator
  83.    * object must be fully Serializable. Any currently built model will
  84.    * now be copied as well.
  85.    *
  86.    * @param model an example evaluator to copy
  87.    * @param num the number of evaluator copies to create.
  88.    * @return an array of evaluators.
  89.    * @exception Exception if an error occurs 
  90.    */
  91.   public static ASEvaluation [] makeCopies(ASEvaluation model,
  92.  int num) throws Exception {
  93.     if (model == null) {
  94.       throw new Exception("No model evaluator set");
  95.     }
  96.     ASEvaluation [] evaluators = new ASEvaluation [num];
  97.     SerializedObject so = new SerializedObject(model);
  98.     for(int i = 0; i < evaluators.length; i++) {
  99.       evaluators[i] = (ASEvaluation) so.getObject();
  100.     }
  101.     return evaluators;
  102.   }
  103. }