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