public class Histogram
extends java.lang.Object
Binnable
objects. The most common usage is to give it an array of Binnable items and a binSize. The
value field of each Binnable item is converted into a bin and the number of occurrences of each bin is then counted and stored. The
toString method returns a string that is easily graphed by Excel. The mean and standard deviation based on the bins can be computed, but
the true mean and standard deviations from the original values are also stored at the beginning. Values can also be added later.
Note that Binnable is an interface that requires the getValue() method. This method is what is used to determine the bin that each Binnable item belongs in.
Modifier and Type | Field and Description |
---|---|
int[] |
bins |
private int |
binWidth |
private int |
maxVal |
private int |
minVal |
private double |
trueMean |
private double |
trueSD |
Constructor and Description |
---|
Histogram(Binnable[] items,
int binSize)
The most often used constructor.
|
Histogram(Binnable[] items,
int binSize,
int minVal)
Specifying the minValue allows you to normalize different Histograms around the same min value.
|
Histogram(int minVal,
int maxVal,
int binSize)
Sets up the variables such that single values can be added to the Histogram.
|
Modifier and Type | Method and Description |
---|---|
void |
add(double value)
Adds a new occurrence in the bin that the given value bins to.
|
private void |
binItems(double[] values)
Converts the values in each item into bin number.
|
static java.lang.String |
boundedAverage(Binnable[] values)
Returns the mean and standard error of values.
|
void |
clear()
Clears the values of this histogram.
|
static double |
computeMean(Binnable[] values)
Computes the mean of the given set.
|
static double |
computeMean(double[] values)
Computes the mean of the given set.
|
static double |
computeSD(Binnable[] values)
Computes the standard deviation of the given set.
|
static double |
computeSD(double[] values)
Computes the standard deviation of the given set.
|
private void |
countBins(double[] values)
Initializes the state variables bins and minVal.
|
int |
getBin(double value)
Returns the bin that this value would be binned to.
|
int |
getCount()
Returns the total number of items in the histogram.
|
int |
getCount(double value)
Returns the number of items in the bin that this would be in.
|
int[] |
getHistogram()
Returns the array of bins.
|
double |
getMean()
Computes the mean of the histogram.
|
double |
getSD()
Computes the sample standard deviation.
|
int |
getValue(int bin)
Converts a bin into the lowest value that would be placed in that bin.
|
java.lang.String |
toString() |
public int[] bins
private final int binWidth
private final int minVal
private final int maxVal
private double trueMean
private double trueSD
public Histogram(Binnable[] items, int binSize)
public Histogram(Binnable[] items, int binSize, int minVal)
public Histogram(int minVal, int maxVal, int binSize)
public static java.lang.String boundedAverage(Binnable[] values)
public static double computeMean(Binnable[] values)
public static double computeMean(double[] values)
public static double computeSD(Binnable[] values)
public static double computeSD(double[] values)
public void add(double value)
private void binItems(double[] values)
public void clear()
private void countBins(double[] values)
public int getBin(double value)
public int getCount()
public int getCount(double value)
public int[] getHistogram()
public double getMean()
public double getSD()
public int getValue(int bin)
public java.lang.String toString()
toString
in class java.lang.Object