weka.clusterers
Class Cobweb.CNode

java.lang.Object
  extended byweka.clusterers.Cobweb.CNode
All Implemented Interfaces:
java.io.Serializable
Enclosing class:
Cobweb

private class Cobweb.CNode
extends java.lang.Object
implements java.io.Serializable

Inner class handling node operations for Cobweb.

See Also:
Serializable

Field Summary
private  AttributeStats[] m_attStats
          Within cluster attribute statistics
private  FastVector m_children
          Children of this node
protected  Instances m_clusterInstances
          Instances at this node
private  int m_clusterNum
          Cluster number of this node
private  int m_numAttributes
          Number of attributes
private  double m_totalInstances
          Total instances at this node
 
Constructor Summary
Cobweb.CNode(int numAttributes)
          Creates an empty CNode instance.
Cobweb.CNode(int numAttributes, Instance leafInstance)
          Creates a new leaf CNode instance.
 
Method Summary
protected  void addChildNode(Cobweb.CNode child)
          Adds the supplied node as a child of this node.
protected  void addInstance(Instance newInstance)
          Adds an instance to this cluster.
private  void assignClusterNums(int[] cl_num)
          Recursively assigns numbers to the nodes in the tree.
protected  double categoryUtility()
          Computes the utility of all children with respect to this node
protected  double categoryUtilityChild(Cobweb.CNode child)
          Computes the utility of a single child with respect to this node
private  double cuScoreForBestTwoMerged(Cobweb.CNode merged, Cobweb.CNode a, Cobweb.CNode b, Instance newInstance)
           
private  double[] cuScoresForChildren(Instance newInstance)
          Temporarily adds a new instance to each of this nodes children in turn and computes the category utility.
protected  java.lang.String dumpData()
          Returns the instances at this node as a string.
protected  void dumpTree(int depth, java.lang.StringBuffer text)
          Recursively build a string representation of the Cobweb tree
private  Cobweb.CNode findHost(Instance newInstance, boolean structureFrozen)
          Finds a host for the new instance in this nodes children.
protected  double getProbability(int attIndex, int valueIndex)
          Returns the probability of a value of a nominal attribute in this node
protected  double getStandardDev(int attIndex)
          Returns the standard deviation of a numeric attribute
protected  void graphTree(java.lang.StringBuffer text)
          Recursively generate the graph string for the Cobweb tree.
protected  void updateStats(Instance updateInstance, boolean delete)
          Update attribute stats using the supplied instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_attStats

private AttributeStats[] m_attStats
Within cluster attribute statistics


m_numAttributes

private int m_numAttributes
Number of attributes


m_clusterInstances

protected Instances m_clusterInstances
Instances at this node


m_children

private FastVector m_children
Children of this node


m_totalInstances

private double m_totalInstances
Total instances at this node


m_clusterNum

private int m_clusterNum
Cluster number of this node

Constructor Detail

Cobweb.CNode

public Cobweb.CNode(int numAttributes)
Creates an empty CNode instance.

Parameters:
numAttributes - the number of attributes in the data

Cobweb.CNode

public Cobweb.CNode(int numAttributes,
                    Instance leafInstance)
Creates a new leaf CNode instance.

Parameters:
numAttributes - the number of attributes in the data
leafInstance - the instance to store at this leaf
Method Detail

addInstance

protected void addInstance(Instance newInstance)
                    throws java.lang.Exception
Adds an instance to this cluster.

Parameters:
newInstance - the instance to add
Throws:
java.lang.Exception - if an error occurs

cuScoresForChildren

private double[] cuScoresForChildren(Instance newInstance)
                              throws java.lang.Exception
Temporarily adds a new instance to each of this nodes children in turn and computes the category utility.

Parameters:
newInstance - the new instance to evaluate
Returns:
an array of category utility values---the result of considering each child in turn as a host for the new instance
Throws:
java.lang.Exception - if an error occurs

cuScoreForBestTwoMerged

private double cuScoreForBestTwoMerged(Cobweb.CNode merged,
                                       Cobweb.CNode a,
                                       Cobweb.CNode b,
                                       Instance newInstance)
                                throws java.lang.Exception
Throws:
java.lang.Exception

findHost

private Cobweb.CNode findHost(Instance newInstance,
                              boolean structureFrozen)
                       throws java.lang.Exception
Finds a host for the new instance in this nodes children. Also considers merging the two best hosts and splitting the best host.

Parameters:
newInstance - the instance to find a host for
structureFrozen - true if the instance is not to be added to the tree and instead the best potential host is to be returned
Returns:
the best host
Throws:
java.lang.Exception - if an error occurs

addChildNode

protected void addChildNode(Cobweb.CNode child)
Adds the supplied node as a child of this node. All of the child's instances are added to this nodes instances

Parameters:
child - the child to add

categoryUtility

protected double categoryUtility()
                          throws java.lang.Exception
Computes the utility of all children with respect to this node

Returns:
the category utility of the children with respect to this node.
Throws:
java.lang.Exception

categoryUtilityChild

protected double categoryUtilityChild(Cobweb.CNode child)
                               throws java.lang.Exception
Computes the utility of a single child with respect to this node

Parameters:
child - the child for which to compute the utility
Returns:
the utility of the child with respect to this node
Throws:
java.lang.Exception - if something goes wrong

getProbability

protected double getProbability(int attIndex,
                                int valueIndex)
                         throws java.lang.Exception
Returns the probability of a value of a nominal attribute in this node

Parameters:
attIndex - the index of the attribute
valueIndex - the index of the value of the attribute
Returns:
the probability
Throws:
java.lang.Exception - if the requested attribute is not nominal

getStandardDev

protected double getStandardDev(int attIndex)
                         throws java.lang.Exception
Returns the standard deviation of a numeric attribute

Parameters:
attIndex - the index of the attribute
Returns:
the standard deviation
Throws:
java.lang.Exception - if an error occurs

updateStats

protected void updateStats(Instance updateInstance,
                           boolean delete)
Update attribute stats using the supplied instance.

Parameters:
updateInstance - the instance for updating
delete - true if the values of the supplied instance are to be removed from the statistics

assignClusterNums

private void assignClusterNums(int[] cl_num)
                        throws java.lang.Exception
Recursively assigns numbers to the nodes in the tree.

Parameters:
cl_num - an int[] value
Throws:
java.lang.Exception - if an error occurs

dumpTree

protected void dumpTree(int depth,
                        java.lang.StringBuffer text)
Recursively build a string representation of the Cobweb tree

Parameters:
depth - depth of this node in the tree
text - holds the string representation

dumpData

protected java.lang.String dumpData()
                             throws java.lang.Exception
Returns the instances at this node as a string. Appends the cluster number of the child that each instance belongs to.

Returns:
a String value
Throws:
java.lang.Exception - if an error occurs

graphTree

protected void graphTree(java.lang.StringBuffer text)
                  throws java.lang.Exception
Recursively generate the graph string for the Cobweb tree.

Parameters:
text - holds the graph string
Throws:
java.lang.Exception