Class BaseDistribution
- java.lang.Object
-
- org.nd4j.linalg.api.rng.distribution.BaseDistribution
-
- All Implemented Interfaces:
Distribution
- Direct Known Subclasses:
BinomialDistribution,ConstantDistribution,LogNormalDistribution,NormalDistribution,OrthogonalDistribution,TruncatedNormalDistribution,UniformDistribution
public abstract class BaseDistribution extends Object implements Distribution
-
-
Field Summary
Fields Modifier and Type Field Description protected Randomrandomprotected doublesolverAbsoluteAccuracy
-
Constructor Summary
Constructors Constructor Description BaseDistribution()BaseDistribution(Random rng)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected doublegetSolverAbsoluteAccuracy()Returns the solver absolute accuracy for inverse cumulative computation.doubleinverseCumulativeProbability(double p)Computes the quantile function of this distribution.doubleprobability(double x)For a random variableXwhose values are distributed according to this distribution, this method returnsP(X = x).doubleprobability(double x0, double x1)For a random variableXwhose values are distributed according to this distribution, this method returnsP(x0 < X <= x1).voidreseedRandomGenerator(long seed)Reseed the random generator used to generate samples.doublesample()Generate a random value sampled from this distribution.INDArraysample(int[] shape)Sample the given shapedouble[]sample(long sampleSize)Generate a random sample from the distribution.INDArraysample(long[] shape)INDArraysample(INDArray target)Fill the target array by sampling from the distribution-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.nd4j.linalg.api.rng.distribution.Distribution
cumulativeProbability, cumulativeProbability, density, getNumericalMean, getNumericalVariance, getSupportLowerBound, getSupportUpperBound, isSupportConnected, isSupportLowerBoundInclusive, isSupportUpperBoundInclusive
-
-
-
-
Field Detail
-
random
protected Random random
-
solverAbsoluteAccuracy
protected double solverAbsoluteAccuracy
-
-
Constructor Detail
-
BaseDistribution
public BaseDistribution(Random rng)
-
BaseDistribution
public BaseDistribution()
-
-
Method Detail
-
probability
public double probability(double x0, double x1)For a random variableXwhose values are distributed according to this distribution, this method returnsP(x0 < X <= x1).- Parameters:
x0- Lower bound (excluded).x1- Upper bound (included).- Returns:
- the probability that a random variable with this distribution
takes a value between
x0andx1, excluding the lower and including the upper endpoint. - Throws:
org.apache.commons.math3.exception.NumberIsTooLargeException- ifx0 > x1. The default implementation uses the identityP(x0 < X <= x1) = P(X <= x1) - P(X <= x0)- Since:
- 3.1
-
inverseCumulativeProbability
public double inverseCumulativeProbability(double p) throws org.apache.commons.math3.exception.OutOfRangeExceptionComputes the quantile function of this distribution. For a random variableXdistributed according to this distribution, the returned value isinf{x in R | P(X<=x) >= p}for0 < p <= 1,inf{x in R | P(X<=x) > 0}forp = 0.
Distribution.getSupportLowerBound()forp = 0,Distribution.getSupportUpperBound()forp = 1.
- Specified by:
inverseCumulativeProbabilityin interfaceDistribution- Parameters:
p- the cumulative probability- Returns:
- the smallest
p-quantile of this distribution (largest 0-quantile forp = 0) - Throws:
org.apache.commons.math3.exception.OutOfRangeException- ifp < 0orp > 1
-
getSolverAbsoluteAccuracy
protected double getSolverAbsoluteAccuracy()
Returns the solver absolute accuracy for inverse cumulative computation. You can override this method in order to use a Brent solver with an absolute accuracy different from the default.- Returns:
- the maximum absolute error in inverse cumulative probability estimates
-
reseedRandomGenerator
public void reseedRandomGenerator(long seed)
Reseed the random generator used to generate samples.- Specified by:
reseedRandomGeneratorin interfaceDistribution- Parameters:
seed- the new seed
-
sample
public double sample()
Generate a random value sampled from this distribution. The default implementation uses the inversion method.- Specified by:
samplein interfaceDistribution- Returns:
- a random value.
-
sample
public double[] sample(long sampleSize)
Generate a random sample from the distribution. The default implementation generates the sample by callingsample()in a loop.- Specified by:
samplein interfaceDistribution- Parameters:
sampleSize- the number of random values to generate- Returns:
- an array representing the random sample
-
probability
public double probability(double x)
For a random variableXwhose values are distributed according to this distribution, this method returnsP(X = x). In other words, this method represents the probability mass function (PMF) for the distribution.- Specified by:
probabilityin interfaceDistribution- Parameters:
x- the point at which the PMF is evaluated- Returns:
- zero.
- Since:
- 3.1
-
sample
public INDArray sample(int[] shape)
Description copied from interface:DistributionSample the given shape- Specified by:
samplein interfaceDistribution- Parameters:
shape- the given shape- Returns:
- an ndarray with random samples from this distribution
-
sample
public INDArray sample(long[] shape)
- Specified by:
samplein interfaceDistribution
-
sample
public INDArray sample(INDArray target)
Description copied from interface:DistributionFill the target array by sampling from the distribution- Specified by:
samplein interfaceDistribution- Parameters:
target- target array- Returns:
- an ndarray with random samples from this distribution
-
-