blog.distrib
Class MultivarGaussian

java.lang.Object
  extended by blog.AbstractCondProbDistrib
      extended by blog.distrib.MultivarGaussian
All Implemented Interfaces:
CondProbDistrib

public class MultivarGaussian
extends AbstractCondProbDistrib

Gaussian (normal) distribution over real vectors of some fixed dimensionality d. This CPD can be initialized with one, two, or three parameters. If three parameters are given, then they are the dimension, mean, and covariance matrix. If two parameters are given, they are interpreted as the dimension and covariance matrix; in this case the mean must be passed as an argument to the getProb and sampleVal methods. If only one parameter is given, it is the dimension, and the mean and covariance matrix must both be given as arguments.


Constructor Summary
MultivarGaussian(java.util.List params)
          Sets mean and covariance and ensures that their dimensions match.
MultivarGaussian(Jama.Matrix mean, Jama.Matrix covariance)
          Creates a new MultivarGaussian distribution with the given mean vector and covariance matrix.
 
Method Summary
 Jama.Matrix getCovar()
          Returns the covariance matrix of this distribution, or null if the covariance is not fixed.
 double getLogProb(Jama.Matrix x)
          Returns the natural log of the probability returned by getProb.
 Jama.Matrix getMean()
          Returns the mean of this distribution, or null if the mean is not fixed.
 double getProb(java.util.List args, java.lang.Object value)
          Ensures that x = value is a column matrix of appropriate dimension d and returns the density of this Gaussian distribution at x.
 double getProb(Jama.Matrix x)
          Given a d-dimensional column vector x, returns the density value p = 1/sqrt((2*pi)^d*|sigma|)*exp{-0.5(x-mean)'*inverse(sigma)*(x-mean)}
 Jama.Matrix sampleVal()
          Samples a value from this multivariate Gaussian by generating d independent samples from univariate Gaussians with unit variance, one for each mean in the mean vector, and multiplying the obtained vector on the left by the square root of sigma (Cholesky decomposition of sigma).
 java.lang.Object sampleVal(java.util.List args, Type childType)
          Samples a value from this multivariate Gaussian by generating d independent samples from univariate Gaussians with unit variance, one for each dimension, and multiplying the obtained vector on the left by the square root of sigma (Cholesky decomposition of sigma).
 
Methods inherited from class blog.AbstractCondProbDistrib
getLogProb, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MultivarGaussian

public MultivarGaussian(Jama.Matrix mean,
                        Jama.Matrix covariance)
Creates a new MultivarGaussian distribution with the given mean vector and covariance matrix. The dimension is inferred from the length of the mean vector.

Parameters:
mean - 1-by-d mean vector
covariance - d-by-d covariance matrix

MultivarGaussian

public MultivarGaussian(java.util.List params)
Sets mean and covariance and ensures that their dimensions match.

Method Detail

getProb

public double getProb(java.util.List args,
                      java.lang.Object value)
Ensures that x = value is a column matrix of appropriate dimension d and returns the density of this Gaussian distribution at x.


getProb

public double getProb(Jama.Matrix x)
Given a d-dimensional column vector x, returns the density value p = 1/sqrt((2*pi)^d*|sigma|)*exp{-0.5(x-mean)'*inverse(sigma)*(x-mean)}

Throws:
java.lang.IllegalStateException - if this distribution does not have fixed mean and covariance

getLogProb

public double getLogProb(Jama.Matrix x)
Returns the natural log of the probability returned by getProb.


sampleVal

public java.lang.Object sampleVal(java.util.List args,
                                  Type childType)
Samples a value from this multivariate Gaussian by generating d independent samples from univariate Gaussians with unit variance, one for each dimension, and multiplying the obtained vector on the left by the square root of sigma (Cholesky decomposition of sigma). This method should only be called if this distribution was constructed with a fixed mean and covariance matrix (internal calls are ok if the private method initParams is called first).


sampleVal

public Jama.Matrix sampleVal()
Samples a value from this multivariate Gaussian by generating d independent samples from univariate Gaussians with unit variance, one for each mean in the mean vector, and multiplying the obtained vector on the left by the square root of sigma (Cholesky decomposition of sigma). This method should only be called if this distribution was constructed with a fixed mean and covariance matrix (internal calls are ok if the private method initParams is called first).


getMean

public Jama.Matrix getMean()
Returns the mean of this distribution, or null if the mean is not fixed.


getCovar

public Jama.Matrix getCovar()
Returns the covariance matrix of this distribution, or null if the covariance is not fixed.