

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object cc.mallet.grmm.types.FactorGraph
public class FactorGraph
Class for undirected graphical models. Created: Mon Sep 15 15:18:30 2003
Constructor Summary  

FactorGraph()


FactorGraph(java.util.Collection factors)


FactorGraph(Factor[] factors)


FactorGraph(int capacity)
Create a model with the given capacity (i.e., capacityin terms of number of variable nodes). 

FactorGraph(Variable[] vars)
Create a model with the variables given. 
Method Summary  

void 
addFactor(Factor factor)
Adds a factor to the model. 
void 
addFactor(Variable var1,
Variable var2,
double[] probs)

protected void 
afterFactorAdd(Factor factor)
Performs operations on a factor after it has been added to the model, such as caching. 
java.util.Collection 
allFactorsContaining(java.util.Collection vars)
Returns a collection of all factors that involve only the given variables. 
java.util.List 
allFactorsContaining(Variable var)

java.util.List 
allFactorsOf(java.util.Collection c)
Returns a list of all factors in the graph whose domain is exactly the specified Collection of Variables. 
java.util.List 
allFactorsOf(Variable var)
Returns a list of all factors in the graph whose domain is exactly the specified var. 
boolean 
almostEquals(Factor p)
Returns whether this is almost equal to another potential. 
boolean 
almostEquals(Factor p,
double epsilon)

int 
argmax()
Returns the assignment that maximizes this potential. 
AssignmentIterator 
assignmentIterator()
Returns an iterator over all assignments to all variables of this graphical model. 
AbstractTableFactor 
asTable()

protected void 
beforeFactorAdd(Factor factor)
Performs checking of a factor before it is added to the model. 
void 
clear()
Removes all potentias from this model. 
boolean 
containsVar(Variable v1)
Returns whether this variable is part of the model. 
void 
divideBy(Factor pot)
Computes this /= pot 
void 
dump()
Dumps all the variables and factors of the model to System.out in humanreadable text. 
void 
dump(java.io.PrintWriter out)

java.lang.String 
dumpToString()

Factor 
duplicate()
Returns a copy of this model. 
double 
entropy()
Returns the expected log factor value, i.e., sum_x factor.value(x) * Math.log (factor.value (x)) where the summation is taken over all passible assignments. 
void 
exponentiate(double power)

Factor 
extractMax(java.util.Collection vars)
Returns a potential phi over the given variables obtained by taking phi (x) = max_[all v that contain x] this.prob (x) 
Factor 
extractMax(Variable var)
Returns a potential phi over the given variables obtained by taking phi (x) = max_[all v that contain x] this.prob (x) 
Factor 
extractMax(Variable[] vars)
Returns a potential phi over the given variables obtained by taking phi (x) = max_[all v that contain x] this.prob (x) 
Factor 
factorOf(java.util.Collection c)
Searches the graphical model for a factor over the given collection of variables. 
Factor 
factorOf(Variable var)
Returns the factor for a given node. 
Factor 
factorOf(Variable var1,
Variable var2)
Returns the factor defined over a given pair of variables. 
Factor 
factorOf(VarSet varSet)
Returns the factor in this graph, if any, whose domain is a given clique. 
double 
factorProduct(Assignment assn)
Returns the unnormalized probability for an assignment to the model. 
java.util.Collection 
factors()
Returns collection that contains factors in this model. 
java.util.Iterator 
factorsIterator()
Returns an iterator of all the factors in the graph. 
Variable 
findVariable(java.lang.String name)
Searches this model for a variable with a given name. 
Variable 
get(int index)
Returns a variable from this model with a given index. 
VarSet 
getAdjacentVertices(Variable var)
Returns all variables that are adjacent to a given variable in this graphthat is, the set of all variables that share a factor with this one. 
int 
getDegree(Variable var)
Returns the degree of a given variable in this factor graph, that is, the number of factors in which the variable is an argument. 
Factor 
getFactor(int i)

int 
getIndex(Factor factor)

int 
getIndex(Variable var)
Returns a unique numeric index for a variable in this model. 
java.lang.Object 
getInferenceCache(java.lang.Class inferencer)
Caches some information about this graph that is specific to a given type of inferencer (e.g., a junction tree). 
Variable 
getVariable(int i)

boolean 
isAdjacent(Variable v1,
Variable v2)
Returns whether two variables are adjacent in the model's graph. 
boolean 
isNaN()

void 
logify()

double 
logValue(Assignment assn)

double 
logValue(AssignmentIterator it)

double 
logValue(int loc)

