|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javaslam.tjt.JunctionTree
A junction tree for a Gaussian graphical model. A junction tree over a set of potentials is a graph whose nodes (called clusters) are sets of variables and that has three properties:
This implementation is designed to efficiently support incremental operations such as adding new variables, multiplying in new potentials, and marginalizing out variables; at all times, the junction tree remains valid and consistent so that cluster marginals are accessible in constant time.
Nested Class Summary | |
class |
JunctionTree.Cluster
A cluster of a junction tree. |
protected class |
JunctionTree.JTEdge
A (directed) edge from one cluster to another in a junction tree. |
Field Summary | |
protected ListSet |
clusters
The Cluster s in this junction tree. |
protected double |
significance
A threshold used in adaptive message passing. |
protected Set |
updated
The set of clusters that have been updated with new evidence but have not yet distributed their evidence (due to lazy or adaptive message passing). |
protected ListSet |
variables
The Variable s present in this junction tree. |
protected Map |
varToClusters
Maps each Variable to the Set of Cluster s containing it. |
Constructor Summary | |
JunctionTree()
Default constructor. |
Method Summary | |
protected void |
add(Variable var)
Adds a variable to this junction tree. |
protected JunctionTree.Cluster |
bestCover(Set vars)
Returns the cluster whose intersection with the supplied set of variables is largest and whose size is the smallest. |
protected JunctionTree.Cluster |
bestCoverToExtend(Set vars)
Returns the cluster that, if extend ed with the
variables in vars , would cause the fewest number of
cluster enlarge ments. |
void |
checkValid()
Tests to see if the junction tree is valid. |
boolean |
consistent()
Tests to see if the junction tree is consistent. |
boolean |
contains(Variable var)
Returns true if this junction tree contains the
supplied variable. |
protected JunctionTree.Cluster |
createCover(Set vars)
Updates this junction tree so that it has a cluster containing the supplied set of variables, while preserving validity and consistency. |
protected void |
enlarge(JunctionTree.Cluster c,
Variable var)
Extends the supplied cluster so that it contains the supplied variable without preserving consistency or the running-intersection property. |
protected void |
extend(JunctionTree.Cluster cluster,
Variable var)
Minimally alters the structure and parameterization of the junction tree so that cluster covers
var and validity and consistency are preserved. |
Set |
getClusters()
Returns a Set s of the JunctionTree.Cluster s of this
junction tree. |
Set |
getClustersWith(Variable var)
Returns an unmodifiable set of Cluster s
containing the supplied variable. |
protected JunctionTree.Cluster |
getCover(Set vars)
Returns the smallest cluster containing the supplied variables, or null if there is no such cluster. |
Gaussian |
getMarginal(Set vars,
boolean force)
Extracts the marginal from the junction tree. |
Map |
getMarginals(Collection vars)
Extracts a set of unary marginals from the junction tree without inverting any cluster potential more than once. |
Set |
getVariables()
Gets an unmodifiable set of the Variable s in
this junction tree. |
protected void |
link(JunctionTree.Cluster c1,
JunctionTree.Cluster c2)
Adds a new pair of edges between the supplied clusters. |
void |
marginalizeOut(Variable var)
Marginalizes a variable out of this junction tree. |
protected JunctionTree.Cluster |
merge(JunctionTree.JTEdge e)
Merges the two clusters that are incident to the supplied edge. |
protected JunctionTree.Cluster |
mergeClustersWith(Variable var)
Merges all clusters containing a particular variable. |
protected JunctionTree.Cluster |
newLeaf(JunctionTree.Cluster c)
Creates an empty cluster and attaches it as a leaf off of the supplied cluster. |
int[] |
parents()
Returns a directed representation of the junction tree. |
void |
passFlows()
Restores consistency; all clusters into new potentials have been multiplied that have not yet distributed their evidence do so. |
protected void |
reduce(JunctionTree.Cluster c,
Variable var)
Reduces the supplied cluster so that it no longer contains the supplied variable. |
protected void |
remove(JunctionTree.Cluster c)
Removes a cluster from this junction tree. |
protected void |
remove(Variable var)
Removes a variable from this junction tree. |
void |
rename(Variable var,
Variable subst)
Renames a variable in this junction tree. |
void |
setSignificance(double s)
Sets a threshold used in adaptive message passing. |
JunctionTree.Cluster |
times(Gaussian p)
Multiplies a new potential into the junction tree and restores validity (but not consistency). |
void |
times(Gaussian p,
JunctionTree.Cluster cluster)
Multiplies a new potential into a particular cluster of this junction tree and restores validity (but not consistency). |
String |
toString()
Returns a String representation of this junction tree. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected ListSet variables
Variable
s present in this junction tree.
This set's iterator is consistent with the order in which the
variables were added to the junction tree.
protected ListSet clusters
Cluster
s in this junction tree.
protected Map varToClusters
Variable
to the Set
of Cluster
s containing it. Variables that are not
currently in the junction tree may still be in this map, but they
will map to empty sets.
protected Set updated
protected double significance
significance
is non-negative, then when distributing
evidence from a cluster, messages are only propagated while the
differential relative entropy (or kl
divergence) from a separator potential to its new value (in
nats) after the message is passed is larger than
significance
.
JunctionTree.Cluster.distributeEvidence(JunctionTree.Cluster,double)
Constructor Detail |
public JunctionTree()
significance
is initialized to
-1.0
so that all messages will be passed.
Method Detail |
public void setSignificance(double s)
s
is non-negative, then when distributing evidence
from a cluster, messages are only propagated while the
differential relative entropy (or kl
divergence) from a separator potential to its
new value (in nats) after the message is passed is larger than
s
.
s
- the new threshold valueJunctionTree.Cluster.distributeEvidence(JunctionTree.Cluster,double)
public boolean contains(Variable var)
true
if this junction tree contains the
supplied variable.
public Set getVariables()
Variable
s in
this junction tree. The iteration order of this set is the order
in which the variables were added to the juntion tree.
public Set getClusters()
Set
s of the JunctionTree.Cluster
s of this
junction tree.
Set
s of the JunctionTree.Cluster
s
of this junction tree.protected void remove(Variable var)
var
- the variable to be removed
IllegalArgumentException
- if var
is present in any
cluster of the junction treeprotected void add(Variable var)
var
- the variable to be addedpublic void rename(Variable var, Variable subst)
var
- the original variablesubst
- the variable substituted for the original variable
IllegalArgumentException
- if var
and
subst
have differing dimensionspublic Set getClustersWith(Variable var)
Cluster
s
containing the supplied variable.
Cluster
s of this junction tree
that contain var
or null
if
var
is not in the junction treeprotected JunctionTree.Cluster getCover(Set vars)
null
if there is no such cluster.
vars
- a set of Variable
s
vars
or
null
if there is no such clusterpublic void times(Gaussian p, JunctionTree.Cluster cluster)
p
- the potential to be multiplied incluster
- the cluster into which it should be multipliedpublic JunctionTree.Cluster times(Gaussian p)
p
- the potential to be multiplied in
p
was multipliedprotected void enlarge(JunctionTree.Cluster c, Variable var)
It is part of the contract of this class that whenever a variable is added to a cluster, this method must be invoked.
var
- the variable to be added to the clusterextend(JunctionTree.Cluster,Variable)
protected void reduce(JunctionTree.Cluster c, Variable var)
c
is a leaf of the subtree induced by
var
.
It is part of the contract of this class that whenever a
variable is removed from a cluster, this method must be invoked;
However, this method is not invoked if a cluster is removed from
the junction tree entirely; in that case, remove
is called
instead.
var
- the variable to be added to the clusterprotected void remove(JunctionTree.Cluster c)
c
is not connected to any other clusters.
It is part of the contract of this class that this method is invoked whenever a cluster is removed from the junction tree.
c
- the cluster to be removed
IllegalArgumentException
- if c
is connected
to any other clusters of the
junction treeprotected JunctionTree.Cluster newLeaf(JunctionTree.Cluster c)
It is part of the contract of this class that this method is invoked whenever a new cluster is added to the junction tree.
c
- the cluster to which the new cluster will be attached as
a leaf; this may be null
if the junction tree
currently has no clusters
IllegalArgumentException
- if c == null
but this junction tree is not emptyprotected void extend(JunctionTree.Cluster cluster, Variable var)
Minimally alters the structure and parameterization of the
junction tree so that cluster
covers
var
and validity and consistency are preserved.
Algorithm: In order to restore the running intersection
property, the closest cluster C containing
var
is found, and var
is added to all
clusters (and separators) on the path to C. Consistency
is restored by passing flows backwards along this path.
This operation can result in non-maximal clusters; these are
subsequently detected by traversing the path and removed by
cluster merging.
cluster
- a cluster of the junction tree to be extendedvar
- the variable to be added to the clusterprotected JunctionTree.Cluster bestCover(Set vars)
vars
- a Set
of Variable
s
vars
is
largest and whose size is the smallestprotected JunctionTree.Cluster bestCoverToExtend(Set vars)
extend
ed with the
variables in vars
, would cause the fewest number of
cluster enlarge
ments. This differs from the result of bestCover(Set)
because it takes into account the cost of
restoring the running intersection property. (Note that there
may be a better cluster to extend---in that its extension will
increase the width of the junction tree by a smaller amount---but
this criterion is a fairly good and cheap heuristic.)
vars
- a Set
of Variable
s
extend
with the
variables in vars
protected JunctionTree.Cluster createCover(Set vars)
bestCoverToExtend
is found and then is extend
ed to
cover each variable in vars
.
vars
- the set of Variable
s that must be covered
vars
protected JunctionTree.Cluster merge(JunctionTree.JTEdge e)
e
- the edge whose incident clusters are to be merged
e.from
)protected JunctionTree.Cluster mergeClustersWith(Variable var)
var
- the variable whose cover clusters are to be merged
public void marginalizeOut(Variable var)
var
- the variable to be marginalized outpublic void passFlows()
public Gaussian getMarginal(Set vars, boolean force)
passFlows()
to ensure the junction tree is
consistent.
vars
- the set of Variable
s whose marginal
is to be computedforce
- if true
, then the junction tree is
restructured if necessary to compute the marginal;
otherwise, null
is returned if there
is no cover for vars
in this junction tree.
vars
(in the
canonical parameterization), or null
if
force
is false
and
vars
do not reside together in a cluster of
the junction treepublic Map getMarginals(Collection vars)
passFlows()
to ensure the junction tree is
consistent.
vars
- a collection of Variable
s, or
null
to indicate all variables in this
junction tree
vars
and whose values are the corresponding
Gaussian
marginals (in the moment parameterization)public String toString()
toString
in class Object
public void checkValid()
InternalError
- if this junction tree is invalidpublic boolean consistent()
public int[] parents()
getClusters()
. The cluster
whose parent index is 0
is the root.
This function is provided to facilitate the plotting of junction trees in Matlab.
getClusters()
protected void link(JunctionTree.Cluster c1, JunctionTree.Cluster c2)
c1
- a clusterc2
- another cluster
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |