public class GenericDiscreteDistribution extends Object implements SamplingDistribution<Integer>, ProbabilityMassFunction, LogProbabilityMassFunction
Modifier and Type | Field and Description |
---|---|
protected double[] |
cdf
cumulative distribution function, used for sampling
|
private boolean |
LOG
Tells if the distribution is internally represented by the natural logarithm of the probability values
|
protected double[] |
pmf
probability mass function
|
protected Random |
rand |
Constructor and Description |
---|
GenericDiscreteDistribution(double[] weights,
Random rand)
Constructor.
|
GenericDiscreteDistribution(double[] weights,
Random rand,
boolean weightsAreLog)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
Integer |
drawSample()
Generate a new sample from this density.
|
double |
log_p(Integer k)
Evaluate natural logarithm of p(X) at location x. log(P(X=x))
|
double |
p(Integer k)
Evaluate p(X) at location x.
|
String |
toString() |
protected Random rand
private boolean LOG
protected double[] pmf
protected double[] cdf
public GenericDiscreteDistribution(double[] weights, Random rand)
weigths.length-1
.
Weights must not sum to 0 and must not be negative. If weights do not sum to 1, they get normalized.weights
- proportional to the probabilities of events 0 to weigths.length-1
.rand
- a random generator used for samplingpublic GenericDiscreteDistribution(double[] weights, Random rand, boolean weightsAreLog)
weigths.length-1
.
If so, (log-)weights must not sum to Double.NEGATIVE_INFINITY
. If (log-)weights do not sum to 0, they get normalized.
If weights are not logarithms of probabilities, see GenericDiscreteDistribution(double[] weights, Random rand)
.weights
- (the natural logarithm of values proportional to) the probabilities of events 0 to weigths.length-1
.rand
- a random generator used for samplingweightsAreLog
- determines if weights are interpreted as log probabilitiespublic double p(Integer k)
EvaluatableDistribution
p
in interface EvaluatableDistribution<Integer>
k
- realization of random variable Xpublic double log_p(Integer k)
LogEvaluatableDistribution
log_p
in interface LogEvaluatableDistribution<Integer>
k
- realization of random variable Xpublic Integer drawSample()
SamplingDistribution
drawSample
in interface SamplingDistribution<Integer>
Copyright © 2010–2020 Martin Luther University Halle-Wittenberg, Institute of Computer Science, Pattern Recognition and Bioinformatics. All rights reserved.