netkit.util
Class Histogram

java.lang.Object
  extended by netkit.util.Histogram
Direct Known Subclasses:
HistogramCategorical, HistogramDiscrete

public abstract class Histogram
extends java.lang.Object

This abstract class represents a histogram on Node field values. The histogram keeps track of unique values and a running of how many times each value appeared.

Author:
Kaveh R. Ghazi
See Also:
Attribute, Node

Field Summary
protected  java.util.Map<java.lang.Integer,java.lang.Double> cMap
           
 
Constructor Summary
protected Histogram(double[] values, Attribute attribute, int minOccurance)
          This constructor creates a histogram object given an array of values and an attribute type.
protected Histogram(Edge[] edges, Attribute attribute, int minOccurance)
          This constructor creates a histogram object given an array of edges and an attribute from which to get the values.
protected Histogram(Node[] nodes, Attribute attribute, int minOccurance)
          This constructor creates a histogram object given an array of nodes and an attribute from which to get the values.
 
Method Summary
 double getCount(int value)
          Gets the number of times a particular value appears in this histogram.
 double[] getDistribution()
          Gets the distribution of values of this histogram, in no particular order.
 int getMode()
          Gets the "mode" for this set of values.
 java.util.Set<java.util.Map.Entry<java.lang.Integer,java.lang.Double>> getSet()
          Gets the set of value->count pairs in this histogram.
 double getTotalCount()
          Gets the cumulative number of times all values appear in this histogram.
static void main(java.lang.String[] args)
          This is a main driver to test the Histogram hierarchy classes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cMap

protected final java.util.Map<java.lang.Integer,java.lang.Double> cMap
Constructor Detail

Histogram

protected Histogram(double[] values,
                    Attribute attribute,
                    int minOccurance)
This constructor creates a histogram object given an array of values and an attribute type. It also checks that values appear at least minOccurance times before including them.

Parameters:
values - the array of double values for this object.
attribute - the attribute describing the field type.
minOccurance - the minimum number of times a value must occur before being kept in this histogram.
Throws:
java.lang.RuntimeException - if minOccurance is less than 1.

Histogram

protected Histogram(Node[] nodes,
                    Attribute attribute,
                    int minOccurance)
This constructor creates a histogram object given an array of nodes and an attribute from which to get the values. It also checks that values appear at least minOccurance times before including them.

Parameters:
nodes - the array of Nodes from which to get values.
attribute - the attribute describing the field in the Node to get values from.
minOccurance - the minimum number of times a value must occur before being kept in this histogram.
Throws:
java.lang.RuntimeException - if minOccurance is less than 1.

Histogram

protected Histogram(Edge[] edges,
                    Attribute attribute,
                    int minOccurance)
This constructor creates a histogram object given an array of edges and an attribute from which to get the values. Each edge counts the destination-node's attribute edge-weight times. It also checks that values appear at least minOccurance times before including them.

Parameters:
edges - the array of Edges from which to get weight + attribute values.
attribute - the attribute describing the field in the Node to get values from.
minOccurance - the minimum number of times a value must occur before being kept in this histogram.
Throws:
java.lang.RuntimeException - if minOccurance is less than 1.
Method Detail

getMode

public int getMode()
Gets the "mode" for this set of values. The mode is the most frequent value, i.e. the entry with the highest count in cMap. If multiple entries tie for highest count, the one returned is unspecified.

Returns:
the mode for this set of values.

getCount

public double getCount(int value)
Gets the number of times a particular value appears in this histogram.

Parameters:
value - the value to lookup in the histogram.
Returns:
the number of times a particular value appears in this histogram.

getTotalCount

public double getTotalCount()
Gets the cumulative number of times all values appear in this histogram.

Returns:
the cumulative number of times all values appear in this histogram.

getDistribution

public double[] getDistribution()
Gets the distribution of values of this histogram, in no particular order.

Returns:
the distribution of values of this histogram.

getSet

public java.util.Set<java.util.Map.Entry<java.lang.Integer,java.lang.Double>> getSet()
Gets the set of value->count pairs in this histogram.

Returns:
the set of value->count pairs in this histogram. The returned set is not modifiable.

main

public static final void main(java.lang.String[] args)
This is a main driver to test the Histogram hierarchy classes.