cc.mallet.grmm.types
Class TableFactor

java.lang.Object
  extended by cc.mallet.grmm.types.AbstractTableFactor
      extended by cc.mallet.grmm.types.TableFactor
All Implemented Interfaces:
DiscreteFactor, Factor, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
BoltzmannPairFactor, BoltzmannUnaryFactor

public class TableFactor
extends AbstractTableFactor

Created: Jan 4, 2006

Version:
$Id: TableFactor.java,v 1.1 2007/10/22 21:37:44 mccallum Exp $
Author:
Serialized Form

Field Summary
 
Fields inherited from class cc.mallet.grmm.types.AbstractTableFactor
probs
 
Constructor Summary
TableFactor()
           
TableFactor(AbstractTableFactor in)
           
TableFactor(AbstractTableFactor ptl, double[] probs)
           
TableFactor(BidirectionalIntObjectMap varMap)
           
TableFactor(java.util.Collection allVars)
           
TableFactor(Variable var)
           
TableFactor(Variable[] allVars)
           
TableFactor(Variable[] allVars, double[] probs)
           
TableFactor(Variable[] allVars, Matrix probsIn)
           
TableFactor(Variable var, double[] values)
           
TableFactor(VarSet allVars, double[] probs)
           
TableFactor(VarSet allVars, Matrix probsIn)
           
 
Method Summary
protected  AbstractTableFactor createBlankSubset(Variable[] vars)
           
protected  void divideByInternal(DiscreteFactor ptl)
           
 Factor duplicate()
           
 void exponentiate(double power)
           
 Matrix getLogValueMatrix()
           
 Matrix getValueMatrix()
           
 double logValue(Assignment assn)
           
 double logValue(AssignmentIterator it)
           
 double logValue(int loc)
           
static TableFactor makeFromLogValues(VarSet domain, double[] vals)
           
protected  Factor marginalizeInternal(AbstractTableFactor result)
           
static AbstractTableFactor multiplyAll(java.util.Collection phis)
          Returns the product of a collection of multinomial potentials.
static DiscreteFactor multiplyAll(Factor[] phis)
           
protected  void multiplyByInternal(DiscreteFactor ptl)
           
 Factor normalize()
          Multiplies every entry in the potential by a constant such that all the entries sum to 1.
protected  void plusEqualsAtLocation(int loc, double v)
           
protected  void plusEqualsInternal(DiscreteFactor ptl)
           
protected  double rawValue(Assignment assn)
           
protected  double rawValue(int singleIdx)
           
 AbstractTableFactor recenter()
          Multiplies this factor by the constant 1/max().
 void setLogValue(Assignment assn, double logValue)
          Use of this method is discouraged.
 void setLogValue(AssignmentIterator assnIt, double logValue)
          Use of this method is discouraged.
 void setLogValues(double[] vals)
           
 void setValue(AssignmentIterator assnIt, double value)
          Use of this method is discouraged.
 void setValues(double[] vals)
           
protected  Factor slice_general(Variable[] vars, Assignment observed)
           
protected  Factor slice_onevar(Variable var, Assignment observed)
          Creates a new potential from another by restricting it to a given assignment.
protected  Factor slice_twovar(Variable v1, Variable v2, Assignment observed)
           
 double sum()
          Returns the sum of this potential over all cases.
 void timesEquals(double v)
          Multiplies a constant by all values in the table.
 double value(Assignment assn)
          Returns the value of the local function for a given assignment.
 double value(AssignmentIterator assn)
          Returns the probability of an assignment to these variables.
 double value(int loc)
           
 double valueAtLocation(int idx)
           
 
Methods inherited from class cc.mallet.grmm.types.AbstractTableFactor
almostEquals, almostEquals, argmax, assignmentIterator, asTable, clone, containsVar, divideBy, divideBy, dumpToString, ensureOperandCompatible, entropy, extractMax, extractMax, extractMax, findVariable, getNumVars, getValues, getVariable, indexAtLocation, isNaN, logsum, makeIdentityFactor, marginalize, marginalize, marginalize, marginalizeOut, marginalizeOut, multiply, multiplyBy, numLocations, plusEquals, plusEquals, prettyOutputString, printSizes, printValues, sample, sampleLocation, setRawValue, setRawValue, setRawValue, setValues, singleIndex, slice, toLogValueArray, toString, toValueArray, varSet
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TableFactor

public TableFactor(Variable var)

TableFactor

public TableFactor(Variable var,
                   double[] values)

TableFactor

public TableFactor()

TableFactor

public TableFactor(BidirectionalIntObjectMap varMap)

TableFactor

public TableFactor(Variable[] allVars)

TableFactor

public TableFactor(java.util.Collection allVars)

TableFactor

public TableFactor(Variable[] allVars,
                   double[] probs)

TableFactor

public TableFactor(VarSet allVars,
                   double[] probs)

TableFactor

public TableFactor(Variable[] allVars,
                   Matrix probsIn)

TableFactor

public TableFactor(AbstractTableFactor in)

TableFactor

