public class EmpiricalDistributionImpl extends java.lang.Object implements java.io.Serializable, EmpiricalDistribution
EmpiricalDistribution interface. This implementation
uses what amounts to the
Variable Kernel Method with Gaussian smoothing:Digesting the input file
binCount "bins."USAGE NOTES:
binCount is set by default to 1000. A good rule of thumb
is to set the bin count to approximately the length of the input file divided
by 10. | Modifier and Type | Class and Description |
|---|---|
private class |
EmpiricalDistributionImpl.ArrayDataAdapter
DataAdapter for data provided as array of doubles. |
private class |
EmpiricalDistributionImpl.DataAdapter
Provides methods for computing
sampleStats and
beanStats abstracting the source of data. |
private class |
EmpiricalDistributionImpl.DataAdapterFactory
Factory of
DataAdapter objects. |
private class |
EmpiricalDistributionImpl.StreamDataAdapter
DataAdapter for data provided through some input stream |
| Modifier and Type | Field and Description |
|---|---|
private int |
binCount
number of bins
|
private java.util.List<SummaryStatistics> |
binStats
List of SummaryStatistics objects characterizing the bins
|
private double |
delta
Grid size
|
private boolean |
loaded
is the distribution loaded?
|
private double |
max
Max loaded value
|
private double |
min
Min loaded value
|
private RandomData |
randomData
RandomData instance to use in repeated calls to getNext()
|
private SummaryStatistics |
sampleStats
Sample statistics
|
private static long |
serialVersionUID
Serializable version identifier
|
private double[] |
upperBounds
upper bounds of subintervals in (0,1) "belonging" to the bins
|
| Constructor and Description |
|---|
EmpiricalDistributionImpl()
Creates a new EmpiricalDistribution with the default bin count.
|
EmpiricalDistributionImpl(int binCount)
Creates a new EmpiricalDistribution with the specified bin count.
|
| Modifier and Type | Method and Description |
|---|---|
private void |
fillBinStats(java.lang.Object in)
Fills binStats array (second pass through data file).
|
private int |
findBin(double value)
Returns the index of the bin to which the given value belongs
|
int |
getBinCount()
Returns the number of bins.
|
java.util.List<SummaryStatistics> |
getBinStats()
Returns a List of
SummaryStatistics instances containing
statistics describing the values in each of the bins. |
double[] |
getGeneratorUpperBounds()
Returns a fresh copy of the array of upper bounds of the subintervals
of [0,1] used in generating data from the empirical distribution.
|
double |
getNextValue()
Generates a random value from this distribution.
|
StatisticalSummary |
getSampleStats()
Returns a
StatisticalSummary describing this distribution. |
double[] |
getUpperBounds()
Returns a fresh copy of the array of upper bounds for the bins.
|
boolean |
isLoaded()
Property indicating whether or not the distribution has been loaded.
|
void |
load(double[] in)
Computes the empirical distribution from the provided
array of numbers.
|
void |
load(java.io.File file)
Computes the empirical distribution from the input file.
|
void |
load(java.net.URL url)
Computes the empirical distribution using data read from a URL.
|
private static final long serialVersionUID
private final java.util.List<SummaryStatistics> binStats
private SummaryStatistics sampleStats
private double max
private double min
private double delta
private final int binCount
private boolean loaded
private double[] upperBounds
private final RandomData randomData
public EmpiricalDistributionImpl()
public EmpiricalDistributionImpl(int binCount)
binCount - number of binspublic void load(double[] in)
load in interface EmpiricalDistributionin - the input data arraypublic void load(java.net.URL url)
throws java.io.IOException
load in interface EmpiricalDistributionurl - url of the input filejava.io.IOException - if an IO error occurspublic void load(java.io.File file)
throws java.io.IOException
load in interface EmpiricalDistributionfile - the input filejava.io.IOException - if an IO error occursprivate void fillBinStats(java.lang.Object in)
throws java.io.IOException
in - object providing access to the datajava.io.IOException - if an IO error occursprivate int findBin(double value)
value - the value whose bin we are trying to findpublic double getNextValue()
throws java.lang.IllegalStateException
getNextValue in interface EmpiricalDistributionjava.lang.IllegalStateException - if the distribution has not been loadedpublic StatisticalSummary getSampleStats()
StatisticalSummary describing this distribution.
Preconditions:getSampleStats in interface EmpiricalDistributionjava.lang.IllegalStateException - if the distribution has not been loadedpublic int getBinCount()
getBinCount in interface EmpiricalDistributionpublic java.util.List<SummaryStatistics> getBinStats()
SummaryStatistics instances containing
statistics describing the values in each of the bins. The list is
indexed on the bin number.getBinStats in interface EmpiricalDistributionpublic double[] getUpperBounds()
Returns a fresh copy of the array of upper bounds for the bins.
Bins are:
[min,upperBounds[0]],(upperBounds[0],upperBounds[1]],...,
(upperBounds[binCount-2], upperBounds[binCount-1] = max].
Note: In versions 1.0-2.0 of commons-math, this method
incorrectly returned the array of probability generator upper
bounds now returned by getGeneratorUpperBounds().
getUpperBounds in interface EmpiricalDistributionpublic double[] getGeneratorUpperBounds()
Returns a fresh copy of the array of upper bounds of the subintervals of [0,1] used in generating data from the empirical distribution. Subintervals correspond to bins with lengths proportional to bin counts.
In versions 1.0-2.0 of commons-math, this array was (incorrectly) returned
by getUpperBounds().
public boolean isLoaded()
isLoaded in interface EmpiricalDistributionCopyright (c) 2003-2013 Apache Software Foundation