blog.distrib
Class UnivarGaussian

java.lang.Object
  extended by blog.AbstractCondProbDistrib
      extended by blog.distrib.UnivarGaussian
All Implemented Interfaces:
CondProbDistrib
Direct Known Subclasses:
Gaussian

public class UnivarGaussian
extends AbstractCondProbDistrib

Gaussian (normal) distribution over real numbers. This CPD can be initialized with zero, one, or two parameters. If two parameters are given, then the first is the mean and the second is the variance. If only one parameter is given, it is interpreted as the variance, and the getProb and sampleVal methods will expect one argument specifying the mean. If no parameters are given, then those methods will expect two arguments, the mean and the variance.


Field Summary
static UnivarGaussian STANDARD
           
 
Constructor Summary
UnivarGaussian(double mean, double variance)
          Creates a univariate Gaussian distribution with the given fixed mean and variance.
UnivarGaussian(java.util.List params)
          Creates a univariate Gaussian distribution.
 
Method Summary
 double getLogProb(double x)
          Returns the natural log of the density of this Gaussian distribution at the given value.
 double getLogProb(java.util.List args, java.lang.Object value)
          Returns the natural log of the value returned by getProb.
 double getProb(double x)
          Returns the density of this Gaussian distribution at the given value.
 double getProb(java.util.List args, java.lang.Object value)
          For a discrete distribution, returns the conditional probability of childValue given the argument values args.
 double sampleVal()
          Returns a value sampled from this Gaussian distribution.
 java.lang.Object sampleVal(java.util.List args, Type childType)
          Samples a value according to this CPD given the args .
 
Methods inherited from class blog.AbstractCondProbDistrib
toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STANDARD

public static final UnivarGaussian STANDARD
Constructor Detail

UnivarGaussian

public UnivarGaussian(double mean,
                      double variance)
Creates a univariate Gaussian distribution with the given fixed mean and variance.


UnivarGaussian

public UnivarGaussian(java.util.List params)
Creates a univariate Gaussian distribution. If two parameters are given, then the first is the mean and the second is the variance. If only one parameter is given, it is interpreted as the variance. Parameters not specified here must be given as arguments to getProb and sampleVal.

Method Detail

getProb

public double getProb(java.util.List args,
                      java.lang.Object value)
Description copied from interface: CondProbDistrib
For a discrete distribution, returns the conditional probability of childValue given the argument values args. For a continuous distribution, returns the conditional probability density at childValue.


getLogProb

public double getLogProb(java.util.List args,
                         java.lang.Object value)
Description copied from interface: CondProbDistrib
Returns the natural log of the value returned by getProb.

Specified by:
getLogProb in interface CondProbDistrib
Overrides:
getLogProb in class AbstractCondProbDistrib

getProb

public double getProb(double x)
Returns the density of this Gaussian distribution at the given value. This method should only be called if the mean and variance were set in the constructor (internal calls are ok if the private method initParams is called first).


getLogProb

public double getLogProb(double x)
Returns the natural log of the density of this Gaussian distribution at the given value. This method should only be called if the meand and variance were set in the constructor, or if initParams has been called.


sampleVal

public java.lang.Object sampleVal(java.util.List args,
                                  Type childType)
Description copied from interface: CondProbDistrib
Samples a value according to this CPD given the args . The object returned should be of the specified type.


sampleVal

public double sampleVal()
Returns a value sampled from this Gaussian distribution. This method should only be called if the mean and variance were set in the constructor (internal calls are ok if the private method initParams is called first).

The implementation uses the Box-Muller transformation [G.E.P. Box and M.E. Muller (1958) "A note on the generation of random normal deviates". Ann. Math. Stat 29:610-611]. See also http://www.cs.princeton.edu/introcs/26function/MyMath.java.html