edu.mines.jtk.dsp
Class Histogram

java.lang.Object
  extended by edu.mines.jtk.dsp.Histogram

public class Histogram
extends java.lang.Object

A histogram summarizes the distribution of values v in an array. The range (vmax-vmin) of values v in the array is partitioned uniformly into some number of bins. Each bin then contains the number of values that lie closest to the center of that bin.

If the values v in the array are assumed to be instances of some random variable, then a probability density function may be estimated for that variable by simply dividing the count in each bin by the total number of values in the array. The resulting fractions are called the densities.

The number of bins may be specified or computed automatically. In the automatic case, we compute bin width = 2.0*(v75-v25)/pow(n,1.0/3.0), where n denotes the number of values, and v25 and v75 are the 25th and 75th percentiles, respectively. The number of bins is then computed by dividing the range (vmax-vmin) of values by that bin width, rounding down to the nearest integer. In this way, the number of bins grows as the cube root of the number of values n.

Minimum and maximum values (vmin and vmax) may also be specified or computed automatically. If specified, then only values in the range [vmin,vmax] are binned, and values outside this range are ignored.

Reference: Izenman, A. J., 1991, Recent developments in nonparametric density estimation: Journal of the American Statistical Association, v. 86, p. 205-224.

Version:
2005.10.18
Author:
Dave Hale, Colorado School of Mines

Constructor Summary
Histogram(float[] v)
          Constructs a histogram for the specified array of values.
Histogram(float[] v, float vmin, float vmax)
          Constructs a histogram for the specified array of values.
Histogram(float[] v, float vmin, float vmax, int nbin)
          Constructs a histogram for the specified array of values.
Histogram(float[] v, int nbin)
          Constructs a histogram for the specified array of values.
 
Method Summary
 int getBinCount()
          Gets the number of bins in this histogram.
 double getBinDelta()
          Gets the bin width (delta) for this histogram.
 double getBinFirst()
          Gets the value of the center of the first bin for this histogram.
 Sampling getBinSampling()
          Gets the bin sampling for this histogram.
 long[] getCounts()
          Gets the array of counts, one count for each bin.
 float[] getDensities()
          Gets the array of densities, one density for each bin.
 long getHighCount()
          Gets the number of values greater than vmax.
 long getInCount()
          Gets the number of values in the range [vmin,vmax].
 long getLowCount()
          Gets the number of values less than vmin.
 float getMaxValue()
          Gets the maximum value (vmax) for this histogram.
 float getMinValue()
          Gets the minimum value (vmin) for this histogram.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Histogram

public Histogram(float[] v)
Constructs a histogram for the specified array of values. Computes the number of bins to obtain a robust estimate of the density function. Counts and bins all values.

Parameters:
v - the array of values.

Histogram

public Histogram(float[] v,
                 int nbin)
Constructs a histogram for the specified array of values. Counts and bins all values.

Parameters:
v - the array of values.
nbin - the number of bins.

Histogram

public Histogram(float[] v,
                 float vmin,
                 float vmax)
Constructs a histogram for the specified array of values. Computes the number of bins to obtain a robust estimate of the density function. Counts and bins only those values in [vmin,vmax].

Parameters:
v - the array of values.
vmin - the minimum value.
vmax - the maximum value.

Histogram

public Histogram(float[] v,
                 float vmin,
                 float vmax,
                 int nbin)
Constructs a histogram for the specified array of values. Counts and bins only those values in [vmin,vmax].

Parameters:
v - the array of values.
vmin - the minimum value.
vmax - the maximum value.
nbin - the number of bins.
Method Detail

getMinValue

public float getMinValue()
Gets the minimum value (vmin) for this histogram.

Returns:
the minimum value.

getMaxValue

public float getMaxValue()
Gets the maximum value (vmax) for this histogram.

Returns:
the maximum value.

getBinCount

public int getBinCount()
Gets the number of bins in this histogram.

Returns:
the number of bins.

getBinDelta

public double getBinDelta()
Gets the bin width (delta) for this histogram.

Returns:
the bin width.

getBinFirst

public double getBinFirst()
Gets the value of the center of the first bin for this histogram.

Returns:
the value of the center of the first bin.

getBinSampling

public Sampling getBinSampling()
Gets the bin sampling for this histogram. Values sampled are the centers of the bins.

Returns:
the bin sampling.

getCounts

public long[] getCounts()
Gets the array of counts, one count for each bin.

Returns:
array[nbin] of counts, where nbin is the number of bins.

getDensities

public float[] getDensities()
Gets the array of densities, one density for each bin. A density for one bin equals the fraction of values in that bin.

Returns:
array[nbin] of densities, where nbin is the number of bins.

getInCount

public long getInCount()
Gets the number of values in the range [vmin,vmax].

Returns:
the number of values.

getLowCount

public long getLowCount()
Gets the number of values less than vmin.

Returns:
the number of values.

getHighCount

public long getHighCount()
Gets the number of values greater than vmax.

Returns:
the number of values.