Class Empirical
- java.lang.Object
-
- cern.colt.PersistentObject
-
- cern.jet.random.AbstractDistribution
-
- cern.jet.random.AbstractContinousDistribution
-
- cern.jet.random.Empirical
-
- All Implemented Interfaces:
DoubleFunction
,IntFunction
,java.io.Serializable
,java.lang.Cloneable
public class Empirical extends AbstractContinousDistribution
Empirical distribution.The probability distribution function (pdf) must be provided by the user as an array of positive real numbers. The pdf does not need to be provided in the form of relative probabilities, absolute probabilities are also accepted.
If interpolationType == LINEAR_INTERPOLATION a linear interpolation within the bin is computed, resulting in a constant density within each bin.
- If interpolationType == NO_INTERPOLATION no interpolation is performed and the result is a discrete distribution.
Instance methods operate on a user supplied uniform random number generator; they are unsynchronized.
- Static methods operate on a default uniform random number generator; they are synchronized.
Implementation: A uniform random number is generated using a user supplied generator. The uniform number is then transformed to the user's distribution using the cumulative probability distribution constructed from the pdf. The cumulative distribution is inverted using a binary search for the nearest bin boundary.
This is a port of RandGeneral used in CLHEP 1.4.0 (C++).
- Version:
- 1.0, 09/24/99
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected double[]
cdf
protected int
interpolationType
static int
LINEAR_INTERPOLATION
static int
NO_INTERPOLATION
-
Fields inherited from class cern.jet.random.AbstractDistribution
randomGenerator
-
Fields inherited from class cern.colt.PersistentObject
serialVersionUID
-
-
Constructor Summary
Constructors Constructor Description Empirical(double[] pdf, int interpolationType, RandomEngine randomGenerator)
Constructs an Empirical distribution.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
cdf(int k)
Returns the cumulative distribution function.java.lang.Object
clone()
Returns a deep copy of the receiver; the copy will produce identical sequences.double
nextDouble()
Returns a random number from the distribution.double
pdf(double x)
Returns the probability distribution function.double
pdf(int k)
Returns the probability distribution function.void
setState(double[] pdf, int interpolationType)
Sets the distribution parameters.java.lang.String
toString()
Returns a String representation of the receiver.private int
xnBins()
Not yet commented.-
Methods inherited from class cern.jet.random.AbstractDistribution
apply, apply, getRandomGenerator, makeDefaultGenerator, nextInt, setRandomGenerator
-
-
-
-
Field Detail
-
cdf
protected double[] cdf
-
interpolationType
protected int interpolationType
-
LINEAR_INTERPOLATION
public static final int LINEAR_INTERPOLATION
- See Also:
- Constant Field Values
-
NO_INTERPOLATION
public static final int NO_INTERPOLATION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Empirical
public Empirical(double[] pdf, int interpolationType, RandomEngine randomGenerator)
Constructs an Empirical distribution. The probability distribution function (pdf) is an array of positive real numbers. It need not be provided in the form of relative probabilities, absolute probabilities are also accepted. The pdf must satisfy both of the following conditions- 0.0 <= pdf[i] : 0<=i<=pdf.length-1
- 0.0 < Sum(pdf[i]) : 0<=i<=pdf.length-1
- Parameters:
pdf
- the probability distribution function.interpolationType
- can be either Empirical.NO_INTERPOLATION or Empirical.LINEAR_INTERPOLATION.randomGenerator
- a uniform random number generator.- Throws:
java.lang.IllegalArgumentException
- if at least one of the three conditions above is violated.
-
-
Method Detail
-
cdf
public double cdf(int k)
Returns the cumulative distribution function.
-
clone
public java.lang.Object clone()
Returns a deep copy of the receiver; the copy will produce identical sequences. After this call has returned, the copy and the receiver have equal but separate state.- Overrides:
clone
in classAbstractDistribution
- Returns:
- a copy of the receiver.
-
nextDouble
public double nextDouble()
Returns a random number from the distribution.- Specified by:
nextDouble
in classAbstractDistribution
-
pdf
public double pdf(double x)
Returns the probability distribution function.
-
pdf
public double pdf(int k)
Returns the probability distribution function.
-
setState
public void setState(double[] pdf, int interpolationType)
Sets the distribution parameters. The pdf must satisfy both of the following conditions- 0.0 <= pdf[i] : 0 < =i <= pdf.length-1
- 0.0 < Sum(pdf[i]) : 0 <=i <= pdf.length-1
- Parameters:
pdf
- probability distribution function.interpolationType
- can be either Empirical.NO_INTERPOLATION or Empirical.LINEAR_INTERPOLATION.- Throws:
java.lang.IllegalArgumentException
- if at least one of the three conditions above is violated.
-
toString
public java.lang.String toString()
Returns a String representation of the receiver.- Overrides:
toString
in classjava.lang.Object
-
xnBins
private int xnBins()
Not yet commented.- Returns:
- int
-
-