Factor 
marginalize(java.util.Collection vars)
Returns the marginal of this distribution over the given variables. 
Factor 
marginalize(Variable var)
Returns the marginal of this distribution over one variable. 
Factor 
marginalize(Variable[] vars)
Returns the marginal of this distribution over the given variables. 
Factor 
marginalizeOut(Variable var)
Returns the marginal distribution attained by summing out the given variable. 
Factor 
marginalizeOut(VarSet varset)
Returns the marginal distribution attained by summing out the given set of variables. 
Factor 
multiply(Factor dist)
Returns the elementwise product of this factor with another. 
void 
multiplyBy(Factor pot)
Does this *= pot. 
Factor 
normalize()
Multiplies this potential by a constant such that it sums to 1. 
int 
numVariables()
Returns the number of variable nodes in the graph. 
java.lang.String 
prettyOutputString()

void 
printAsDot(java.io.PrintWriter out)

void 
printAsDot(java.io.PrintWriter out,
Assignment assn)

void 
remove(java.util.Collection vars)
Removes a Collection of variables from this model, along with all of its factors. 
void 
remove(Variable var)
Removes a variable from this model, along with all of its factors. 
Assignment 
sample(Randoms r)
Return an assignment sampled from this factor, interpreting it as an unnormalized probability distribution. 
Assignment 
sampleContinuousVars(Randoms r)
Samples the continuous variables in this factor graph. 
void 
setInferenceCache(java.lang.Class inferencer,
java.lang.Object info)
Caches some information about this graph that is specific to a given type of inferencer (e.g., a junction tree). 
Factor 
slice(Assignment assn)

Factor 
slice(Assignment assn,
java.util.Map toSlicedMap)

double 
sum()
Returns the sum of this potential over all cases. 
java.lang.String 
toString()

double 
value(Assignment assn)
FACTOR IMPLEMENTATION 
double 
value(AssignmentIterator it)
Returns the probability of an assignment to these variables. 
java.util.Iterator 
variablesIterator()

java.util.Set 
variablesSet()

VarSet 
varSet()
Returns set of variables in this potential. 
java.util.Iterator 
varSetIterator()
Returns an iterator of all the VarSets in the graph over which factors are defined. 
Methods inherited from class java.lang.Object 

clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait 
Constructor Detail 

public FactorGraph()
public FactorGraph(Variable[] vars)
public FactorGraph(Factor[] factors)
public FactorGraph(java.util.Collection factors)
public FactorGraph(int capacity)
Method Detail 

public int numVariables()
public java.util.Set variablesSet()
public java.util.Iterator variablesIterator()
public VarSet getAdjacentVertices(Variable var)
public java.util.Collection factors()
public java.util.Iterator factorsIterator()
public AssignmentIterator assignmentIterator()
assignmentIterator
in interface Factor
Assignment
public java.util.Iterator varSetIterator()
public int getIndex(Variable var)
getIndex and get are inverses. That is, if idx == getIndex (var), then get(idx) will return var.
var
 A variable contained in this graphical model
get(int)
public int getIndex(Factor factor)
public Variable get(int index)
getIndex and get are inverses. That is, if idx == getIndex (var), then get(idx) will return var.
getIndex(Variable)
public Factor getFactor(int i)
public int getDegree(Variable var)
public Variable findVariable(java.lang.String name)
name
 Name to find.
public Factor factorOf(VarSet varSet)
addFactor(Factor)
,
factorOf(Variable,Variable)
,
factorOf(Variable)
public Factor factorOf(Variable var1, Variable var2)
This method is equivalent to calling factorOf(cc.mallet.grmm.types.VarSet)
with a VarSet that contains only v1 and v2.
var1
 One variable of the pair.var2
 The other variable of the pair.
public java.util.Collection allFactorsContaining(java.util.Collection vars)
public java.util.List allFactorsContaining(Variable var)
public java.util.List allFactorsOf(Variable var)
public java.util.List allFactorsOf(java.util.Collection c)
public void remove(Variable var)
public void remove(java.util.Collection vars)
public boolean isAdjacent(Variable v1, Variable v2)
v1
 A variable in this modelv2
 Another variable in this model
public boolean containsVar(Variable v1)
containsVar
in interface Factor
v1
 Any Variable object
public void addFactor(Variable var1, Variable var2, double[] probs)
public void addFactor(Factor factor)
If a factor has already been added for the variables in the given clique, the effects of this method are (currently) undefined.
All convenience methods for adding factors eventually call through to this one, so this is the method for subclasses to override if they wish to perform additional actions when a factor is added to the graph.
factor
 A factor over the variables in clique.protected void beforeFactorAdd(Factor factor)
