de.unihalle.informatik.MiToBo.math.distributions.impl
Class GenericDiscreteDistribution

java.lang.Object
  extended by de.unihalle.informatik.MiToBo.math.distributions.impl.GenericDiscreteDistribution
All Implemented Interfaces:
EvaluatableDistribution<java.lang.Integer>, LogEvaluatableDistribution<java.lang.Integer>, LogProbabilityMassFunction, ProbabilityMassFunction, SamplingDistribution<java.lang.Integer>

public class GenericDiscreteDistribution
extends java.lang.Object
implements SamplingDistribution<java.lang.Integer>, ProbabilityMassFunction, LogProbabilityMassFunction

A generic discrete distribution

Author:
Oliver Gress

Field Summary
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  java.util.Random rand
           
 
Constructor Summary
GenericDiscreteDistribution(double[] weights, java.util.Random rand)
          Constructor.
GenericDiscreteDistribution(double[] weights, java.util.Random rand, boolean weightsAreLog)
          Constructor.
 
Method Summary
 java.lang.Integer drawSample()
          Generate a new sample from this density.
 double log_p(java.lang.Integer k)
          Evaluate natural logarithm of p(X) at location x. log(P(X=x))
 double p(java.lang.Integer k)
          Evaluate p(X) at location x.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cdf

protected double[] cdf
cumulative distribution function, used for sampling


LOG

private boolean LOG
Tells if the distribution is internally represented by the natural logarithm of the probability values


pmf

protected double[] pmf
probability mass function


rand

protected java.util.Random rand
Constructor Detail

GenericDiscreteDistribution

public GenericDiscreteDistribution(double[] weights,
                                   java.util.Random rand)
Constructor. The weights represent the discrete distribution of values 0 to weigths.length-1. Weights must not sum to 0 and must not be negative. If weights do not sum to 1, they get normalized.

Parameters:
weights - proportional to the probabilities of events 0 to weigths.length-1.
rand - a random generator used for sampling

GenericDiscreteDistribution

public GenericDiscreteDistribution(double[] weights,
                                   java.util.Random rand,
                                   boolean weightsAreLog)
Constructor. The weights might represent natural logarithm of the probabilities of values 0 to 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).

Parameters:
weights - (the natural logarithm of values proportional to) the probabilities of events 0 to weigths.length-1.
rand - a random generator used for sampling
weightsAreLog - determines if weights are interpreted as log probabilities
Method Detail

drawSample

public java.lang.Integer drawSample()
Description copied from interface: SamplingDistribution
Generate a new sample from this density. This method should create a new object.

Specified by:
drawSample in interface SamplingDistribution<java.lang.Integer>
Returns:
new sample object

log_p

public double log_p(java.lang.Integer k)
Description copied from interface: LogEvaluatableDistribution
Evaluate natural logarithm of p(X) at location x. log(P(X=x))

Specified by:
log_p in interface LogEvaluatableDistribution<java.lang.Integer>
Parameters:
k - realization of random variable X
Returns:
value of log(p(X)) at x

p

public double p(java.lang.Integer k)
Description copied from interface: EvaluatableDistribution
Evaluate p(X) at location x. P(X=x)

Specified by:
p in interface EvaluatableDistribution<java.lang.Integer>
Parameters:
k - realization of random variable X
Returns:
value of p(X) at x

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object