weka.associations.classification
Class CrTree

java.lang.Object
  extended by weka.associations.classification.PruneCAR
      extended by weka.associations.classification.CrTree
All Implemented Interfaces:
java.io.Serializable, OptionHandler
Direct Known Subclasses:
JCBAPruning

public class CrTree
extends PruneCAR
implements java.io.Serializable

Class for building and using a CrTree. A CrTree(n-ary tree in child-sibling representation) can store classification association rules(CARs) and allows pruning and classification. Tree Structure described at: W. Li, J. Han, J.Pei: CMAR: Accurate and Efficient Classification Based on Multiple Class-Association Rules. In ICDM'01:369-376,2001. The child sibling representation for n-ary trees is used

Version:
$Revision: 8108 $
Author:
Stefan Mutter
See Also:
Serialized Form

Constructor Summary
CrTree()
          Constructor constructs an empty CrTree
CrTree(CrNode root, Instances instances, Instances onlyClass)
          Constructor
CrTree(Instances instances, Instances onlyClass)
          Constructor
 
Method Summary
 void deleteContent(CrNode node, int index)
          Deletes one rule out of the CrTree
 void deleteNode(CrNode node)
          deletes a node out of the CrTree if possible
 CrList getAssociateList()
          Gets the associated list
 int getDefaultClass()
          Gets the default class
 java.lang.String[] getOptions()
          Gets the current settings of the CrTree object.
 CrNode getRoot()
          Gets the root node
 void insertContent(CrNode node, FastVector input)
          Adds another consequence to an existing premise.
 void insertNode(FastVector rulePremise, FastVector ruleConsequence)
          insert a new rule into the CrTree in three steps: 1.
 boolean isEmpty()
          Checks if the the CrTree is empty
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options.
 void makeEmpty()
          Deletes the whole CrTree and its associated list by setting the child pointer of the root to null
 java.lang.String pathToString(java.lang.String metricString)
          Prints a rule
 void preprocess(FastVector premises, FastVector consequences, FastVector confidences)
          The preprocessing step before a rule is inserted into a CrTree.
 void prune()
          Method for pruning a CrTree.
 void pruneBeforeInsertion(FastVector premise, FastVector consequence)
          Method that provides a pruning step before a rule is inserted into the CrTree.
 int prunedRules()
          Returns the number of pruned rules
 FastVector pruningCriterions(FastVector input)
          Potentially adds additional measures that can be used as pruning criterias to a rule.
 void removeAtChild(CrNode node, CrNode sibling)
          Deletes a node out of the parent list.
 void removeAtList(CrNode node)
          deletes the node out of the list that connects nodes storing the same item.
 void removeAtSibling(CrNode node)
          Deletes a node out of the child list.
 int[] reportSubtreeCount(CrNode subTreeRoot)
          Gets the class distribution of the rules from a subtree of a specified node
 java.lang.String rulePremise()
          Prints a rule premise (from bottom to top in the tree, respectively infrequent items to frequent ones).
 FastVector search(FastVector data)
          Searches for an existing rule premise are parts of an rule premise in the CrTree
 void setDefaultClass()
          Sets the default class as the amjority class in the instances.
 void setInstancesNoClass(Instances instances)
          Sets the instances (without class attribute)
 void setInstancesOnlyClass(Instances instances)
          Sets the class information
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
 FastVector sortItemSet(ItemSet current)
          Sorts an item set accoring to the frequencies values of the items.
 java.lang.String toString(java.lang.String metricString)
          Returns a string description of the CrTree Object
 void updateHeight(CrNode node)
          Adjust the (minimum) height of a CrListElement
 
Methods inherited from class weka.associations.classification.PruneCAR
forName
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CrTree

public CrTree()
Constructor constructs an empty CrTree


CrTree

public CrTree(CrNode root,
              Instances instances,
              Instances onlyClass)
Constructor

Parameters:
root - the root node
instances - the instances without class attribute
onlyClass - the class attribute and its values for all instances

CrTree

public CrTree(Instances instances,
              Instances onlyClass)
Constructor

Parameters:
instances - the instances without class attribute
onlyClass - the class attribute and its values for all instances
Method Detail

setInstancesNoClass

public final void setInstancesNoClass(Instances instances)
Sets the instances (without class attribute)

Specified by:
setInstancesNoClass in class PruneCAR
Parameters:
instances - instances without classattribute

setInstancesOnlyClass

public final void setInstancesOnlyClass(Instances instances)
Sets the class information

Specified by:
setInstancesOnlyClass in class PruneCAR
Parameters:
instances - the class attribute and its values

preprocess

public void preprocess(FastVector premises,
                       FastVector consequences,
                       FastVector confidences)
                throws java.lang.Exception
The preprocessing step before a rule is inserted into a CrTree. The main purpose is to sort the items according to their frequencies in the datsaset. More frequent items will be found in nodes closer to the root.

Specified by:
preprocess in class PruneCAR
Parameters:
premises - the premises
consequences - the consequences
confidences - the interestingness measures
Throws:
java.lang.Exception - throws exception if preprocessing is not possible

setDefaultClass

