source: src/main/java/weka/classifiers/trees/adtree/Splitter.java @ 14

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

Import di weka.

File size: 3.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 *    Splitter.java
19 *    Copyright (C) 2001 University of Waikato, Hamilton, New Zealand
20 *
21 */
22
23package weka.classifiers.trees.adtree;
24
25import weka.core.Instance;
26import weka.core.Instances;
27import weka.core.RevisionHandler;
28
29import java.io.Serializable;
30
31/**
32 * Abstract class representing a splitter node in an alternating tree.
33 *
34 * @author Richard Kirkby (rkirkby@cs.waikato.ac.nz)
35 * @version $Revision: 1.5 $
36 */
37public abstract class Splitter
38  implements Serializable, Cloneable, RevisionHandler {
39
40  /** for serialization */
41  private static final long serialVersionUID = 8190449848490055L;
42
43  /** The number this node was in the order of nodes added to the tree */
44  public int orderAdded;
45
46  /**
47   * Gets the number of branches of the split.
48   *
49   * @return the number of branches
50   */
51  public abstract int getNumOfBranches();
52
53  /**
54   * Gets the index of the branch that an instance applies to. Returns -1 if no branches
55   * apply.
56   *
57   * @param i the instance
58   * @return the branch index
59   */
60  public abstract int branchInstanceGoesDown(Instance i);
61
62  /**
63   * Gets the subset of instances that apply to a particluar branch of the split. If the
64   * branch index is -1, the subset will consist of those instances that don't apply to
65   * any branch.
66   *
67   * @param branch the index of the branch
68   * @param sourceInstances the instances from which to find the subset
69   * @return the set of instances that apply
70   */
71  public abstract ReferenceInstances instancesDownBranch(int branch, Instances sourceInstances);
72
73  /**
74   * Gets the string describing the attributes the split depends on.
75   * i.e. the left hand side of the description of the split.
76   *
77   * @param dataset the dataset that the split is based on
78   * @return a string describing the attributes
79   */
80  public abstract String attributeString(Instances dataset);
81
82  /**
83   * Gets the string describing the comparision the split depends on for a particular
84   * branch. i.e. the right hand side of the description of the split.
85   *
86   * @param branchNum the branch of the split
87   * @param dataset the dataset that the split is based on
88   * @return a string describing the comparison
89   */
90  public abstract String comparisonString(int branchNum, Instances dataset);
91
92  /**
93   * Tests whether two splitters are equivalent.
94   *
95   * @param compare the splitter to compare with
96   * @return whether or not they match
97   */
98  public abstract boolean equalTo(Splitter compare);
99
100  /**
101   * Sets the child for a branch of the split.
102   *
103   * @param branchNum the branch to set the child for
104   * @param childPredictor the new child
105   */
106  public abstract void setChildForBranch(int branchNum, PredictionNode childPredictor);
107
108  /**
109   * Gets the child for a branch of the split.
110   *
111   * @param branchNum the branch to get the child for
112   * @return the child
113   */
114  public abstract PredictionNode getChildForBranch(int branchNum);
115
116  /**
117   * Clones this node. Performs a deep copy, recursing through the tree.
118   *
119   * @return a clone
120   */
121  public abstract Object clone();
122}
Note: See TracBrowser for help on using the repository browser.