org.jaitools.numeric
Class Histogram<T extends Number & Comparable>

java.lang.Object
  extended by org.jaitools.numeric.Histogram<T>
Type Parameters:
T - the value type

public class Histogram<T extends Number & Comparable>
extends Object

A simple numeric histogram class that uses the Range class to define bins. New bins can be defined even after data had already been added to allow a histogram to adapt to the input data, however the new bins must not overlap with existing bins.

Since:
1.0
Version:
$Id$
Author:
Michael Bedward

Field Summary
static int NO_BIN
          Constant indicating that a value does not fall in any bin
 
Constructor Summary
Histogram()
          Creates a new histogram.
 
Method Summary
 void addBin(Range<T> range)
          Adds a new bin to the histogram.
 int addValue(T value)
          Adds a value to the histogram.
 void addValues(List<T> values)
          Adds a list of values to the histogram.
 int getBinForValue(T value)
          Gets the bin index for a value.
 List<Integer> getBinForValues(List<T> values)
          Gets bin indices for a list of input values.
 List<Integer> getCounts()
          Gets the count of data items in each bin.
 int size()
          Gets the number of bins.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_BIN

public static final int NO_BIN
Constant indicating that a value does not fall in any bin

See Also:
Constant Field Values
Constructor Detail

Histogram

public Histogram()
Creates a new histogram.

Method Detail

addBin

public void addBin(Range<T> range)
            throws org.jaitools.numeric.HistogramException
Adds a new bin to the histogram.

Parameters:
range - the data range for this bin.
Throws:
HistogramException - if the new bin overlaps with an existing bin

addValue

public int addValue(T value)
Adds a value to the histogram.

Parameters:
value - the value
Returns:
the index of the bin that the value was allocated to or NO_BIN

addValues

public void addValues(List<T> values)
Adds a list of values to the histogram. This will be faster than adding values one at a time if the list is at least partially sorted.

Parameters:
values - input values

getBinForValue

public int getBinForValue(T value)
Gets the bin index for a value. The value is not added to the histogram.

Parameters:
value - the value
Returns:
the bin index or NO_BIN

getBinForValues

public List<Integer> getBinForValues(List<T> values)
Gets bin indices for a list of input values. The values are not added to the histogram.

Parameters:
values - input values
Returns:
a new List of bin indices

size

public int size()
Gets the number of bins.

Returns:
number of bins

getCounts

public List<Integer> getCounts()
Gets the count of data items in each bin.

Returns:
the counts


Copyright © 2009-2013. All Rights Reserved.