public class TableFactor extends NDArrayDoubles
Holds a factor populated by doubles that knows how to do all the important operations for PGM inference. Internally, these are just different flavors of two basic data-flow operations:
- Factor product - Factor marginalization
The output here is different ways to grow and shrink factors that turn out to be useful for downstream uses in PGMs. Basically, we care about message passing, as that will be the primary operation.
Everything is represented as log-linear, because the primary use for TableFactor is in CliqueTree, and that is intended for use with log-linear models.
Modifier and Type | Field and Description |
---|---|
int[] |
neighborIndices |
static boolean |
USE_EXP_APPROX |
dimensions, values
Constructor and Description |
---|
TableFactor(ConcatVector weights,
GraphicalModel.Factor factor)
Construct a TableFactor for inference within a model.
|
TableFactor(ConcatVector weights,
GraphicalModel.Factor factor,
int[] observations)
Construct a TableFactor for inference within a model.
|
Modifier and Type | Method and Description |
---|---|
static double |
exp(double val)
Fast approximation of the exp() function.
|
double |
getAssignmentValue(int[] assignment)
Just a pass through to the NDArray version, plus a Math.exp to ensure that to the outside world the TableFactor
doesn't look like it's in log-space
|
double[][] |
getMaxedMarginals()
Convenience function to max out all but one variable, and return the marginal array.
|
double[][] |
getSummedMarginals()
Returns the summed marginals for each element in the factor.
|
TableFactor |
maxOut(int variable)
Marginalize out a variable by taking the max value.
|
TableFactor |
multiply(TableFactor other)
Product two factors, taking the multiplication at the intersections.
|
TableFactor |
observe(int variable,
int value)
Remove a variable by observing it at a certain value, return a new factor without that variable.
|
void |
setAssignmentValue(int[] assignment,
double value)
Just a pass through to the NDArray version, plus a Math.log to ensure that to the outside world the TableFactor
doesn't look like it's in log-space
|
TableFactor |
sumOut(int variable)
Marginalize out a variable by taking a sum.
|
double |
valueSum()
This is useful for calculating the partition function, and is exposed here because when implemented internally
we can do a much more numerically stable summation.
|
combinatorialNeighborStatesCount, fastPassByReferenceIterator, getDimensions, iterator
public int[] neighborIndices
public static final boolean USE_EXP_APPROX
public TableFactor(ConcatVector weights, GraphicalModel.Factor factor)
Each element of the table is given by: t_i = exp(f_i*w)
weights
- the vector to dot product with every element of the factor tablefactor
- the feature factor to be multiplied inpublic TableFactor(ConcatVector weights, GraphicalModel.Factor factor, int[] observations)
Each element of the table is given by: t_i = exp(f_i*w)
weights
- the vector to dot product with every element of the factor tablefactor
- the feature factor to be multiplied inpublic static double exp(double val)
val
- The value to be exponentiatedpublic TableFactor observe(int variable, int value)
variable
- the variable to be observedvalue
- the value the variable takes when observedpublic double[][] getSummedMarginals()
public double[][] getMaxedMarginals()
public TableFactor maxOut(int variable)
variable
- the variable to be maxed out.public TableFactor sumOut(int variable)
variable
- the variable to be summed outpublic TableFactor multiply(TableFactor other)
other
- the other factor to be multipliedpublic double valueSum()
public double getAssignmentValue(int[] assignment)
getAssignmentValue
in class NDArrayDoubles
assignment
- a list of variable settings, in the same order as the neighbors array of the factorpublic void setAssignmentValue(int[] assignment, double value)
setAssignmentValue
in class NDArrayDoubles
assignment
- a list of variable settings, in the same order as the neighbors array of the factorvalue
- the value to put into the factor table