public class Histogram extends java.lang.Object implements DistributionApproximation
histogramType.
This class provides two different ways to create a histogram. One way involves passing an entire double array
to evaluate(double[]) a second way requires that you first incrementally update the data with
calls to increment(double) or setData(double[]) and then call evaluate(). If you
call the method evaluate() without first calling setData(double[]) or incrementally
updating the data, you will get a null pointer exception.| Modifier and Type | Field and Description |
|---|---|
protected boolean |
interpolatorUpdateNeeded |
| Constructor and Description |
|---|
Histogram(HistogramType histogramType) |
Histogram(HistogramType histogramType,
BinCalculationType binCalculationType,
boolean lowerInclusive)
This constructor is the most general.
|
Histogram(HistogramType histogramType,
int numberOfBins,
double min,
double max,
boolean lowerInclusive)
This constructor is for use with a
SimpleBinCalculation
where the user provides the min, max, and number of points. |
| Modifier and Type | Method and Description |
|---|---|
double[] |
evaluate()
Gets an array of value values.
|
double[] |
evaluate(double[] x) |
Bin |
getBinAt(int index)
Histogram bins are stored in an array list.
|
double |
getBinWidth() |
double |
getDensityAt(int index)
Gets a value value at the specified index.
|
double |
getMaximum() |
double |
getMean() |
double |
getMinimum() |
int |
getNumberOfBins()
Gets the number of histogram bins.
|
int |
getNumberOfPoints()
Gets the number of evaluation points (and corresponding number of value values).
|
double |
getPointAt(int index)
Gets an evaluation points at the specified index.
|
double[] |
getPoints()
Gets an array of evaluation points.
|
double |
getSampleSize() |
double |
getStandardDeviation() |
double |
getSumOfValues() |
double |
getValueAt(int index) |
void |
increment(double value)
Incrementally counts the number of observations in each bin.
|
void |
increment(double value,
double frequency) |
java.util.Iterator<Bin> |
iterator()
Gets the iterator for the array list of bin objects.
|
void |
setData(double[] x) |
void |
setDensityAt(int index,
double value) |
void |
setPointAt(int index,
double value) |
double[] |
standardize(boolean keepPoints)
Uses current quadrature points and weights to compute the mean and standard deviation of the
density, and tehn standardizes the distribution to have a mean of zero and a standard deviation of one.
|
java.lang.String |
toString()
A string representation of the histogram.
|
public Histogram(HistogramType histogramType)
public Histogram(HistogramType histogramType, BinCalculationType binCalculationType, boolean lowerInclusive)
binCalculationType must be a FreedmanDiaconisBinCalculation, ScottBinCalculation, or
SturgesBinCalculation. A SimpleBinCalculation is not permitted.histogramType - indicates the type of y-axis values that will be returned when evaluate()
is called. It has no other effect.lowerInclusive - true if the bins should be lower inclusive. If false, the bins will be upper inclusive.public Histogram(HistogramType histogramType, int numberOfBins, double min, double max, boolean lowerInclusive)
SimpleBinCalculation
where the user provides the min, max, and number of points.histogramType - type of histogramnumberOfBins - number of bins to include in histogrammin - minimum valuemax - maximum valuelowerInclusive - true if lower bound is included in the interval but teh upper bound is not.
If false lower bound not included but upper bound is included.public double getSumOfValues()
public double getValueAt(int index)
public void increment(double value)
value - a value to be counted in a bin.public void increment(double value,
double frequency)
public int getNumberOfBins()
public double getSampleSize()
public Bin getBinAt(int index)
index - position in the array list of the bin.public double[] getPoints()
DistributionApproximation interface.
The evaluation points are the bin midpoints.getPoints in interface DistributionApproximationpublic void setData(double[] x)
public double[] evaluate()
DistributionApproximation interface.evaluate in interface DistributionApproximationpublic double[] evaluate(double[] x)
public double getPointAt(int index)
DistributionApproximation interface. The evaluation points are the bin midpoints.getPointAt in interface DistributionApproximationindex - array index of evaluation point.public double getDensityAt(int index)
DistributionApproximation interface.getDensityAt in interface DistributionApproximationindex - array index of value value.public void setDensityAt(int index,
double value)
setDensityAt in interface DistributionApproximationpublic void setPointAt(int index,
double value)
setPointAt in interface DistributionApproximationpublic double getMinimum()
getMinimum in interface DistributionApproximationpublic double getMaximum()
getMaximum in interface DistributionApproximationpublic double getMean()
getMean in interface DistributionApproximationpublic double getStandardDeviation()
getStandardDeviation in interface DistributionApproximationpublic double getBinWidth()
public int getNumberOfPoints()
DistributionApproximation interface.getNumberOfPoints in interface DistributionApproximationpublic java.util.Iterator<Bin> iterator()
public double[] standardize(boolean keepPoints)
standardize in interface DistributionApproximationkeepPoints - if true original points are retained and weights are computed at these points using
linear interpolation of the empirical cumulative distribution. If false, original weights
are retained and standardization is achieved by linearly transforming the original points.public java.lang.String toString()
toString in class java.lang.Object