public TableFactor(VarSet allVars,
                   Matrix probsIn)

TableFactor

public TableFactor(AbstractTableFactor ptl,
                   double[] probs)
Method Detail

multiplyAll

public static DiscreteFactor multiplyAll(Factor[] phis)

multiplyAll

public static AbstractTableFactor multiplyAll(java.util.Collection phis)
Returns the product of a collection of multinomial potentials.


duplicate

public Factor duplicate()
Specified by:
duplicate in interface Factor
Specified by:
duplicate in class AbstractTableFactor

createBlankSubset

protected AbstractTableFactor createBlankSubset(Variable[] vars)
Specified by:
createBlankSubset in class AbstractTableFactor

normalize

public Factor normalize()
Multiplies every entry in the potential by a constant such that all the entries sum to 1.

Specified by:
normalize in interface Factor
Specified by:
normalize in class AbstractTableFactor

sum

public double sum()
Description copied from interface: Factor
Returns the sum of this potential over all cases.

Specified by:
sum in interface Factor
Specified by:
sum in class AbstractTableFactor

logValue

public double logValue(AssignmentIterator it)

logValue

public double logValue(Assignment assn)

logValue

public double logValue(int loc)

value

public double value(Assignment assn)
Description copied from interface: Factor
Returns the value of the local function for a given assignment. All variables in the potential must be included, but it's okay if the assignment uses variables not in the potential.

Specified by:
value in interface Factor
Specified by:
value in class AbstractTableFactor

value

public double value(int loc)

value

public double value(AssignmentIterator assn)
Description copied from interface: Factor
Returns the probability of an assignment to these variables. The assignment used is the curret assignment from the given AssignmentIterator.

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.


marginalizeInternal

protected Factor marginalizeInternal(AbstractTableFactor result)
Specified by:
marginalizeInternal in class AbstractTableFactor

multiplyByInternal

protected void multiplyByInternal(DiscreteFactor ptl)
Specified by:
multiplyByInternal in class AbstractTableFactor

divideByInternal

protected void divideByInternal(DiscreteFactor ptl)
Specified by:
divideByInternal in class AbstractTableFactor

plusEqualsInternal

protected void plusEqualsInternal(DiscreteFactor ptl)
Specified by:
plusEqualsInternal in class AbstractTableFactor

rawValue

protected double rawValue(Assignment assn)

rawValue

protected double rawValue(int singleIdx)
Specified by:
rawValue in class AbstractTableFactor

exponentiate

public void exponentiate(double power)

setLogValue

public void setLogValue(Assignment assn,
                        double logValue)
Description copied from class: AbstractTableFactor
Use of this method is discouraged.

Specified by:
setLogValue in class AbstractTableFactor

setLogValue

public void setLogValue(AssignmentIterator assnIt,
                        double logValue)
Description copied from class: AbstractTableFactor
Use of this method is discouraged.

Specified by:
setLogValue in class AbstractTableFactor

setValue

public void setValue(AssignmentIterator assnIt,
                     double value)
Description copied from class: AbstractTableFactor
Use of this method is discouraged.

Specified by:
setValue in class AbstractTableFactor

setLogValues

public void setLogValues(double[] vals)
Specified by:
setLogValues in class AbstractTableFactor

setValues

public void setValues(double[] vals)
Specified by:
setValues in class AbstractTableFactor

timesEquals

public void timesEquals(double v)
Description copied from class: AbstractTableFactor
Multiplies a constant by all values in the table.

Specified by:
timesEquals in class AbstractTableFactor

plusEqualsAtLocation

protected void plusEqualsAtLocation(int loc,
                                    double v)
Specified by:
plusEqualsAtLocation in class AbstractTableFactor

getValueMatrix

public Matrix getValueMatrix()
Specified by:
getValueMatrix in class AbstractTableFactor

getLogValueMatrix

public Matrix getLogValueMatrix()
Specified by:
getLogValueMatrix in class AbstractTableFactor

valueAtLocation

public double valueAtLocation(int idx)

slice_onevar

protected Factor slice_onevar(Variable var,
                              Assignment observed)
Creates a new potential from another by restricting it to a given assignment.

Specified by:
slice_onevar in class AbstractTableFactor
Parameters:
var - Variable the new potential will be over
observed - Evidence to restrict to. Must give values for all variables in ptl.varSet() except for var.
Returns:
A DiscretePotential over var

slice_twovar

protected Factor slice_twovar(Variable v1,
                              Variable v2,
                              Assignment observed)
Specified by:
slice_twovar in class AbstractTableFactor

slice_general

protected Factor slice_general(Variable[] vars,
                               Assignment observed)
Specified by:
slice_general in class AbstractTableFactor

makeFromLogValues

public static TableFactor makeFromLogValues(VarSet domain,
                                            double[] vals)

recenter

public AbstractTableFactor recenter()
Description copied from class: AbstractTableFactor
Multiplies this factor by the constant 1/max(). This ensures that the maximum value of this factor is 1.0

Specified by:
recenter in class AbstractTableFactor