cc.mallet.grmm.types
Class Assignment

java.lang.Object
  extended by cc.mallet.grmm.types.AbstractFactor
      extended by cc.mallet.grmm.types.Assignment
All Implemented Interfaces:
Factor, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
LabelsAssignment

public class Assignment
extends AbstractFactor
implements java.io.Serializable

An assignment to a bunch of variables.

Note that outcomes are always integers. If you want them to be something else, then the Variables all have outcome Alphabets; for example, see Variable.lookupOutcome(int).

Created: Tue Oct 21 15:11:11 2003

Version:
$Id: Assignment.java,v 1.1 2007/10/22 21:37:44 mccallum Exp $
Author:
Charles Sutton
See Also:
Serialized Form

Field Summary
 
Fields inherited from class cc.mallet.grmm.types.AbstractFactor
vars
 
Constructor Summary
Assignment()
          Creates an empty assignment.
Assignment(FactorGraph mdl, int[] outcomes)
          Creates an assignment over all Variables in a model.
Assignment(java.util.List vars, int[] outcomes)
          Creates an assignemnt for the given variables.
Assignment(Variable[] vars, double[] outcomes)
          Creates an assignemnt for the given variables.
Assignment(Variable[] vars, int[] outcomes)
          Creates an assignemnt for the given variables.
Assignment(Variable var, double outcome)
           
Assignment(Variable var, int outcome)
           
 
Method Summary
 void addRow(Assignment other)
           
 void addRow(java.lang.Object[] row)
           
 void addRow(Variable[] vars, double[] values)
           
 void addRow(Variable[] vars, int[] values)
           
 void addRow(Variable[] vars, java.lang.Object[] values)
           
 boolean almostEquals(Factor p, double epsilon)
           
 java.util.List asList()
          Returns a list of single-row assignments, one for each row in this assignment.
 AbstractTableFactor asTable()
           
 boolean containsVar(Variable var)
          Returns true if this assignment specifies a value for var
 void dump()
           
 void dump(java.io.PrintWriter out)
           
 void dumpNumeric()
           
 java.lang.String dumpToString()
           
 Factor duplicate()
           
protected  Factor extractMaxInternal(VarSet varSet)
           
 int get(int ridx, Variable var)
          Returns the value of var in this assigment.
 int get(Variable var)
           
 int[] getColumnInt(Variable x1)
           
 double getDouble(int ridx, Variable var)
          Returns the value of var in this assigment.
 double getDouble(Variable var)
           
 java.lang.Object getObject(int ri, Variable var)
           
 java.lang.Object getObject(Variable var)
           
 Assignment getRow(int ridx)
           
 Variable getVariable(int i)
           
 Variable[] getVars()
          Returns all variables which are assigned to.
 boolean isNaN()
           
protected  double lookupValueInternal(int assnIdx)
           
static Assignment makeFromSingleIndex(VarSet clique, int idx)
           
protected  Factor marginalizeInternal(VarSet varsToKeep)
           
 Factor normalize()
          Multiplies this potential by a constant such that it sums to 1.
 int numRows()
           
 int numVariables()
           
static Assignment restriction(Assignment assn, VarSet varSet)
          Deprecated. marginalize
 Assignment sample(Randoms r)
          Return an assignment sampled from this factor, interpreting it as an unnormalized probability distribution.
 void setDouble(int ridx, Variable var, double value)
           
 void setRow(int ridx, Assignment other)
           
 void setRow(int ridx, int[] vals)
           
 void setValue(int ridx, Variable var, int value)
           
 void setValue(Variable var, int value)
           
 int singleIndex()
          Converts this assignment into a unique integer.
 int singleIndex(int row)
           
 int size()
           
 Factor slice(Assignment assn)
           
 Assignment subAssn(int start, int end)
           
 double[] toDoubleArray(int ridx)
           
static Assignment union(Assignment assn1, Assignment assn2)
          Returns the union of two Assignments.
 
Methods inherited from class cc.mallet.grmm.types.AbstractFactor
almostEquals, argmax, assignmentIterator, delogify, divideBy, entropy, exponentiate, extractMax, extractMax, extractMax, isInLogSpace, log, logify, logValue, logValue, logValue, marginalize, marginalize, marginalize, marginalizeOut, marginalizeOut, multiply, multiplyBy, phi, prettyOutputString, setVarSet, sum, value, value, varSet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Assignment

public Assignment()
Creates an empty assignment.


Assignment

public Assignment(Variable var,
                  int outcome)

Assignment

public Assignment(Variable var,
                  double outcome)

Assignment

public Assignment(Variable[] vars,
                  int[] outcomes)
Creates an assignemnt for the given variables.


Assignment

public Assignment(Variable[] vars,
                  double[] outcomes)
