

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object  +javaslam.prob.Gaussian
A Gaussian probability density over a set of vectorvalued variables.
In the moment parameterization, the density is expressed as
p(x) = (1 / Z) exp {0.5 (x  m)^{T} S^{1}(x  m)}where Z is a normalizing constant, and the vector m (mu) and the (positive definite) matrix S (sigma) are the parameters. m is the expected value (mean) of x and S is its covariance matrix.
In the canonical parameterization, the density is expressed as
p(x) = exp (a + h^{T}x  (1/2) x^{T} L x)where a is a normalizing constant, and the vector h (eta) and the (positive definite) matrix L (lambda) are the parameters. The parameters of the moment and canonical representations are related by
Because some operations are more efficient or more numerically stable in one or the other parameterization, this class uses both representations. When an operation is unsupported by the current parameterization, the user must firstS = L^{1}
m = L^{1}h
reparameterize(boolean)
the density, or else an IllegalStateException
will be thrown.
This class records counts of all floating point operations using
Flops.count(long)
(except those used in the service of
debugging and avoiding numerical errors).
Field Summary  
protected boolean 
doubling
If true , then the capacity (i.e., the actual
dimension of vP and mP ) of this Gaussian is
doubled when it must be increased to accomodate new variables;
otherwise it is increased only enough to admit the new variables. 
protected boolean 
isMoment
A field indicating whether this Gaussian is currently represented in the moment parameterization. 
protected Matrix 
mP
The positive definite matrix parameter; this is S if isMoment is true
and L otherwise. 
protected Set 
variables
An unmodifiable ordered set whose elements are the Variable s bound by this Gaussian. 
protected ListSet 
vars
An ordered set whose elements are the Variable s
bound by this Gaussian. 
protected HashMap 
varsToStarts
A map whose keys are the Variable s bound by this
Gaussian and whose values are Integer s giving
the starting index of the corresponding subvectors of vP
and subblocks of mP . 
protected Matrix 
vP
The vector parameter; this is m if isMoment is true and h otherwise. 
Constructor Summary  
Gaussian(boolean isMoment)
Default constructor. 

Gaussian(boolean isMoment,
int capacity)
Default constructor. 

Gaussian(Gaussian p)
Copy constructor. 

Gaussian(Gaussian p,
Gaussian q)
Separator Gaussian constructor. 

Gaussian(ListSet vars,
double[] vP,
double[][] mP,
boolean isMoment)
Constructor. 

Gaussian(ListSet vars,
Matrix vP,
Matrix mP,
boolean isMoment)
Constructor. 

