marytts.cart
Class DecisionNode

java.lang.Object
  extended by marytts.cart.Node
      extended by marytts.cart.DecisionNode
Direct Known Subclasses:
DecisionNode.BinaryByteDecisionNode, DecisionNode.BinaryFloatDecisionNode, DecisionNode.BinaryShortDecisionNode, DecisionNode.ByteDecisionNode, DecisionNode.ShortDecisionNode

public abstract class DecisionNode
extends Node

A decision node that determines the next Node to go to in the CART. All decision nodes inherit from this class


Nested Class Summary
static class DecisionNode.BinaryByteDecisionNode
          A binary decision Node that compares two byte values.
static class DecisionNode.BinaryFloatDecisionNode
          A binary decision Node that compares two float values.
static class DecisionNode.BinaryShortDecisionNode
          A binary decision Node that compares two short values.
static class DecisionNode.ByteDecisionNode
          An decision Node with an arbitrary number of daughters.
static class DecisionNode.ShortDecisionNode
          An decision Node with an arbitrary number of daughters.
static class DecisionNode.Type
           
 
Field Summary
protected  Node[] daughters
           
protected  java.lang.String feature
           
protected  FeatureDefinition featureDefinition
           
protected  int featureIndex
           
protected  int lastDaughter
           
protected  int nData
           
protected  boolean TRACE
           
protected  int uniqueDecisionNodeId
           
 
Fields inherited from class marytts.cart.Node
isRoot, mother, nodeIndex
 
Constructor Summary
DecisionNode(int numDaughters, FeatureDefinition featureDefinition)
          Construct a new DecisionNode
DecisionNode(int featureIndex, int numDaughters, FeatureDefinition featureDefinition)
          Construct a new DecisionNode
DecisionNode(java.lang.String feature, int numDaughters, FeatureDefinition featureDefinition)
          Construct a new DecisionNode
 
Method Summary
 void addDaughter(Node daughter)
          Add a daughter to the node
 void countData()
          Set the number of candidates correctly, by counting while walking down the tree.
protected  void fillData(java.lang.Object target, int pos, int total)
          Write this node's data into the target object at pos, making sure that exactly len data are written.
 java.lang.Object getAllData()
          Get all unit indices from all leaves below this node
 Node getDaughter(int index)
          Get the daughter at the specified index
abstract  DecisionNode.Type getDecisionNodeType()
          Get the decision node type
abstract  java.lang.String getDecisionPath(int daughterIndex)
          Get the path leading to the daughter with the given index.
 FeatureDefinition getFeatureDefinition()
           
 int getFeatureIndex()
           
 java.lang.String getFeatureName()
          Get the name of the feature
abstract  Node getNextNode(FeatureVector featureVector)
          Select a daughter node according to the value in the given target
abstract  java.lang.String getNodeDefinition()
          Gets the String that defines the decision done in the node
 int getNumberOfData()
          Count all the data available at and below this node.
 int getNumberOfDaugthers()
          Number of daughters of current node.
 int getNumberOfNodes()
          Count all the nodes at and below this node.
 int getUniqueDecisionNodeId()
           
 boolean hasMoreDaughters(int index)
          Tests, if the given index refers to a daughter
 boolean isDecisionNode()
           
 void replaceDaughter(Node newDaughter, int index)
          Replace daughter at given index with another daughter
 void setUniqueDecisionNodeId(int id)
           
 java.lang.String toString()
           
 
Methods inherited from class marytts.cart.Node
getDecisionPath, getMother, getNodeIndex, getRootNode, isDirectedGraphNode, isLeafNode, isRoot, setIsRoot, setMother, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TRACE

protected boolean TRACE

featureDefinition

protected FeatureDefinition featureDefinition

daughters

protected Node[] daughters

featureIndex

protected int featureIndex

feature

protected java.lang.String feature

lastDaughter

protected int lastDaughter

nData

protected int nData

uniqueDecisionNodeId

