com.flaptor.hist4j
Class HistogramDataNode

java.lang.Object
  extended by com.flaptor.hist4j.HistogramNode
      extended by com.flaptor.hist4j.HistogramDataNode
All Implemented Interfaces:
java.io.Serializable

public class HistogramDataNode
extends HistogramNode

The HistogramDataNode stores the histogram data for a range of values. It knows the minimum and maximum values for which it counts the number of instances. When the count exceeds the allowed limit it splits itself in two, increasing the histogram resolution for this range.

Author:
Jorge Handl
See Also:
Serialized Form

Constructor Summary
HistogramDataNode()
          Creates an empty data node.
HistogramDataNode(long count, float minValue, float maxValue)
          Creates a data node for the given range with the given instance count.
 
Method Summary
 HistogramNode addValue(AdaptiveHistogram root, float value)
          Adds a value to the data node.
 void apply(AdaptiveHistogram.ValueConversion valueConversion)
          Applies a convertion function to the values stored in the histogram.
 long getAccumCount(float value)
          Returns the cumulative density function for a given data point.
 long getCount(float value)
          Returns the number of data points stored in the same bucket as a given value.
 java.lang.Float getValueForAccumCount(long[] accumCount)
          Returns the data point where the running cumulative count reaches the target cumulative count.
 void reset()
          Clears the data node.
 void show(int level)
          Prints this nodes' data with a margin depending on the level of the node in the tree.
 void toTable(java.util.ArrayList<Cell> table)
          Build the table representing the histogram data adding this node's cell to it.
 
Methods inherited from class com.flaptor.hist4j.HistogramNode
margin
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HistogramDataNode

public HistogramDataNode()
Creates an empty data node.


HistogramDataNode

public HistogramDataNode(long count,
                         float minValue,
                         float maxValue)
Creates a data node for the given range with the given instance count.

Parameters:
count - the number of data instances in the given range.
minValue - the start of the range of counted values.
maxValue - the end of the range of counted values.
Method Detail

reset

public void reset()
Clears the data node.

Specified by:
reset in class HistogramNode

addValue

public HistogramNode addValue(AdaptiveHistogram root,
                              float value)
Adds a value to the data node.

If the value falls inside of the nodes' range and the count does not exceed the imposed limit, it simply increments the count.
If the value falls outside of the nodes' range, it expands the range.
If the count exceeds the limit, it splits in two assuming uniform distribution inside the node.
If the value falls outside of the nodes' range AND the count exceeds the limit, it creates a new node for that value.

Specified by:
addValue in class HistogramNode
Parameters:
root - a reference to the adaptive histogram instance that uses this structure.
value - the value for which the count is to be incremented.
Returns:
A reference to itself if no structural change happened, or a reference to the new fork node if this node was split.

getCount

public long getCount(float value)
Returns the number of data points stored in the same bucket as a given value.

Specified by:
getCount in class HistogramNode
Parameters:
value - the reference data point.
Returns:
the number of data points stored in the same bucket as the reference point.

getAccumCount

public long getAccumCount(float value)
Returns the cumulative density function for a given data point.

Specified by:
getAccumCount in class HistogramNode
Parameters:
value - the reference data point.
Returns:
the cumulative density function for the reference point.

getValueForAccumCount

public java.lang.Float getValueForAccumCount(long[] accumCount)
Returns the data point where the running cumulative count reaches the target cumulative count. It uses linear interpolation over the range of the node to get a better estimate of the true value.

Specified by:
getValueForAccumCount in class HistogramNode
Parameters:
accumCount - an array containing:
- accumCount[0] the running cumulative count.
- accumCount[1] the target cumulative count.
Returns:
the data point where the running cumulative count reaches the target cumulative count.

apply

public void apply(AdaptiveHistogram.ValueConversion valueConversion)
Applies a convertion function to the values stored in the histogram.

Specified by:
apply in class HistogramNode
Parameters:
valueConversion - a class that defines a function to convert the value.

show

public void show(int level)
Prints this nodes' data with a margin depending on the level of the node in the tree.

Specified by:
show in class HistogramNode
Parameters:
level - the level of this node in the tree.

toTable

public void toTable(java.util.ArrayList<Cell> table)
Build the table representing the histogram data adding this node's cell to it.

Specified by:
toTable in class HistogramNode