Gaussian(Set vars,
boolean isMoment)
Creates an uninformative Gaussian density over the supplied set of variables. 
Method Summary  
protected void 
clear()
Clears all variables from this Gaussian. 
Gaussian 
condition(ListSet cvars,
Matrix obs,
boolean inPlace)
Conditions on a subset of the variables in this Gaussian. 
Gaussian 
div(Gaussian p,
boolean inPlace)
Divides two Gaussians (in the canonical parameterization). 
double 
entropy()
Computes the differential entropy H of this Gaussian. 
void 
extend(Set vars)
Extends this Gaussian to include a new set of variables. 
int 
getDimension()
Gets the sum of the dimensions of all variables bound by this Gaussian. 
Matrix 
getEta(ListSet vars)
Gets a subvector of h. 
int[] 
getIndices(ListSet vars)
Gets an array of indices into the parameters that corresponds to the supplied set of variables. 
Matrix 
getLambda(ListSet rowVars,
ListSet colVars)
Gets a submatrix of L. 
Matrix 
getMu(ListSet vars)
Gets a subvector of m. 
Matrix 
getSigma(ListSet rowVars,
ListSet colVars)
Gets a submatrix of S. 
int 
getSize()
Returns the number of variables bound by this Gaussian. 
Set 
getVariables()
Returns an unmodifiable ordered set of the Variable s bound by this Gaussian. 
protected void 
initialize(ListSet vars,
Matrix vP,
Matrix mP)
Initializes this Gaussian using the supplied arguments. 
boolean 
isCanonical()
Returns true if this Gaussian is represented using
the canonical parameterization, i.e., using the vector h and the (positive definite) matrix
L. 
boolean 
isMoment()
Returns true if this Gaussian is represented using
the moment parameterization, i.e., using the mean vector m and the (positive definite)
covariance matrix S. 
double 
kl(Gaussian q)
Computes the relative entropy (KullbackLiebler divergence) from this Gaussian to the supplied Gaussian. 
double 
likelihood(double[] val)
Computes the likelihood of a particular value under this distribution. 
Gaussian 
marginalize(Set vars,
boolean inPlace)
Marginalizes out a subset of the variables in this Gaussian. 
void 
marginalizeOut(Set mvars)
Marginalizes a set of variables out of this Gaussian (in place). 
double 
mutualInformation(Set x,
Set y,
Set z)
Computes the (conditional) mutual information x ;y 
x z ) 
void 
paint(Graphics2D g,
double conf)
Paints a 2D confidence ellipse for the first two dimensions of this Gaussian distribution. 
void 
rename(Variable var,
Variable subst)
Renames a variable in this Gaussian. 
Gaussian 
reparameterize(boolean inPlace)
Reparameterizes this Gaussian; i.e., the parameterization will be switched from the canonical to the moment parameterization, or viceversa. 
Matrix 
sample(int n,
Random r)
Samples from this Gaussian distribution. 
void 
set(Gaussian p)
Sets this Gaussian equal to the supplied Gaussian. 
void 
setDoubling(boolean on)
Controls the memory allocation behavior of this Gaussian. 
void 
setEta(ListSet vars,
Matrix eta)
Sets a subvector of h. 
void 
setLambda(ListSet rowVars,
ListSet colVars,
Matrix lambda)
Sets a submatrix of L. 
void 
setMu(ListSet vars,
Matrix mu)
Sets a subvector of m. 
void 
setSigma(ListSet rowVars,
ListSet colVars,
Matrix sigma)
Sets a submatrix of S. 
Gaussian 
times(Gaussian p,
boolean inPlace)
Multiplies two Gaussians. 
String 
toString()
Creates a simple String representation of this
Gaussian that prints out its parameters using Matlab notation. 
Methods inherited from class java.lang.Object 
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait 
Field Detail 
protected final HashMap varsToStarts
Variable
s bound by this
Gaussian and whose values are Integer
s giving
the starting index of the corresponding subvectors of vP
and subblocks of mP
.
protected ListSet vars
Variable
s
bound by this Gaussian. The iteration order of the set is the
storage order of the parameters.
protected final Set variables
Variable
s bound by this Gaussian. The iteration order
of the set is the storage order of the parameters. This is
merely a wrapper over vars
.
protected boolean isMoment
protected Matrix vP
isMoment
is true
and h otherwise. The length of this vector is
greater than or equal to the sum of the dimensions of the
variables bound by this Gaussian.
protected Matrix mP
isMoment
is true
and L otherwise. This matrix is
always square, and the lengths of its sides are greater than or
equal to the sum of the dimensions of the variables bound by this
Gaussian.
protected boolean doubling
true
, then the capacity (i.e., the actual
dimension of vP
and mP
) of this Gaussian is
doubled when it must be increased to accomodate new variables;
otherwise it is increased only enough to admit the new variables.
Constructor Detail 
public Gaussian(boolean isMoment)
isMoment
 true
if this Gaussian should be
represented in the moment parameterizationpublic Gaussian(boolean isMoment, int capacity)
isMoment
 true
if this Gaussian should be
represented in the moment parameterizationcapacity
 the initial capacity of the parameter matricespublic Gaussian(Gaussian p)
public Gaussian(Set vars, boolean isMoment)
vP
and
mP
are structured so that their blocks are ordered
consistently with the iteration order of vars
.
vars
 a set of Variable
objectsisMoment
 true
if this Gaussian should be
represented in the moment parameterizationpublic Gaussian(Gaussian p, Gaussian q)
p
 a Gaussian densityq
 a Gaussian densitypublic Gaussian(ListSet vars, Matrix vP, Matrix mP, boolean isMoment)
vars
 an ordered set of Variable
objectsvP
 a column vector whose length matches the sum dimensions
of the variables and whose subvectors are ordered
consistently with the order of vars
mP
 a positive definite matrix whose lengths
match the sum dimensions of the variables and whose
blocks are ordered consistently with the order of
vars
isMoment
 if true
, then vP
is
interpreted as m and
mP
is interpreted as S; otherwise,
vP
is interpreted as h and mP
is
interpreted as L
IllegalArgumentException
 if mP
is not square, or
the dimensions of vP
or
mP
do not match the
sum dimension of vars
public Gaussian(ListSet vars, double[] vP, double[][] mP, boolean isMoment)
vars
 an ordered set of Variable
