Top Description Inners Fields Constructors Methods
org.apache.commons.math3.random

public Class EmpiricalDistribution

extends AbstractRealDistribution
Class Inheritance
Imports
java.io.BufferedReader, .File, .FileInputStream, .IOException, .InputStream, .InputStreamReader, java.net.URL, java.nio.charset.Charset, java.util.ArrayList, .List, org.apache.commons.math3.distribution.AbstractRealDistribution, .ConstantRealDistribution, .NormalDistribution, .RealDistribution, org.apache.commons.math3.exception.MathIllegalStateException, .MathInternalError, .NullArgumentException, .OutOfRangeException, .ZeroException, .NotStrictlyPositiveException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.stat.descriptive.StatisticalSummary, .SummaryStatistics, org.apache.commons.math3.util.FastMath, .MathUtils

Represents an empirical probability distribution -- a probability distribution derived from observed data without making any assumptions about the functional form of the population distribution that the data come from.

An EmpiricalDistribution maintains data structures, called distribution digests, that describe empirical distributions and support the following operations:

Applications can use EmpiricalDistribution to build grouped frequency histograms representing the input data or to generate random values "like" those in the input file -- i.e., the values generated will follow the distribution of the values in the file.

The implementation uses what amounts to the Variable Kernel Method with Gaussian smoothing:

Digesting the input file

  1. Pass the file once to compute min and max.
  2. Divide the range from min-max into binCount "bins."
  3. Pass the data file again, computing bin counts and univariate statistics (mean, std dev.) for each of the bins
  4. Divide the interval (0,1) into subintervals associated with the bins, with the length of a bin's subinterval proportional to its count.
Generating random values from the distribution
  1. Generate a uniformly distributed value in (0,1)
  2. Select the subinterval to which the value belongs.
  3. Generate a random Gaussian value with mean = mean of the associated bin and std dev = std dev of associated bin.

EmpiricalDistribution implements the RealDistribution interface as follows. Given x within the range of values in the dataset, let B be the bin containing x and let K be the within-bin kernel for B. Let P(B-) be the sum of the probabilities of the bins below B and let K(B) be the mass of B under K (i.e., the integral of the kernel density over B). Then set P(X < x) = P(B-) + P(B) * K(x) / K(B) where K(x) is the kernel distribution evaluated at x. This results in a cdf that matches the grouped frequency distribution at the bin endpoints and interpolates within bins using within-bin kernels.

USAGE NOTES:

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
EmpiricalDistribution.ArrayDataAdapter

DataAdapter for data provided as array of doubles.

private abstract class
EmpiricalDistribution.DataAdapter

Provides methods for computing sampleStats and beanStats abstracting the source of data.

private class
EmpiricalDistribution.StreamDataAdapter

DataAdapter for data provided through some input stream

Field Summary

Modifier and TypeField and Description
private final int
binCount

number of bins

private final List<SummaryStatistics>
binStats

List of SummaryStatistics objects characterizing the bins

public static final int
DEFAULT_BIN_COUNT

Default bin count

private double
delta

Grid size

private static final String
FILE_CHARSET

Character set for file input

private boolean
loaded

is the distribution loaded?

private double
max

Max loaded value

private double
min

Min loaded value

protected final RandomDataGenerator
randomData

Hides org.apache.commons.math3.distribution.AbstractRealDistribution.randomData.

Deprecated as a consequence of RandomDataGenerator being deprecated.
RandomDataGenerator instance to use in repeated calls to getNext()
private SummaryStatistics
sampleStats

Sample statistics

private static final long
private double[]
upperBounds

upper bounds of subintervals in (0,1) "belonging" to the bins

Inherited from org.apache.commons.math3.distribution.AbstractRealDistribution:
randomSOLVER_DEFAULT_ABSOLUTE_ACCURACY

Constructor Summary

AccessConstructor and Description
public
EmpiricalDistribution()

