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

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

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

Class to manage a simple Histogram. Note: the iterator returns pairs containing the coordinate and the bin value!


Nested Class Summary
static class ReplacingHistogram.Adapter<T>
          Interface to plug in a data type T.
protected  class ReplacingHistogram.Iter
          Iterator class to iterate over all bins.
protected  class ReplacingHistogram.RIter
          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  ReplacingHistogram.Adapter<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
ReplacingHistogram(int bins, double min, double max)
          Histogram constructor without 'Constructor' to generate new elements.
ReplacingHistogram(int bins, double min, double max, ReplacingHistogram.Adapter<T> maker)
          Histogram constructor
 
Method Summary
static ReplacingHistogram<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 ReplacingHistogram<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.
protected  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 ReplacingHistogram<Integer> IntHistogram(int bins, double min, double max)
          Convenience constructor for Integer-based Histograms.
static ReplacingHistogram<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.
protected  T make()
          Make a new bin.
private  void putBin(int bin, T d)
          Internal put function to handle the special cases of histogram resizing.
 void replace(double coord, T d)
          Put data at a given coordinate.
 Iterator<Pair<Double,T>> reverseIterator()
          Get an iterator over all histogram bins.
 
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 ReplacingHistogram.Adapter<T> maker
Constructor for new elements

Constructor Detail

ReplacingHistogram

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

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

ReplacingHistogram

public ReplacingHistogram(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

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)

replace

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

Parameters:
coord - Coordinate
d - New Data

getBinNr

protected 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

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

getData

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

Returns:
raw data array.

make

protected T make()
Make a new bin.

Returns:
new bin.

iterator

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

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

reverseIterator

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


IntHistogram

public static ReplacingHistogram<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 ReplacingHistogram<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 ReplacingHistogram<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 ReplacingHistogram<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.

Release 0.4.0 (2011-09-20_1324)