Creates an assignemnt for the given variables.


Assignment

public Assignment(java.util.List vars,
                  int[] outcomes)
Creates an assignemnt for the given variables.


Assignment

public Assignment(FactorGraph mdl,
                  int[] outcomes)
Creates an assignment over all Variables in a model. The assignment will assign outcomes[i] to the variable mdl.get(i)

Method Detail

union

public static Assignment union(Assignment assn1,
                               Assignment assn2)
Returns the union of two Assignments. That is, the value of a variable in the returned Assignment will be as specified in one of the given assignments.

If the assignments share variables, the value in the new Assignment for those variables in undefined.

Parameters:
assn1 - One assignment.
assn2 - Another assignment.
Returns:
A newly-created Assignment.

restriction

public static Assignment restriction(Assignment assn,
                                     VarSet varSet)
Deprecated. marginalize

Returns a new assignment which only assigns values to those variabes in a given clique.

Parameters:
assn - A large assignment
varSet - Which variables to restrict assignment o
Returns:
A newly-created Assignment

getRow

public Assignment getRow(int ridx)

addRow

public void addRow(Variable[] vars,
                   int[] values)

addRow

public void addRow(Variable[] vars,
                   double[] values)

addRow

public void addRow(Variable[] vars,
                   java.lang.Object[] values)

addRow

public void addRow(java.lang.Object[] row)

addRow

public void addRow(Assignment other)

numRows

public int numRows()

get

public int get(Variable var)

getDouble

public double getDouble(Variable var)

getObject

public java.lang.Object getObject(Variable var)

get

public int get(int ridx,
               Variable var)
Returns the value of var in this assigment.


getDouble

public double getDouble(int ridx,
                        Variable var)
Returns the value of var in this assigment. This will be removed when we switch to Java 1.5.


getObject

public java.lang.Object getObject(int ri,
                                  Variable var)

getVariable

public Variable getVariable(int i)
Specified by:
getVariable in interface Factor
Overrides:
getVariable in class AbstractFactor

getVars

public Variable[] getVars()
Returns all variables which are assigned to.


size

public int size()

makeFromSingleIndex

public static Assignment makeFromSingleIndex(VarSet clique,
                                             int idx)

singleIndex

public int singleIndex()
Converts this assignment into a unique integer. All different assignments to the same variables are guaranteed to have unique integers. The range of the index will be between 0 (inclusive) and M (exclusive), where M is the product of all cardinalities of all variables in this assignment.

Returns:
An integer

singleIndex

public int singleIndex(int row)

numVariables

public int numVariables()

toDoubleArray

public double[] toDoubleArray(int ridx)

duplicate

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

dump

public void dump()

dump

public void dump(java.io.PrintWriter out)

dumpNumeric

public void dumpNumeric()

containsVar

public boolean containsVar(Variable var)
Returns true if this assignment specifies a value for var

Specified by:
containsVar in interface Factor
Overrides:
containsVar in class AbstractFactor

setValue

public void setValue(Variable var,
                     int value)

setValue

public void setValue(int ridx,
                     Variable var,
                     int value)

setDouble

public void setDouble(int ridx,
                      Variable var,
                      double value)

setRow

public void setRow(int ridx,
                   Assignment other)

setRow

public void setRow(int ridx,
                   int[] vals)

extractMaxInternal

protected Factor extractMaxInternal(VarSet varSet)
Specified by:
extractMaxInternal in class AbstractFactor

lookupValueInternal

protected double lookupValueInternal(int assnIdx)
Specified by:
lookupValueInternal in class AbstractFactor

marginalizeInternal

protected Factor marginalizeInternal(VarSet varsToKeep)
Specified by:
marginalizeInternal in class AbstractFactor

almostEquals

public boolean almostEquals(Factor p,
                            double epsilon)
Specified by:
almostEquals in interface Factor

isNaN

public boolean isNaN()
Specified by:
isNaN in interface Factor

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

sample

public Assignment sample(Randoms r)
Description copied from interface: Factor
Return an assignment sampled from this factor, interpreting it as an unnormalized probability distribution.

Specified by:
sample in interface Factor
Overrides:
sample in class AbstractFactor

dumpToString

public java.lang.String dumpToString()
Specified by:
dumpToString in interface Factor

slice

public Factor slice(Assignment assn)
Specified by:
slice in interface Factor

asTable

public AbstractTableFactor asTable()
Specified by:
asTable in interface Factor
Overrides:
asTable in class AbstractFactor

asList

public java.util.List asList()
Returns a list of single-row assignments, one for each row in this assignment.


subAssn

public Assignment subAssn(int start,
                          int end)

getColumnInt

public int[] getColumnInt(Variable x1)