Creates a new EmpiricalDistribution with the default bin count.

public
EmpiricalDistribution(int
number of bins. Must be strictly positive.
binCount
)

Creates a new EmpiricalDistribution with the specified bin count.

public
EmpiricalDistribution(int
number of bins. Must be strictly positive.
binCount
,
RandomGenerator
random data generator (may be null, resulting in default JDK generator)
generator
)

Creates a new EmpiricalDistribution with the specified bin count using the provided RandomGenerator as the source of random data.

public
EmpiricalDistribution(RandomGenerator
random data generator (may be null, resulting in default JDK generator)
generator
)

Creates a new EmpiricalDistribution with default bin count using the provided RandomGenerator as the source of random data.

public
EmpiricalDistribution(int
number of bins
binCount
,
RandomDataImpl
random data generator (may be null, resulting in default JDK generator)
randomData
)
Deprecated As of 3.1.

Creates a new EmpiricalDistribution with the specified bin count using the provided RandomDataImpl instance as the source of random data.

public
EmpiricalDistribution(RandomDataImpl
random data generator (may be null, resulting in default JDK generator)
randomData
)
Deprecated As of 3.1.

Creates a new EmpiricalDistribution with default bin count using the provided RandomDataImpl as the source of random data.

private
EmpiricalDistribution(int
number of bins. Must be strictly positive.
binCount
,
RandomDataGenerator
Random data generator.
randomData
)
Deprecated as a consequence of RandomDataGenerator being deprecated.

Private constructor to allow lazy initialisation of the RNG contained in the randomData instance variable.

Method Summary

Modifier and TypeMethod and Description
private double

Returns:

sum of the probabilities of bins through binIndex
cumBinP
(int
maximum bin index
binIndex
)

The combined probability of the bins up to and including binIndex.

public double
cumulativeProbability(double
the point at which the CDF is evaluated
x
)

Implements org.apache.commons.math3.distribution.RealDistribution.cumulativeProbability.

For a random variable X whose values are distributed according to this distribution, this method returns P(X <= x).

public double
density(double
the point at which the PDF is evaluated
x
)

Implements org.apache.commons.math3.distribution.RealDistribution.density.

Returns the probability density function (PDF) of this distribution evaluated at the specified point x.

private void
fillBinStats(final EmpiricalDistribution.DataAdapter
object providing access to the data
da
)

Fills binStats array (second pass through data file).

private int

Returns:

the index of the bin containing the value
findBin
(double
the value whose bin we are trying to find
value
)

Returns the index of the bin to which the given value belongs

public int

Returns:

the number of bins.
getBinCount
()

Returns the number of bins.

public List<SummaryStatistics>

Returns:

List of bin statistics.
getBinStats
()

Returns a List of SummaryStatistics instances containing statistics describing the values in each of the bins.

public double[]

Returns:

array of upper bounds of subintervals used in data generation
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.

protected RealDistribution

Returns:

within-bin kernel parameterized by bStats
getKernel
(SummaryStatistics
summary statistics for the bin
bStats
)

The within-bin smoothing kernel.

public double

Returns:

the random value.
getNextValue
()

Generates a random value from this distribution.

public double
getNumericalMean()

Implements org.apache.commons.math3.distribution.RealDistribution.getNumericalMean.

Use this method to get the numerical value of the mean of this distribution.

public double
getNumericalVariance()

Implements org.apache.commons.math3.distribution.RealDistribution.getNumericalVariance.

Use this method to get the numerical value of the variance of this distribution.

public StatisticalSummary

Returns:

the sample statistics
getSampleStats
()

Returns a StatisticalSummary describing this distribution.

public double
public double
public double[]

Returns:

array of bin upper bounds
getUpperBounds
()

Returns a fresh copy of the array of upper bounds for the bins.

public double
public boolean

Returns:

true if the distribution has been loaded
isLoaded
()

Property indicating whether or not the distribution has been loaded.

