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<Integer>, LogEvaluatableDistribution<Integer>, LogProbabilityMassFunction, ProbabilityMassFunction, SamplingDistribution<Integer>

@ALDMetaInfo(export=ALLOWED)
public class GenericDiscreteDistribution
extends Object
implements SamplingDistribution<Integer>, ProbabilityMassFunction, LogProbabilityMassFunction

A generic discrete distribution

Author:
Oliver Gress

Field Summary
protected  double[] cdf
          cumulative distribution function, used for sampling
protected  double[] pmf
          probability mass function
protected  Random rand
           
 
Constructor Summary
GenericDiscreteDistribution(double[] weights, Random rand)
          Constructor.
GenericDiscreteDistribution(double[] weights, Random rand, boolean weightsAreLog)
          Constructor.
 
Method Summary
 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()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

rand

protected Random rand

pmf

protected double[] pmf
probability mass function


cdf

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

Constructor Detail

GenericDiscreteDistribution

public GenericDiscreteDistribution(double[] weights,
                                   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,
                                   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

p

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

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

log_p

public double log_p(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<Integer>
Parameters:
k - realization of random variable X
Returns:
value of log(p(X)) at x

drawSample

public 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<Integer>
Returns:
new sample object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2010–2015 Martin Luther University Halle-Wittenberg. All rights reserved.