Environment for
DeveLoping
KDD-Applications
Supported by Index-Structures

de.lmu.ifi.dbs.elki.math
Class Histogram<T>

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.math.Histogram<T>
Type Parameters:
T - Histogram data type.
All Implemented Interfaces:
Iterable<Pair<Double,T>>

public class Histogram<T>
extends Object
implements Iterable<Pair<Double,T>>

Class to manage a simple Histogram.

Author:
Erich Schubert

Nested Class Summary
static class Histogram.Constructor<T>
          Interface to plug in constructors for type T.
protected  class Histogram.Iter
          Iterator class to iterate over all bins.
 
Field Summary
protected  double base
          Array 'base', i.e. the point of 0.0.
protected  double binsize
          Width of a bin.
protected  ArrayList<T> data
          Data storage
private  Histogram.Constructor<T> maker
          Constructor for new elements
protected  double max
          To avoid introducing an extra bucket for the maximum value.
protected  int offset
          Array shift to account for negative indices.
protected  int size
          Size of array storage.
 
Constructor Summary
Histogram(int bins, double min, double max)
          Histogram constructor without 'Constructor' to generate new elements.
Histogram(int bins, double min, double max, Histogram.Constructor<T> maker)
          Histogram constructor
 
Method Summary
static Histogram<Pair<Double,Double>> DoubleDoubleHistogram(int bins, double min, double max)
          Convenience constructor for Histograms with pairs of Doubles Uses a constructor to initialize bins with Pair(Double(0),Double(0))
static Histogram<Double> DoubleHistogram(int bins, double min, double max)
          Convenience constructor for Double-based Histograms.
 T get(double coord)
          Get the data at a given Coordinate.
private  int getBinNr(double coord)
          Compute the bin number.
 double getBinsize()
          Get the size (width) of a bin.
 double getCoverMaximum()
          Get maximum (covered by bins, not data!)
 double getCoverMinimum()
          Get minimum (covered by bins, not data!)
 ArrayList<T> getData()
          Get the raw data.
 int getNumBins()
          Get the number of bins actually in use.
static Histogram<Integer> IntHistogram(int bins, double min, double max)
          Convenience constructor for Integer-based Histograms.
static Histogram<Pair<Integer,Integer>> IntIntHistogram(int bins, double min, double max)
          Convenience constructor for Histograms with pairs of Integers Uses a constructor to initialize bins with Pair(Integer(0),Integer(0))
 Iterator<Pair<Double,T>> iterator()
          Get an iterator over all histogram bins.
private  T make()
          Call the constructor to produce a new element, if possible.
static Histogram<MeanVariance> MeanVarianceHistogram(int bins, double min, double max)
          Convenience constructor for MeanVariance-based Histograms.
 void put(double coord, T d)
          Put data at a given coordinate.
private  void putBin(int bin, T d)
          Internal put function to handle the special cases of histogram resizing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

offset

protected int offset
Array shift to account for negative indices.


size

protected int size
Size of array storage.


base

protected double base
Array 'base', i.e. the point of 0.0. Usually the minimum.


max

protected double max
To avoid introducing an extra bucket for the maximum value.


binsize

protected double binsize
Width of a bin.


data

protected ArrayList<T> data
Data storage


maker

private Histogram.Constructor<T> maker
Constructor for new elements

Constructor Detail

Histogram

public Histogram(int bins,
                 double min,
                 double max,
                 Histogram.Constructor<T> maker)
Histogram constructor

Parameters:
bins - Number of bins to use.
min - Minimum Value
max - Maximum Value
maker - Constructor for new elements.

Histogram

public Histogram(int bins,
                 double min,
                 double max)
Histogram constructor without 'Constructor' to generate new elements. Empty bins will be initialized with 'null'.

Parameters:
bins - Number of bins
min - Minimum value
max - Maximum value.
Method Detail

make

private T make()
Call the constructor to produce a new element, if possible.

Returns:
new element or null.

get

public T get(double coord)
Get the data at a given Coordinate.

Parameters:
coord - Coordinate.
Returns:
data element there (which may be a new empty bin or null)

put

public void put(double coord,
                T d)
Put data at a given coordinate. Note: this replaces the contents, it doesn't "add" or "count".

Parameters:
coord -
d -

getBinNr

private int getBinNr(double coord)
Compute the bin number. Has a special case for rounding max down to the last bin.

Parameters:
coord - Coordinate
Returns:
bin number

putBin

private void putBin(int bin,
                    T d)
Internal put function to handle the special cases of histogram resizing.

Parameters:
bin - bin number
d - data to put

getData

public ArrayList<T> getData()
Get the raw data. Note that this does NOT include the coordinates.

Returns:
raw data array.

iterator

public Iterator<Pair<Double,T>> iterator()
Get an iterator over all histogram bins.

Specified by:
iterator in interface Iterable<Pair<Double,T>>

IntHistogram

public static final Histogram<Integer> IntHistogram(int bins,
                                                    double min,
                                                    double max)
Convenience constructor for Integer-based Histograms. Uses a constructor to initialize bins with Integer(0)

Parameters:
bins - Number of bins
min - Minimum coordinate
max - Maximum coordinate
Returns:
New histogram for Integers.

DoubleHistogram

public static final Histogram<Double> DoubleHistogram(int bins,
                                                      double min,
                                                      double max)
Convenience constructor for Double-based Histograms. Uses a constructor to initialize bins with Double(0)

Parameters:
bins - Number of bins
min - Minimum coordinate
max - Maximum coordinate
Returns:
New histogram for Doubles.

IntIntHistogram

public static final Histogram<Pair<Integer,Integer>> IntIntHistogram(int bins,
                                                                     double min,
                                                                     double max)
Convenience constructor for Histograms with pairs of Integers Uses a constructor to initialize bins with Pair(Integer(0),Integer(0))

Parameters:
bins - Number of bins
min - Minimum coordinate
max - Maximum coordinate
Returns:
New histogram for Integer pairs.

DoubleDoubleHistogram

public static final Histogram<Pair<Double,Double>> DoubleDoubleHistogram(int bins,
                                                                         double min,
                                                                         double max)
Convenience constructor for Histograms with pairs of Doubles Uses a constructor to initialize bins with Pair(Double(0),Double(0))

Parameters:
bins - Number of bins
min - Minimum coordinate
max - Maximum coordinate
Returns:
New histogram for Double pairs.

MeanVarianceHistogram

public static final Histogram<MeanVariance> MeanVarianceHistogram(int bins,
                                                                  double min,
                                                                  double max)
Convenience constructor for MeanVariance-based Histograms. Uses a constructor to initialize bins with new MeanVariance objects

Parameters:
bins - Number of bins
min - Minimum coordinate
max - Maximum coordinate
Returns:
New histogram for MeanVariance.

getNumBins

public int getNumBins()
Get the number of bins actually in use.

Returns:
number of bins

getBinsize

public double getBinsize()
Get the size (width) of a bin.

Returns:
bin size

getCoverMinimum

public double getCoverMinimum()
Get minimum (covered by bins, not data!)

Returns:
minimum

getCoverMaximum

public double getCoverMaximum()
Get maximum (covered by bins, not data!)

Returns:
maximum

Release 0.2.1 (2009-07-13_1605)