public boolean
isSupportConnected()

Implements org.apache.commons.math3.distribution.RealDistribution.isSupportConnected.

Use this method to get information about whether the support is connected, i.e. whether all values between the lower and upper bound of the support are included in the support.

public boolean
isSupportLowerBoundInclusive()

Implements org.apache.commons.math3.distribution.RealDistribution.isSupportLowerBoundInclusive.

Whether or not the lower bound of support is in the domain of the density function.

public boolean
isSupportUpperBoundInclusive()

Implements org.apache.commons.math3.distribution.RealDistribution.isSupportUpperBoundInclusive.

Whether or not the upper bound of support is in the domain of the density function.

private RealDistribution

Returns:

the within-bin kernel of the bin containing x
k
(double
the value to locate within a bin
x
)

The within-bin kernel of the bin that x belongs to.

private double

Returns:

the difference in the within-bin kernel cdf between the upper and lower endpoints of bin i
kB
(int
index of the bin
i
)

Mass of bin i under the within-bin kernel of the bin.

public void
load(double[]
the input data array
in
)

Computes the empirical distribution from the provided array of numbers.

public void
load(URL
url of the input file
url
)

Computes the empirical distribution using data read from a URL.

public void
load(File
the input file
file
)

Computes the empirical distribution from the input file.

private double

Returns:

the probability that selection begins in bin i
pB
(int
the index of the bin
i
)

The probability of bin i.

private double

Returns:

the probability that selection begins in a bin below bin i.
pBminus
(int
the index of the bin
i
)

The combined probability of the bins up to but not including bin i.

public double
probability(double
the point at which the PMF is evaluated
x
)

Overrides org.apache.commons.math3.distribution.AbstractRealDistribution.probability.

Implements org.apache.commons.math3.distribution.RealDistribution.probability.

For a random variable X whose values are distributed according to this distribution, this method returns P(X = x).

public void
reSeed(long
random generator seed
seed
)

Reseeds the random number generator used by getNextValue().

public void
Inherited from org.apache.commons.math3.distribution.AbstractRealDistribution:
cumulativeProbabilitygetSolverAbsoluteAccuracylogDensityprobabilitysamplesample

Field Detail

binCountback to summary
private final int binCount

number of bins

binStatsback to summary
private final List<SummaryStatistics> binStats

List of SummaryStatistics objects characterizing the bins

DEFAULT_BIN_COUNTback to summary
public static final int DEFAULT_BIN_COUNT

Default bin count

deltaback to summary
private double delta

Grid size

FILE_CHARSETback to summary
private static final String FILE_CHARSET

Character set for file input

loadedback to summary
private boolean loaded

is the distribution loaded?

maxback to summary
private double max

Max loaded value

minback to summary
private double min

Min loaded value

randomDataback to summary
protected final RandomDataGenerator randomData

Hides org.apache.commons.math3.distribution.AbstractRealDistribution.randomData.

Deprecated

as a consequence of RandomDataGenerator being deprecated. See corresponding docs for further information.

RandomDataGenerator instance to use in repeated calls to getNext()

sampleStatsback to summary
private SummaryStatistics sampleStats

Sample statistics

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.math3.distribution.AbstractRealDistribution.serialVersionUID.

Serializable version identifier

upperBoundsback to summary
private double[] upperBounds

upper bounds of subintervals in (0,1) "belonging" to the bins

Constructor Detail

EmpiricalDistributionback to summary
public EmpiricalDistribution()

Creates a new EmpiricalDistribution with the default bin count.

EmpiricalDistributionback to summary
public EmpiricalDistribution(int binCount)

Creates a new EmpiricalDistribution with the specified bin count.

Parameters
binCount:int

number of bins. Must be strictly positive.

Exceptions
NotStrictlyPositiveException:
if binCount <= 0.
EmpiricalDistributionback to summary
public EmpiricalDistribution(int binCount, RandomGenerator generator)

