source: branches/MetisMQI/src/main/java/weka/attributeSelection/ASSearch.java @ 37

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

Taggata versione per la demo e aggiunto branch.

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