~ubuntu-branches/ubuntu/trusty/weka/trusty-proposed

« back to all changes in this revision

Viewing changes to weka/attributeSelection/ASSearch.java

  • Committer: Bazaar Package Importer
  • Author(s): Soeren Sonnenburg
  • Date: 2008-02-24 09:18:45 UTC
  • Revision ID: james.westby@ubuntu.com-20080224091845-1l8zy6fm6xipbzsr
Tags: upstream-3.5.7+tut1
ImportĀ upstreamĀ versionĀ 3.5.7+tut1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 *    ASSearch.java
 
19
 *    Copyright (C) 1999 University of Waikato, Hamilton, New Zealand
 
20
 *
 
21
 */
 
22
 
 
23
package weka.attributeSelection;
 
24
 
 
25
import weka.core.Instances;
 
26
import weka.core.SerializedObject;
 
27
import weka.core.Utils;
 
28
 
 
29
import java.io.Serializable;
 
30
 
 
31
/** 
 
32
 * Abstract attribute selection search class.
 
33
 *
 
34
 * @author Mark Hall (mhall@cs.waikato.ac.nz)
 
35
 * @version $Revision: 1.11 $
 
36
 */
 
37
public abstract class ASSearch implements Serializable {
 
38
 
 
39
  /** for serialization */
 
40
  private static final long serialVersionUID = 7591673350342236548L;
 
41
  
 
42
  // ===============
 
43
  // Public methods.
 
44
  // ===============
 
45
  
 
46
  /**
 
47
   * Searches the attribute subset/ranking space.
 
48
   *
 
49
   * @param ASEvaluator the attribute evaluator to guide the search
 
50
   * @param data the training instances.
 
51
   * @return an array (not necessarily ordered) of selected attribute indexes
 
52
   * @throws Exception if the search can't be completed
 
53
   */
 
54
  public abstract int [] search(ASEvaluation ASEvaluator,
 
55
                                Instances data) throws Exception;
 
56
 
 
57
  /**
 
58
   * Creates a new instance of a search class given it's class name and
 
59
   * (optional) arguments to pass to it's setOptions method. If the
 
60
   * search method implements OptionHandler and the options parameter is
 
61
   * non-null, the search method will have it's options set.
 
62
   *
 
63
   * @param searchName the fully qualified class name of the search class
 
64
   * @param options an array of options suitable for passing to setOptions. May
 
65
   * be null.
 
66
   * @return the newly created search object, ready for use.
 
67
   * @throws Exception if the search class name is invalid, or the options
 
68
   * supplied are not acceptable to the search class.
 
69
   */
 
70
  public static ASSearch forName(String searchName,
 
71
                                 String [] options) throws Exception {
 
72
    return (ASSearch)Utils.forName(ASSearch.class,
 
73
                                   searchName,
 
74
                                   options);
 
75
  }
 
76
 
 
77
  /**
 
78
   * Creates copies of the current search scheme. Note that this method
 
79
   * now uses Serialization to perform a deep copy, so the search
 
80
   * object must be fully Serializable. Any currently built model will
 
81
   * now be copied as well.
 
82
   *
 
83
   * @param model an example search scheme to copy
 
84
   * @param num the number of search scheme copies to create.
 
85
   * @return an array of search schemes.
 
86
   * @throws Exception if an error occurs 
 
87
   */
 
88
  public static ASSearch[] makeCopies(ASSearch model, int num) throws Exception {
 
89
 
 
90
    if (model == null)
 
91
      throw new Exception("No model search scheme set");
 
92
      
 
93
    ASSearch[] result = new ASSearch[num];
 
94
    SerializedObject so = new SerializedObject(model);
 
95
    for (int i = 0; i < result.length; i++)
 
96
      result[i] = (ASSearch) so.getObject();
 
97
 
 
98
    return result;
 
99
  }
 
100
}