Creates a new EmpiricalDistribution with the specified bin count using the provided RandomGenerator as the source of random data.

Parameters
binCount:int

number of bins. Must be strictly positive.

generator:RandomGenerator

random data generator (may be null, resulting in default JDK generator)

Exceptions
NotStrictlyPositiveException:
if binCount <= 0.
Since
3.0
EmpiricalDistributionback to summary
public EmpiricalDistribution(RandomGenerator generator)

Creates a new EmpiricalDistribution with default bin count using the provided RandomGenerator as the source of random data.

Parameters
generator:RandomGenerator

random data generator (may be null, resulting in default JDK generator)

Since
3.0
EmpiricalDistributionback to summary
public EmpiricalDistribution(int binCount, RandomDataImpl randomData)

Deprecated

As of 3.1. Please use EmpiricalDistribution(int, RandomGenerator) instead.

Creates a new EmpiricalDistribution with the specified bin count using the provided RandomDataImpl instance as the source of random data.

Parameters
binCount:int

number of bins

randomData:RandomDataImpl

random data generator (may be null, resulting in default JDK generator)

Annotations
@Deprecated
Since
3.0
EmpiricalDistributionback to summary
public EmpiricalDistribution(RandomDataImpl randomData)

Deprecated

As of 3.1. Please use EmpiricalDistribution(RandomGenerator) instead.

Creates a new EmpiricalDistribution with default bin count using the provided RandomDataImpl as the source of random data.

Parameters
randomData:RandomDataImpl

random data generator (may be null, resulting in default JDK generator)

Annotations
@Deprecated
Since
3.0
EmpiricalDistributionback to summary
private EmpiricalDistribution(int binCount, RandomDataGenerator randomData)

Deprecated

as a consequence of RandomDataGenerator being deprecated. See corresponding docs for further information.

Private constructor to allow lazy initialisation of the RNG contained in the randomData instance variable.

Parameters
binCount:int

number of bins. Must be strictly positive.

randomData:RandomDataGenerator

Random data generator.

Exceptions
NotStrictlyPositiveException:
if binCount <= 0.

Method Detail

cumBinPback to summary
private double cumBinP(int binIndex)

The combined probability of the bins up to and including binIndex.

Parameters
binIndex:int

maximum bin index

Returns:double

sum of the probabilities of bins through binIndex

cumulativeProbabilityback to summary
public double cumulativeProbability(double x)

Implements org.apache.commons.math3.distribution.RealDistribution.cumulativeProbability.

Doc from org.apache.commons.math3.distribution.RealDistribution.cumulativeProbability.

For a random variable X whose values are distributed according to this distribution, this method returns P(X <= x). In other words, this method represents the (cumulative) distribution function (CDF) for this distribution.

Algorithm description:

  1. Find the bin B that x belongs to.
  2. Compute P(B) = the mass of B and P(B-) = the combined mass of the bins below B.
  3. Compute K(B) = the probability mass of B with respect to the within-bin kernel and K(B-) = the kernel distribution evaluated at the lower endpoint of B
  4. Return P(B-) + P(B) * [K(x) - K(B-)] / K(B) where K(x) is the within-bin kernel distribution function evaluated at x.
If K is a constant distribution, we return P(B-) + P(B) (counting the full mass of B).

Parameters
x:double

the point at which the CDF is evaluated

Returns:double

the probability that a random variable with this distribution takes a value less than or equal to x

Since
3.1
densityback to summary
public double density(double x)

Implements org.apache.commons.math3.distribution.RealDistribution.density.

Doc from org.apache.commons.math3.distribution.RealDistribution.density.

Returns the probability density function (PDF) of this distribution evaluated at the specified point x. In general, the PDF is the derivative of the CDF. If the derivative does not exist at x, then an appropriate replacement should be returned, e.g. Double.POSITIVE_INFINITY, Double.NaN, or the limit inferior or limit superior of the difference quotient.