public void setDefaultClass()
Sets the default class as the amjority class in the instances. The default class is stored in the head of the associated CrList.


getDefaultClass

public int getDefaultClass()
Gets the default class

Returns:
the default class coded as integer

sortItemSet

public final FastVector sortItemSet(ItemSet current)
Sorts an item set accoring to the frequencies values of the items. For every item the resulting FastVector conatins two integer: attribute number and value

Parameters:
current - the item set
Returns:
a Fastvector with sorted attributes accoring to their frequencies.

pruningCriterions

public FastVector pruningCriterions(FastVector input)
Potentially adds additional measures that can be used as pruning criterias to a rule. This method is provided for the children of CrTree. This class implements no pruning and therefore needs no additional pruning criterias

Specified by:
pruningCriterions in class PruneCAR
Parameters:
input - pruning criteria
Returns:
a FastVector with the added criterias

pruneBeforeInsertion

public void pruneBeforeInsertion(FastVector premise,
                                 FastVector consequence)
Method that provides a pruning step before a rule is inserted into the CrTree. In its general form here, no pruning is done.

Specified by:
pruneBeforeInsertion in class PruneCAR
Parameters:
premise - the rule premise
consequence - the rule consequence

isEmpty

public final boolean isEmpty()
Checks if the the CrTree is empty

Specified by:
isEmpty in class PruneCAR
Returns:
true if it is empty, false otherwise

getRoot

public final CrNode getRoot()
Gets the root node

Returns:
the root node

getAssociateList

public final CrList getAssociateList()
Gets the associated list

Returns:
the associated list

removeAtSibling

public final void removeAtSibling(CrNode node)
Deletes a node out of the child list.

Parameters:
node - the node that has to be deletet out of the child list

removeAtChild

public final void removeAtChild(CrNode node,
                                CrNode sibling)
Deletes a node out of the parent list.

Parameters:
node - the node that has to be deleted
sibling - a sibling node

removeAtList

public final void removeAtList(CrNode node)
deletes the node out of the list that connects nodes storing the same item. If no other node stores the same item, the element in the associated list is deleted as well.

Parameters:
node - the node that has to be deleted

updateHeight

public final void updateHeight(CrNode node)
Adjust the (minimum) height of a CrListElement

Parameters:
node - the node that has to deleted

deleteContent

public final void deleteContent(CrNode node,
                                int index)
Deletes one rule out of the CrTree

Specified by:
deleteContent in class PruneCAR
Parameters:
node - the node where the consequence of the rule is stored
index - the index of the consequence

deleteNode

public final void deleteNode(CrNode node)
deletes a node out of the CrTree if possible

Parameters:
node - the node that should be deleted

insertContent

public void insertContent(CrNode node,
                          FastVector input)
Adds another consequence to an existing premise.

Specified by:
insertContent in class PruneCAR
Parameters:
node - the node where the conesequence should be added
input - the consequence

insertNode

public final void insertNode(FastVector rulePremise,
                             FastVector ruleConsequence)
insert a new rule into the CrTree in three steps: 1. search for existing paths and the right node to start the insertion. 2. insert (rest of) premise 3. insert consequence and additional measures (by calling insertContent)

Parameters:
rulePremise - the rule premise
ruleConsequence - the consequence and additional measures

search

public final FastVector search(FastVector data)
Searches for an existing rule premise are parts of an rule premise in the CrTree

Parameters:
data - the rule premise
Returns:
the part of the rule premise that cannot be found in the CrTree

prune

public void prune()
Method for pruning a CrTree. In thgis general form of a CrTree there is no pruning involved. Children of this class implement this method with their pruning strategy.

Specified by:
prune in class PruneCAR

makeEmpty

public final void makeEmpty()
Deletes the whole CrTree and its associated list by setting the child pointer of the root to null


reportSubtreeCount

public int[] reportSubtreeCount(CrNode subTreeRoot)
Gets the class distribution of the rules from a subtree of a specified node

Parameters:
subTreeRoot - the root of the subtree
Returns:
the class distribution

rulePremise

public java.lang.String rulePremise()
Prints a rule premise (from bottom to top in the tree, respectively infrequent items to frequent ones).

Returns:
a string with a rule premise

toString

public java.lang.String toString(java.lang.String metricString)
Returns a string description of the CrTree Object

Specified by:
toString in class PruneCAR
Parameters:
metricString - the metric used
Returns:
a string describing the CrTree object

pathToString

public java.lang.String pathToString(java.lang.String metricString)
Prints a rule

Parameters:
metricString - the metric used for class association rule mining
Returns:
strting with rules with the same premise

getOptions

public java.lang.String[] getOptions()
Gets the current settings of the CrTree object. There are no options available.

Specified by:
getOptions in interface OptionHandler
Returns:
an array with an empty string.

listOptions

public java.util.Enumeration listOptions()
Returns an enumeration describing the available options. There are no options available

Specified by:
listOptions in interface OptionHandler
Returns:
a FastVector containing an empty string.

setOptions

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

There are no options available.

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

prunedRules

public int prunedRules()
Returns the number of pruned rules

Specified by:
prunedRules in class PruneCAR
Returns:
the number of pruned rules