protected int uniqueDecisionNodeId
Constructor Detail

DecisionNode

public DecisionNode(java.lang.String feature,
                    int numDaughters,
                    FeatureDefinition featureDefinition)
Construct a new DecisionNode

Parameters:
feature - the feature
numDaughters - the number of daughters

DecisionNode

public DecisionNode(int featureIndex,
                    int numDaughters,
                    FeatureDefinition featureDefinition)
Construct a new DecisionNode

Parameters:
featureIndex - the feature index
numDaughters - the number of daughters

DecisionNode

public DecisionNode(int numDaughters,
                    FeatureDefinition featureDefinition)
Construct a new DecisionNode

Parameters:
numDaughters - the number of daughters
Method Detail

isDecisionNode

public boolean isDecisionNode()
Overrides:
isDecisionNode in class Node

getFeatureName

public java.lang.String getFeatureName()
Get the name of the feature

Returns:
the name of the feature

getFeatureIndex

public int getFeatureIndex()

getFeatureDefinition

public FeatureDefinition getFeatureDefinition()

addDaughter

public void addDaughter(Node daughter)
Add a daughter to the node

Parameters:
daughter - the new daughter

getDaughter

public Node getDaughter(int index)
Get the daughter at the specified index

Parameters:
index - the index of the daughter
Returns:
the daughter (potentially null); if index out of range: null

replaceDaughter

public void replaceDaughter(Node newDaughter,
                            int index)
Replace daughter at given index with another daughter

Parameters:
newDaughter - the new daughter
index - the index of the daughter to replace

hasMoreDaughters

public boolean hasMoreDaughters(int index)
Tests, if the given index refers to a daughter

Parameters:
index - the index
Returns:
true, if the index is in range of the daughters array

getAllData

public java.lang.Object getAllData()
Get all unit indices from all leaves below this node

Specified by:
getAllData in class Node
Returns:
an int array containing the indices

fillData

protected void fillData(java.lang.Object target,
                        int pos,
                        int total)
Description copied from class: Node
Write this node's data into the target object at pos, making sure that exactly len data are written. The type of data written depends on the type of nodes; for example, when IntArrayLeafNodes are used, target would be an int[].

Specified by:
fillData in class Node
pos - the position in the target at which to start writing
total - the amount of data items to write, usually equals getNumberOfData().

getNumberOfNodes

public int getNumberOfNodes()
Count all the nodes at and below this node. A leaf will return 1; the root node will report the total number of decision and leaf nodes in the tree.

Specified by:
getNumberOfNodes in class Node
Returns:

getNumberOfData

public int getNumberOfData()
Description copied from class: Node
Count all the data available at and below this node. The meaning of this depends on the type of nodes; for example, when IntArrayLeafNodes are used, it is the total number of ints that are saved in all leaf nodes below the current node.

Specified by:
getNumberOfData in class Node
Returns:
an int counting the data below the current node, or -1 if such a concept is not meaningful.

getNumberOfDaugthers

public int getNumberOfDaugthers()
Number of daughters of current node.


countData

public void countData()
Set the number of candidates correctly, by counting while walking down the tree. This needs to be done once for the entire tree.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getDecisionPath

public abstract java.lang.String getDecisionPath(int daughterIndex)
Get the path leading to the daughter with the given index. This will recursively go up to the root node.

Parameters:
daughterIndex -
Returns:

setUniqueDecisionNodeId

public void setUniqueDecisionNodeId(int id)

getUniqueDecisionNodeId

public int getUniqueDecisionNodeId()

getNodeDefinition

public abstract java.lang.String getNodeDefinition()
Gets the String that defines the decision done in the node

Returns:
the node definition

getDecisionNodeType

public abstract DecisionNode.Type getDecisionNodeType()
Get the decision node type

Returns:

getNextNode

public abstract Node getNextNode(FeatureVector featureVector)
Select a daughter node according to the value in the given target

Parameters:
target - the target
Returns:
a daughter