Returns the kernel density normalized so that its integral over each bin equals the bin mass.

Algorithm description:

  1. Find the bin B that x belongs to.
  2. Compute K(B) = the mass of B with respect to the within-bin kernel (i.e., the integral of the kernel density over B).
  3. Return k(x) * P(B) / K(B), where k is the within-bin kernel density and P(B) is the mass of B.

Parameters
x:double

the point at which the PDF is evaluated

Returns:double

the value of the probability density function at point x

Since
3.1
fillBinStatsback to summary
private void fillBinStats(final EmpiricalDistribution.DataAdapter da) throws IOException

Fills binStats array (second pass through data file).

Parameters
da:EmpiricalDistribution.DataAdapter

object providing access to the data

Exceptions
IOException:
if an IO error occurs
findBinback to summary
private int findBin(double value)

Returns the index of the bin to which the given value belongs

Parameters
value:double

the value whose bin we are trying to find

Returns:int

the index of the bin containing the value

getBinCountback to summary
public int getBinCount()

Returns the number of bins.

Returns:int

the number of bins.

getBinStatsback to summary
public List<SummaryStatistics> getBinStats()

Returns a List of SummaryStatistics instances containing statistics describing the values in each of the bins. The list is indexed on the bin number.

Returns:List<SummaryStatistics>

List of bin statistics.

getGeneratorUpperBoundsback to summary
public 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.

Preconditions:
  • the distribution must be loaded before invoking this method

In versions 1.0-2.0 of commons-math, this array was (incorrectly) returned by getUpperBounds().

Returns:double[]

array of upper bounds of subintervals used in data generation

Exceptions
NullPointerException:
unless a load method has been called beforehand.
Since
2.1
getKernelback to summary
protected RealDistribution getKernel(SummaryStatistics bStats)

The within-bin smoothing kernel. Returns a Gaussian distribution parameterized by bStats, unless the bin contains only one observation, in which case a constant distribution is returned.

Parameters
bStats:SummaryStatistics

summary statistics for the bin

Returns:RealDistribution

within-bin kernel parameterized by bStats

getNextValueback to summary
public double getNextValue() throws MathIllegalStateException

Generates a random value from this distribution. Preconditions:

  • the distribution must be loaded before invoking this method
Returns:double

the random value.

Exceptions
MathIllegalStateException:
if the distribution has not been loaded
getNumericalMeanback to summary
public double getNumericalMean()

Implements org.apache.commons.math3.distribution.RealDistribution.getNumericalMean.

Doc from org.apache.commons.math3.distribution.RealDistribution.getNumericalMean.

Use this method to get the numerical value of the mean of this distribution.

Returns:double

the mean or Double.NaN if it is not defined

Since
3.1
getNumericalVarianceback to summary
public double getNumericalVariance()

Implements org.apache.commons.math3.distribution.RealDistribution.getNumericalVariance.

Doc from org.apache.commons.math3.distribution.RealDistribution.getNumericalVariance.

Use this method to get the numerical value of the variance of this distribution.

Returns:double

the variance (possibly Double.POSITIVE_INFINITY as for certain cases in TDistribution) or Double.NaN if it is not defined

Since
3.1
getSampleStatsback to summary
public StatisticalSummary getSampleStats()

Returns a StatisticalSummary describing this distribution. Preconditions:

  • the distribution must be loaded before invoking this method
Returns:StatisticalSummary

the sample statistics

Exceptions
IllegalStateException:
if the distribution has not been loaded
getSupportLowerBoundback to summary
public double getSupportLowerBound()

Implements org.apache.commons.math3.distribution.RealDistribution.getSupportLowerBound.

Doc from org.apache.commons.math3.distribution.RealDistribution.getSupportLowerBound.

Access the lower bound of the support. This method must return the same value as inverseCumulativeProbability(0). In other words, this method must return

inf {x in R | P(X <= x) > 0}.

Returns:double