factor
 Factor that is about to be addedprotected void afterFactorAdd(Factor factor)
factor
 Factor that has just been addedpublic void clear()
public double factorProduct(Assignment assn)
\prod_C \phi_C (assn)where C ranges over all cliques for which factors have been defined.
assn
 An assignment for all variables in this model.
public Factor factorOf(Variable var)
This method is equivalent to calling factorOf(cc.mallet.grmm.types.VarSet)
with a clique object that contains only v.
var
 which the factor is over.
addFactor(Factor)
). Returns null if
no such factor exists.
java.lang.RuntimeException
 If the model contains more than one factor over the given variable. Use allFactorsOf in this case.public Factor factorOf(java.util.Collection c)
java.lang.RuntimeException
 If multiple factors exist over the given collection.allFactorsOf(java.util.Collection)
,
addFactor(Factor)
,
factorOf(VarSet)
public Factor duplicate()
duplicate
in interface Factor
public void dump()
public void dump(java.io.PrintWriter out)
public java.lang.String dumpToString()
dumpToString
in interface Factor
public double value(Assignment assn)
value
in interface Factor
public double value(AssignmentIterator it)
Factor
This can be used to do things like
DiscretePotential phi = createMyPtl (); for (AssignmentIterator it = phi.assignmentIterator; it.hasNext(); it.advance()) { double val = ptl.phi (it); // do something with val }
This is equivalent to creating an assignment object explicitly using (Assignment) it.next(), but can be much faster.
value
in interface Factor
public Factor normalize()
Factor
normalize
in interface Factor
public Factor marginalize(Variable[] vars)
Factor
marginalize
in interface Factor
public Factor marginalize(java.util.Collection vars)
Factor
marginalize
in interface Factor
public Factor marginalize(Variable var)
Factor
marginalize
in interface Factor
public Factor marginalizeOut(Variable var)
Factor
marginalizeOut
in interface Factor
public Factor marginalizeOut(VarSet varset)
Factor
marginalizeOut
in interface Factor
public Factor extractMax(java.util.Collection vars)
Factor
extractMax
in interface Factor
public Factor extractMax(Variable var)
Factor
extractMax
in interface Factor
public Factor extractMax(Variable[] vars)
Factor
extractMax
in interface Factor
public int argmax()
Factor
argmax
in interface Factor
public Assignment sample(Randoms r)
Factor
sample
in interface Factor
public Assignment sampleContinuousVars(Randoms r)
public double sum()
Factor
sum
in interface Factor
public double entropy()
Factor
entropy
in interface Factor
public Factor multiply(Factor dist)
Factor
multiply
in interface Factor
public void multiplyBy(Factor pot)
Factor
If both potentials are currently in log space, then does addition instead.
multiplyBy
in interface Factor
public void exponentiate(double power)
exponentiate
in interface Factor
public void divideBy(Factor pot)
Factor
If both potentials are currently in log space, then does subtraction instead.
divideBy
in interface Factor
public VarSet varSet()
Factor
varSet
in interface Factor
public boolean almostEquals(Factor p)
Factor
almostEquals
in interface Factor
public boolean almostEquals(Factor p, double epsilon)
almostEquals
in interface Factor
public boolean isNaN()
isNaN
in interface Factor
public double logValue(AssignmentIterator it)
logValue
in interface Factor
public double logValue(int loc)
logValue
in interface Factor
public Variable getVariable(int i)
getVariable
in interface Factor
public Factor slice(Assignment assn)
slice
in interface Factor
public Factor slice(Assignment assn, java.util.Map toSlicedMap)
public void setInferenceCache(java.lang.Class inferencer, java.lang.Object info)
inferencer
 Class of inferencer that can use this
informationinfo
 The information to cache.getInferenceCache(java.lang.Class)
public java.lang.Object getInferenceCache(java.lang.Class inferencer)
inferencer
 Class of inferencer which wants the information
setInferenceCache(java.lang.Class, java.lang.Object)
public void logify()
public double logValue(Assignment assn)
logValue
in interface Factor
public AbstractTableFactor asTable()
asTable
in interface Factor
public java.lang.String prettyOutputString()
prettyOutputString
in interface Factor
public java.lang.String toString()
toString
in class java.lang.Object
public void printAsDot(java.io.PrintWriter out)
public void printAsDot(java.io.PrintWriter out, Assignment assn)


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