weka.classifiers.trees
Class RandomTree

java.lang.Object
  extended byweka.classifiers.Classifier
      extended byweka.classifiers.DistributionClassifier
          extended byweka.classifiers.trees.RandomTree
All Implemented Interfaces:
java.lang.Cloneable, OptionHandler, Randomizable, java.io.Serializable, WeightedInstancesHandler

public class RandomTree
extends DistributionClassifier
implements OptionHandler, WeightedInstancesHandler, Randomizable

Class for constructing a tree that considers K random features at each node. Performs no pruning.

See Also:
Serialized Form

Field Summary
protected  int m_Attribute
          The attribute to split on.
protected  double[] m_ClassProbs
          Class probabilities from the training data.
protected  boolean m_Debug
          Debug info
protected  double[][] m_Distribution
          The class distribution from the training data.
protected  Instances m_Info
          The header information.
protected  int m_KValue
          The number of attributes considered for a split.
protected  double m_MinNum
          Minimum number of instances for leaf.
protected  double[] m_Prop
          The proportions of training instances going down each branch.
protected  java.util.Random m_random
          Random number generator.
protected  int m_randomSeed
          The random seed to use.
protected  double m_SplitPoint
          The split point.
protected  RandomTree[] m_Successors
          The subtrees appended to this tree.
 
Constructor Summary
RandomTree()
           
 
Method Summary
 void buildClassifier(Instances data)
          Builds classifier.
protected  void buildTree(int[][] sortedIndices, double[][] weights, Instances data, double[] classProbs, Instances header, double minNum, boolean debug, int[] attIndicesWindow)
          Recursively generates a tree.
protected  double distribution(double[][] props, double[][][] dists, int att, int[] sortedIndices, double[] weights, Instances data)
          Computes class distribution for an attribute.
 double[] distributionForInstance(Instance instance)
          Computes class distribution of an instance using the decision tree.
protected  double gain(double[][] dist, double priorVal)
          Computes value of splitting criterion after split.
 boolean getDebug()
          Get the value of Debug.
 int getKValue()
          Get the value of K.
 double getMinNum()
          Get the value of MinNum.
 java.lang.String[] getOptions()
          Gets options from this classifier.
 int getSeed()
          Gets the seed for the random number generations
protected  java.lang.String leafString()
          Outputs a leaf.
 java.util.Enumeration listOptions()
          Lists the command-line options for this classifier.
static void main(java.lang.String[] argv)
          Main method for this class.
 int numNodes()
          Computes size of the tree.
protected  double priorVal(double[][] dist)
          Computes value of splitting criterion before split.
 void setDebug(boolean newDebug)
          Set the value of Debug.
 void setKValue(int k)
          Set the value of K.
 void setMinNum(double newMinNum)
          Set the value of MinNum.
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
 void setSeed(int seed)
          Set the seed for random number generation.
protected  void splitData(int[][][] subsetIndices, double[][][] subsetWeights, int att, double splitPoint, int[][] sortedIndices, double[][] weights, double[][] dist, Instances data)
          Splits instances into subsets.
 java.lang.String toGraph()
          Outputs the decision tree as a graph
 int toGraph(java.lang.StringBuffer text, int num)
          Outputs one node for graph.
 java.lang.String toString()
          Outputs the decision tree.
protected  java.lang.String toString(int level)
          Recursively outputs the tree.
 
Methods inherited from class weka.classifiers.DistributionClassifier
calculateEntropy, calculateLabeledInstanceMargin, calculateMargin, classifyInstance
 
Methods inherited from class weka.classifiers.Classifier
forName, makeCopies
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_Successors

protected RandomTree[] m_Successors
The subtrees appended to this tree.


m_Attribute

protected int m_Attribute
The attribute to split on.


m_SplitPoint

protected double m_SplitPoint
The split point.


m_Distribution

protected double[][] m_Distribution
The class distribution from the training data.


m_Info

protected Instances m_Info
The header information.


m_Prop

protected double[] m_Prop
The proportions of training instances going down each branch.


m_ClassProbs

protected double[] m_ClassProbs
Class probabilities from the training data.


m_MinNum

protected double m_MinNum
Minimum number of instances for leaf.


m_Debug

protected boolean m_Debug
Debug info


m_KValue

protected int m_KValue
The number of attributes considered for a split.


m_random

protected java.util.Random m_random
Random number generator.


m_randomSeed

protected int m_randomSeed
The random seed to use.

Constructor Detail

RandomTree

public RandomTree()
Method Detail

getMinNum

public double getMinNum()
Get the value of MinNum.

Returns:
Value of MinNum.

setMinNum

public void setMinNum(double newMinNum)
Set the value of MinNum.

Parameters:
newMinNum - Value to assign to MinNum.

getKValue

public int getKValue()
Get the value of K.

Returns:
Value of K.

setKValue

public void setKValue(int k)
Set the value of K.

Parameters:
k - Value to assign to K.

getDebug

public boolean getDebug()
Get the value of Debug.

Returns:
Value of Debug.

setDebug

public void setDebug(boolean newDebug)
Set the value of Debug.

Parameters:
newDebug - Value to assign to Debug.

setSeed

public void setSeed(int seed)
Set the seed for random number generation.

Specified by:
setSeed in interface Randomizable
Parameters:
seed - the seed

getSeed

public int getSeed()
Gets the seed for the random number generations

Specified by:
getSeed in interface Randomizable
Returns:
the seed for the random number generation

listOptions

public java.util.Enumeration listOptions()
Lists the command-line options for this classifier.

Specified by:
listOptions in interface OptionHandler
Returns:
an enumeration of all available options.

getOptions

public java.lang.String[] getOptions()
Gets options from this classifier.

Specified by:
getOptions in interface OptionHandler
Returns:
the list of current option settings as an array of strings

setOptions

public void setOptions(java.lang.String[] options)
                throws java.lang.Exception
Parses a given list of options.

Specified by:
setOptions in interface OptionHandler
Parameters:
options - the list of options as an array of strings
Throws:
java.lang.Exception - if an option is not supported

buildClassifier

public void buildClassifier(Instances data)
                     throws java.lang.Exception
Builds classifier.

Specified by:
buildClassifier in class Classifier
Parameters:
data - set of instances serving as training data
Throws:
java.lang.Exception - if the classifier has not been generated successfully

distributionForInstance

public double[] distributionForInstance(Instance instance)
                                 throws java.lang.Exception
Computes class distribution of an instance using the decision tree.

Specified by:
distributionForInstance in class DistributionClassifier
Parameters:
instance - the instance to be classified
Returns:
an array containing the estimated membership probabilities of the test instance in each class (this should sum to at most 1)
Throws:
java.lang.Exception - if distribution could not be computed successfully

toGraph

public java.lang.String toGraph()
Outputs the decision tree as a graph


toGraph

public int toGraph(java.lang.StringBuffer text,
                   int num)
            throws java.lang.Exception
Outputs one node for graph.

Throws:
java.lang.Exception

toString

public java.lang.String toString()
Outputs the decision tree.


leafString

protected java.lang.String leafString()
                               throws java.lang.Exception
Outputs a leaf.

Throws:
java.lang.Exception

toString

protected java.lang.String toString(int level)
Recursively outputs the tree.


buildTree

protected void buildTree(int[][] sortedIndices,
                         double[][] weights,
                         Instances data,
                         double[] classProbs,
                         Instances header,
                         double minNum,
                         boolean debug,
                         int[] attIndicesWindow)
                  throws java.lang.Exception
Recursively generates a tree.

Throws:
java.lang.Exception

numNodes

public int numNodes()
Computes size of the tree.


splitData

protected void splitData(int[][][] subsetIndices,
                         double[][][] subsetWeights,
                         int att,
                         double splitPoint,
                         int[][] sortedIndices,
                         double[][] weights,
                         double[][] dist,
                         Instances data)
                  throws java.lang.Exception
Splits instances into subsets.

Throws:
java.lang.Exception

distribution

protected double distribution(double[][] props,
                              double[][][] dists,
                              int att,
                              int[] sortedIndices,
                              double[] weights,
                              Instances data)
                       throws java.lang.Exception
Computes class distribution for an attribute.

Throws:
java.lang.Exception

priorVal

protected double priorVal(double[][] dist)
Computes value of splitting criterion before split.


gain

protected double gain(double[][] dist,
                      double priorVal)
Computes value of splitting criterion after split.


main

public static void main(java.lang.String[] argv)
Main method for this class.