objectsvP
 a column vector whose length matches the sum dimensions
of the variables and whose subvectors are ordered
consistently with the order of vars
mP
 a positive definite matrix whose lengths
match the sum dimensions of the variables and whose
blocks are ordered consistently with the order of
vars
isMoment
 if true
, then vP
is
interpreted as m and
mP
is interpreted as S; otherwise,
vP
is interpreted as h and mP
is
interpreted as L
IllegalArgumentException
 if lambda is not square, or the
dimensions of vP
or
mP
do not match the
sum dimension of vars
Method Detail 
public boolean isMoment()
true
if this Gaussian is represented using
the moment parameterization, i.e., using the mean vector m and the (positive definite)
covariance matrix S.
true
if this Gaussian is represented using
the moment parameterizationpublic boolean isCanonical()
true
if this Gaussian is represented using
the canonical parameterization, i.e., using the vector h and the (positive definite) matrix
L.
true
if this Gaussian is represented using
the canonical parameterizationpublic Gaussian reparameterize(boolean inPlace)
inPlace
 if true
, then this Gaussian is
internally reparameterized; otherwise a fresh
Gaussian is constructed
public void setDoubling(boolean on)
on == true
, then the capacity of the Gaussian
(i.e., the lengths of vP
and the sides of mP
)
is doubled whenever adding a variable to the Gaussian (via
extend(java.util.Set)
) would cause the capacity to be
exceeded; otherwise, the capacity is increased only enough to
admit the new variable. Doubling is off by default; Gaussians
that are frequently extended should turn it on.
public void extend(Set vars)
vP
and blocks of mP
are ordered consistently with the iteration order of
vars
.
vars
 a set of Variable
objectsprotected void initialize(ListSet vars, Matrix vP, Matrix mP)
vars
 an ordered set of Variable
objects.vP
 a column vector whose length matches the sum dimensions
of the variables and whose subvectors are ordered
consistently with the order of vars
;mP
 a positive definite matrix whose lengths
match the sum dimensions of the variables and whose
blocks are ordered consistently with the order
IllegalArgumentException
 if mP
is not square, or
the dimensions of vP
or
mP
do not match the
sum dimension of vars
protected void clear()
public void rename(Variable var, Variable subst)
var
 the original variablesubst
 the variable substituted for the original variable
IllegalArgumentException
 if var
is not in this
Gaussian or var
and
subst
have differing
dimensionpublic Set getVariables()
Variable
s bound by this Gaussian. The iteration order of this
set is the storage order of the parameters.
public int getDimension()
public int getSize()
public int[] getIndices(ListSet vars)
vars
.
vars
 An ordered set of Variable
s; the indices
corresponding to these variables is returned. If this
Gaussian binds only one variable, then null
is interpreted as the singleton containing the only
variable bound by this Gaussian.
vars
public Matrix getEta(ListSet vars)
vars
.
vars
 an ordered set of Variable
s; if this
is null
, then it is like supplying the
result of getVariables()
, except the
underlying parameter vector is returned, not copied
vars == null
IllegalStateException
 if this Gaussian is not currently in
the canonical parameterizationpublic void setEta(ListSet vars, Matrix eta)
eta
are assumed to be ordered consistently with
the order of vars
.
vars
 an ordered set of Variable
s; this can
be null
if this Gaussian binds only one
variableeta
 the new subvector value
IllegalStateException
 if this Gaussian is not currently in
the canonical parameterizationpublic Matrix getLambda(ListSet rowVars, ListSet colVars)
rowVars
 an ordered set of Variable
s; if this
is null
, then it is like supplying the
result of getVariables()
, except the
underlying parameter matrix is returned, not copiedcolVars
 an ordered set of Variable
s; use
null
to indicate that this is the same as
rowVars
Matrix
object; this is a copy
unless vars == null
IllegalStateException
 if this Gaussian is not currently in
the canonical parameterizationpublic void setLambda(ListSet rowVars, ListSet colVars, Matrix lambda)
lambda
must be ordered consistently with the orders
of the index sets. This method permits the setting of diagonal
blocks or off diagonal blocks, but not both simultaneously; if
off diagonal blocks are specified, then their transpose blocks
are also set to maintain the symmetry of
L.
rowVars
 an ordered set of Variable
s; this
can be null
if this Gaussian binds
only one variablecolVars
 an ordered set of Variable
s; use
null
to indicate that this is the same as
rowVars
lambda
 the new submatrix value; this must be symmetric