lower bound of the support (might be Double.NEGATIVE_INFINITY)

Since
3.1
getSupportUpperBoundback to summary
public double getSupportUpperBound()

Implements org.apache.commons.math3.distribution.RealDistribution.getSupportUpperBound.

Doc from org.apache.commons.math3.distribution.RealDistribution.getSupportUpperBound.

Access the upper bound of the support. This method must return the same value as inverseCumulativeProbability(1). In other words, this method must return

inf {x in R | P(X <= x) = 1}.

Returns:double

upper bound of the support (might be Double.POSITIVE_INFINITY)

Since
3.1
getUpperBoundsback to summary
public 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().

Returns:double[]

array of bin upper bounds

Since
2.1
inverseCumulativeProbabilityback to summary
public double inverseCumulativeProbability(final double p) throws OutOfRangeException

Overrides org.apache.commons.math3.distribution.AbstractRealDistribution.inverseCumulativeProbability.

Implements org.apache.commons.math3.distribution.RealDistribution.inverseCumulativeProbability.

Doc from org.apache.commons.math3.distribution.AbstractRealDistribution.inverseCumulativeProbability.

Computes the quantile function of this distribution. For a random variable X distributed according to this distribution, the returned value is

  • inf{x in R | P(X<=x) >= p} for 0 < p <= 1,
  • inf{x in R | P(X<=x) > 0} for p = 0.
The default implementation returns

Algorithm description:

  1. Find the smallest i such that the sum of the masses of the bins through i is at least p.
  2. Let K be the within-bin kernel distribution for bin i.
    Let K(B) be the mass of B under K.
    Let K(B-) be K evaluated at the lower endpoint of B (the combined mass of the bins below B under K).
    Let P(B) be the probability of bin i.
    Let P(B-) be the sum of the bin masses below bin i.
    Let pCrit = p - P(B-)
  3. Return the inverse of K evaluated at
    K(B-) + pCrit * K(B) / P(B)

Parameters
p:double

Doc from org.apache.commons.math3.distribution.RealDistribution.inverseCumulativeProbability.

the cumulative probability

Returns:double

Doc from org.apache.commons.math3.distribution.RealDistribution.inverseCumulativeProbability.

the smallest p-quantile of this distribution (largest 0-quantile for p = 0)

Annotations
@Override
Exceptions
OutOfRangeException:

Doc from org.apache.commons.math3.distribution.RealDistribution.inverseCumulativeProbability.

if p < 0 or p > 1

Since
3.1
isLoadedback to summary
public boolean isLoaded()

Property indicating whether or not the distribution has been loaded.

Returns:boolean

true if the distribution has been loaded

isSupportConnectedback to summary
public boolean isSupportConnected()

Implements org.apache.commons.math3.distribution.RealDistribution.isSupportConnected.

Doc from org.apache.commons.math3.distribution.RealDistribution.isSupportConnected.

Use this method to get information about whether the support is connected, i.e. whether all values between the lower and upper bound of the support are included in the support.

Returns:boolean

whether the support is connected or not

Since
3.1
isSupportLowerBoundInclusiveback to summary
public boolean isSupportLowerBoundInclusive()

Implements org.apache.commons.math3.distribution.RealDistribution.isSupportLowerBoundInclusive.

Doc from org.apache.commons.math3.distribution.RealDistribution.isSupportLowerBoundInclusive.

Whether or not the lower bound of support is in the domain of the density function. Returns true iff getSupporLowerBound() is finite and density(getSupportLowerBound()) returns a non-NaN, non-infinite value.

Returns:boolean

true if the lower bound of support is finite and the density function returns a non-NaN, non-infinite value there

Since
3.1
isSupportUpperBoundInclusiveback to summary
public boolean isSupportUpperBoundInclusive()

Implements org.apache.commons.math3.distribution.RealDistribution.isSupportUpperBoundInclusive.

