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.
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.
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.
19
* Copyright (C) 1999 University of Waikato, Hamilton, New Zealand
23
package weka.attributeSelection;
25
import weka.core.Instances;
26
import weka.core.SerializedObject;
27
import weka.core.Utils;
29
import java.io.Serializable;
32
* Abstract attribute selection search class.
34
* @author Mark Hall (mhall@cs.waikato.ac.nz)
35
* @version $Revision: 1.11 $
37
public abstract class ASSearch implements Serializable {
39
/** for serialization */
40
private static final long serialVersionUID = 7591673350342236548L;
47
* Searches the attribute subset/ranking space.
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
54
public abstract int [] search(ASEvaluation ASEvaluator,
55
Instances data) throws Exception;
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.
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
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.
70
public static ASSearch forName(String searchName,
71
String [] options) throws Exception {
72
return (ASSearch)Utils.forName(ASSearch.class,
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.
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
88
public static ASSearch[] makeCopies(ASSearch model, int num) throws Exception {
91
throw new Exception("No model search scheme set");
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();