if colVars
is null
double
array
IllegalStateException
 if this Gaussian is not currently in
the canonical parameterization
IllegalArgumentException
 if colVars
is
null
and lambda
is not symmetricpublic Matrix getMu(ListSet vars)
vars
.
vars
 an ordered set of Variable
s; if this
is null
, then it is like supplying the
result of getVariables()
, except the
underlying parameter vector is returned, not copied
vars == null
IllegalStateException
 if this Gaussian is not currently in
the moment parameterizationpublic void setMu(ListSet vars, Matrix mu)
mu
are assumed to be ordered consistently with
the order of vars
.
vars
 an ordered set of Variable
s; this can
be null
if this Gaussian binds only one
variablemu
 the new subvector value
IllegalStateException
 if this Gaussian is not currently in
the moment parameterizationpublic Matrix getSigma(ListSet rowVars, ListSet colVars)
rowVars
 an ordered set of Variable
s; if this
is null
, then it is like supplying the
result of getVariables()
, except the
underlying parameter matrix is returned, not copiedcolVars
 an ordered set of Variable
s; use
null
to indicate that this is the same as
rowVars
Matrix
object; this is a copy
unless vars == null
IllegalStateException
 if this Gaussian is not currently in
the moment parameterizationpublic void setSigma(ListSet rowVars, ListSet colVars, Matrix sigma)
sigma
must be ordered consistently with the orders
of the index sets. This method permits the setting of diagonal
blocks or off diagonal blocks, but not both simultaneously; if
off diagonal blocks are specified, then their transpose blocks
are also set to maintain the symmetry of
S.
rowVars
 an ordered set of Variable
s; this
can be null
if this Gaussian binds
only one variablecolVars
 an ordered set of Variable
s; use
null
to indicate that this is the same as
rowVars
sigma
 the new submatrix value; this must be symmetric
if colVars
is null
double
array
IllegalStateException
 if this Gaussian is not currently in
the moment parameterization
IllegalArgumentException
 if colVars
is
null
and sigma
is not symmetricpublic void marginalizeOut(Set mvars)
mvars
 a set of Variable
s to marginalize out;
any of these that are not bound by the Gaussian are ignoredpublic Gaussian marginalize(Set vars, boolean inPlace)
inPlace
 if true
, then the Gaussian is
marginalized in place.
mvars
marginalized out
IllegalArgumentException
 if this Gaussian does not contain
the variables in rvars
public Gaussian condition(ListSet cvars, Matrix obs, boolean inPlace)
cvars
 an ordered set of the Variable
s
of this Gaussian being conditioned onobs
 a vector (whose length and order is consistent with
cvars
) representing the observationinPlace
 if true
, the conditioning is done inplace.
cvars
conditioned on
IllegalArgumentException
 if this Gaussian does not contain
the variables in rvars
public void set(Gaussian p)
public Gaussian times(Gaussian p, boolean inPlace)
inPlace
 if true
, then p
is
multiplied into this
and this
is returned.
this
and p
IllegalStateException
 if this Gaussian or the supplied
Gaussian are in the moment
parameterizationpublic Gaussian div(Gaussian p, boolean inPlace)
inPlace
 if true
, then p
is
divided into this
and this
is returned.
this
divided by p
IllegalArgumentException
 if p
binds variables
not bound by this Gaussian
IllegalStateException
 if this Gaussian or the supplied
Gaussian are in the moment
parameterizationpublic double entropy()
public double kl(Gaussian q)
this
 q
) (in nats, i.e.,
natural logarithmic units).
IllegalArgumentException
 if this and the supplied
Gaussian do not cover the same set of variablespublic double mutualInformation(Set x, Set y, Set z)
x
;y

x
z
)
x
 a set of Variable
s in this Gaussiany
 a set of Variable
s in this Gaussianz
 a set of Variable
s in this Gaussian
x
;y

x
z
)IllegalArgumentException
 if x
, y
,
or z
contain variables
not bound by this Gaussianpublic Matrix sample(int n, Random r)
n
 the number of samples to drawr
 the source of random bits
n
columns, each of which
is a sample from this distributionpublic double likelihood(double[] val)
val
 the value
val
IllegalArgumentException
 if the length of val
does not equal the dimension of
this distributionpublic String toString()
String
representation of this
Gaussian that prints out its parameters using Matlab notation.
toString
in class Object
public void paint(Graphics2D g, double conf)


PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 