Doc from org.apache.commons.math3.distribution.RealDistribution.isSupportUpperBoundInclusive.

Whether or not the upper bound of support is in the domain of the density function. Returns true iff getSupportUpperBound() is finite and density(getSupportUpperBound()) returns a non-NaN, non-infinite value.

Returns:boolean

true if the upper bound of support is finite and the density function returns a non-NaN, non-infinite value there

Since
3.1
kback to summary
private RealDistribution k(double x)

The within-bin kernel of the bin that x belongs to.

Parameters
x:double

the value to locate within a bin

Returns:RealDistribution

the within-bin kernel of the bin containing x

kBback to summary
private double kB(int i)

Mass of bin i under the within-bin kernel of the bin.

Parameters
i:int

index of the bin

Returns:double

the difference in the within-bin kernel cdf between the upper and lower endpoints of bin i

Annotations
@SuppressWarnings:deprecation
loadback to summary
public void load(double[] in) throws NullArgumentException

Computes the empirical distribution from the provided array of numbers.

Parameters
in:double[]

the input data array

Exceptions
NullArgumentException:
if in is null
loadback to summary
public void load(URL url) throws IOException, NullArgumentException, ZeroException

Computes the empirical distribution using data read from a URL.

The input file must be an ASCII text file containing one valid numeric entry per line.

Parameters
url:URL

url of the input file

Exceptions
IOException:
if an IO error occurs
NullArgumentException:
if url is null
ZeroException:
if URL contains no data
loadback to summary
public void load(File file) throws IOException, NullArgumentException

Computes the empirical distribution from the input file.

The input file must be an ASCII text file containing one valid numeric entry per line.

Parameters
file:File

the input file

Exceptions
IOException:
if an IO error occurs
NullArgumentException:
if file is null
pBback to summary
private double pB(int i)

The probability of bin i.

Parameters
i:int

the index of the bin

Returns:double

the probability that selection begins in bin i

pBminusback to summary
private double pBminus(int i)

The combined probability of the bins up to but not including bin i.

Parameters
i:int

the index of the bin

Returns:double

the probability that selection begins in a bin below bin i.

probabilityback to summary
public double probability(double x)

Overrides org.apache.commons.math3.distribution.AbstractRealDistribution.probability.

Implements org.apache.commons.math3.distribution.RealDistribution.probability.

Doc from org.apache.commons.math3.distribution.AbstractRealDistribution.probability.

For a random variable X whose values are distributed according to this distribution, this method returns P(X = x). In other words, this method represents the probability mass function (PMF) for the distribution.

Parameters
x:double

Doc from org.apache.commons.math3.distribution.RealDistribution.probability.

the point at which the PMF is evaluated

Returns:double

zero.

Annotations
@Override
Since
3.1
reSeedback to summary
public void reSeed(long seed)

Reseeds the random number generator used by getNextValue().

Parameters
seed:long

random generator seed

Since
3.0
reseedRandomGeneratorback to summary
public void reseedRandomGenerator(long seed)

Overrides org.apache.commons.math3.distribution.AbstractRealDistribution.reseedRandomGenerator.

Implements org.apache.commons.math3.distribution.RealDistribution.reseedRandomGenerator.

Doc from org.apache.commons.math3.distribution.AbstractRealDistribution.reseedRandomGenerator.

Reseed the random generator used to generate samples.

Parameters
seed:long

Doc from org.apache.commons.math3.distribution.RealDistribution.reseedRandomGenerator.

the new seed

Annotations
@Override
Since
3.1
org.apache.commons.math3.random back to summary

private Class EmpiricalDistribution.ArrayDataAdapter

extends DataAdapter
Class Inheritance

DataAdapter for data provided as array of doubles.

Field Summary

Modifier and TypeField and Description
private double[]
inputArray

Array of input data values

Constructor Summary

AccessConstructor and Description
pack-priv
ArrayDataAdapter(double[]
double[] array holding the data
in
)

