cc.mallet.grmm.types
Class LogTableFactor

java.lang.Object
  extended by cc.mallet.grmm.types.AbstractTableFactor
      extended by cc.mallet.grmm.types.LogTableFactor
All Implemented Interfaces:
DiscreteFactor, Factor, java.io.Serializable, java.lang.Cloneable

public class LogTableFactor
extends AbstractTableFactor

Created: Jan 4, 2006

Version:
$Id: LogTableFactor.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
LogTableFactor(AbstractTableFactor in)
           
LogTableFactor(java.util.Collection allVars)
           
LogTableFactor(Variable var)
           
LogTableFactor(Variable[] allVars)
           
 
Method Summary
protected  AbstractTableFactor createBlankSubset(Variable[] vars)
           
protected  void divideByInternal(DiscreteFactor ptl)
           
 Factor duplicate()
           
 void exponentiate(double power)
           
 Matrix getLogValueMatrix()
           
 Matrix getValueMatrix()
           
 double logsum()
           
 double logValue(Assignment assn)
           
 double logValue(AssignmentIterator it)
           
 double logValue(int idx)
           
static LogTableFactor makeFromLogMatrix(Variable[] vars, Matrix values)
           
static LogTableFactor makeFromLogValues(Variable[] vars, double[] vals)
           
static LogTableFactor makeFromLogValues(Variable v, double[] vals)
           
static LogTableFactor makeFromMatrix(Variable[] vars, SparseMatrixn values)
           
static LogTableFactor makeFromValues(Variable[] vars, double[] vals)
           
static LogTableFactor makeFromValues(Variable var, double[] vals2)
           
protected  Factor marginalizeInternal(AbstractTableFactor result)
           
static LogTableFactor multiplyAll(java.util.Collection phis)
           
protected  void multiplyByInternal(DiscreteFactor ptl)
          Does the conceptual equivalent of this *= pot.
 Factor normalize()
          Multiplies this potential by a constant such that it sums to 1.
protected  void plusEqualsAtLocation(int loc, double v)
           
protected  void plusEqualsInternal(DiscreteFactor ptl)
          Does the conceptual equivalent of this += pot.
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)
           
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 it)
          Returns the probability of an assignment to these variables.
 double value(int idx)
           
 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, 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

LogTableFactor

public LogTableFactor(AbstractTableFactor in)

LogTableFactor

public LogTableFactor(Variable var)

LogTableFactor

public LogTableFactor(Variable[] allVars)

LogTableFactor

public LogTableFactor(java.util.Collection allVars)
Method Detail

makeFromValues

public static LogTableFactor makeFromValues(Variable[] vars,
                                            double[] vals)

makeFromLogValues

public static LogTableFactor makeFromLogValues(Variable[] vars,
                                               double[] vals)

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()
Description copied from interface: Factor
Multiplies this potential by a constant such that it sums to 1. Destructive; returns this factor.

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

logsum

public double logsum()
Overrides:
logsum in class AbstractTableFactor

multiplyByInternal

protected void multiplyByInternal(DiscreteFactor ptl)
Does the conceptual equivalent of this *= pot. Assumes that pot's variables are a subset of this potential's.

Specified by:
multiplyByInternal in class AbstractTableFactor

divideByInternal

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

plusEqualsInternal

protected void plusEqualsInternal(DiscreteFactor ptl)
Does the conceptual equivalent of this += pot. Assumes that pot's variables are a subset of this potential's.

Specified by:
plusEqualsInternal in class AbstractTableFactor

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(AssignmentIterator it)
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.


value

public double value(int idx)

logValue

public double logValue(AssignmentIterator it)

logValue

public double logValue(int idx)

logValue

public double logValue(Assignment assn)

marginalizeInternal

protected Factor marginalizeInternal(AbstractTableFactor result)
Specified by:
marginalizeInternal 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

makeFromValues

public static LogTableFactor makeFromValues(Variable var,
                                            double[] vals2)

makeFromMatrix

public static LogTableFactor makeFromMatrix(Variable[] vars,
                                            SparseMatrixn values)

makeFromLogMatrix

public static LogTableFactor makeFromLogMatrix(Variable[] vars,
                                               Matrix values)

makeFromLogValues

public static LogTableFactor makeFromLogValues(Variable v,
                                               double[] vals)

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)
Specified by:
slice_onevar in class AbstractTableFactor

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

multiplyAll

public static LogTableFactor multiplyAll(java.util.Collection phis)

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