Construct an ArrayDataAdapter from a double[] array

Method Summary

Modifier and TypeMethod and Description
public void
public void

Field Detail

inputArrayback to summary
private double[] inputArray

Array of input data values

Constructor Detail

ArrayDataAdapterback to summary
pack-priv ArrayDataAdapter(double[] in) throws NullArgumentException

Construct an ArrayDataAdapter from a double[] array

Parameters
in:double[]

double[] array holding the data

Exceptions
NullArgumentException:
if in is null

Method Detail

computeBinStatsback to summary
public void computeBinStats() throws IOException

Implements abstract org.apache.commons.math3.random.EmpiricalDistribution.DataAdapter.computeBinStats.

Doc from org.apache.commons.math3.random.EmpiricalDistribution.DataAdapter.computeBinStats.

Compute bin stats.

Annotations
@Override
Exceptions
IOException:
if an error occurs computing bin stats
computeStatsback to summary
public void computeStats() throws IOException

Implements abstract org.apache.commons.math3.random.EmpiricalDistribution.DataAdapter.computeStats.

Doc from org.apache.commons.math3.random.EmpiricalDistribution.DataAdapter.computeStats.

Compute sample statistics.

Annotations
@Override
Exceptions
IOException:
if an error occurs computing sample stats
org.apache.commons.math3.random back to summary

private abstract Class EmpiricalDistribution.DataAdapter

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.commons.math3.random.EmpiricalDistribution.DataAdapter
Known Direct Subclasses
org.apache.commons.math3.random.EmpiricalDistribution.StreamDataAdapter, org.apache.commons.math3.random.EmpiricalDistribution.ArrayDataAdapter

Provides methods for computing sampleStats and beanStats abstracting the source of data.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public abstract void
computeBinStats()

Compute bin stats.

public abstract void
computeStats()

Compute sample statistics.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

DataAdapterback to summary
private DataAdapter()

Method Detail

computeBinStatsback to summary
public abstract void computeBinStats() throws IOException

Compute bin stats.

Exceptions
IOException:
if an error occurs computing bin stats
computeStatsback to summary
public abstract void computeStats() throws IOException

Compute sample statistics.

Exceptions
IOException:
if an error occurs computing sample stats
org.apache.commons.math3.random back to summary

private Class EmpiricalDistribution.StreamDataAdapter

extends DataAdapter
Class Inheritance

DataAdapter for data provided through some input stream

Field Summary

Modifier and TypeField and Description
private BufferedReader
inputStream

Input stream providing access to the data

Constructor Summary

AccessConstructor and Description
pack-priv
StreamDataAdapter(BufferedReader
BufferedReader input stream
in
)

Create a StreamDataAdapter from a BufferedReader

Method Summary

Modifier and TypeMethod and Description
public void
public void

Field Detail

inputStreamback to summary
private BufferedReader inputStream

Input stream providing access to the data

Constructor Detail

StreamDataAdapterback to summary
pack-priv StreamDataAdapter(BufferedReader in)

Create a StreamDataAdapter from a BufferedReader

Parameters
in:BufferedReader

BufferedReader input stream

Method Detail

computeBinStatsback to summary
public void computeBinStats() throws IOException

Implements abstract org.apache.commons.math3.random.EmpiricalDistribution.DataAdapter.computeBinStats.

Doc from org.apache.commons.math3.random.EmpiricalDistribution.DataAdapter.computeBinStats.

Compute bin stats.

Annotations
@Override
Exceptions
IOException:
if an error occurs computing bin stats
computeStatsback to summary
public void computeStats() throws IOException

Implements abstract org.apache.commons.math3.random.EmpiricalDistribution.DataAdapter.computeStats.

Doc from org.apache.commons.math3.random.EmpiricalDistribution.DataAdapter.computeStats.

Compute sample statistics.

Annotations
@Override
Exceptions
IOException:
if an error occurs computing sample stats