cc.mallet.grmm.learning
Class ACRF.Template

java.lang.Object
  extended by cc.mallet.grmm.learning.ACRF.Template
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ACRF.FixedFactorTemplate, ACRF.SequenceTemplate
Enclosing class:
ACRF

public abstract static class ACRF.Template
extends java.lang.Object
implements java.io.Serializable

A type of clique in the model. Each type of clique is assumed to have the same number of possible outcomes and the same set of weights

See Also:
Serialized Form

Field Summary
 int index
           
protected  SparseVector[] weights
           
 
Constructor Summary
ACRF.Template()
           
 
Method Summary
abstract  void addInstantiatedCliques(ACRF.UnrolledGraph graph, Instance instance)
          Adds all instiated cliques for an instance.
 int addSomeUnsupportedWeights(InstanceList training)
           
protected  Assignment computeAssignment(Assignment graphAssn, VarSet vs)
           
 AbstractTableFactor computeFactor(ACRF.UnrolledVarSet clique)
           
protected  Matrix createFactorMatrix(ACRF.UnrolledVarSet clique)
          Creates an empty matrix for use in storing factor values when this template is unrolled.
protected  java.util.BitSet getAssignmentsPresent()
           
 double getDefaultWeight(int i)
           
 SparseVector getDefaultWeights()
           
 SparseVector[] getWeights()
          Returns the weights for this clique template.
 int initWeights(InstanceList training)
          Initializes the weight vectors to the appropriate size for a set of training data.
protected  boolean isSupportedOnly()
           
 boolean isTrainable()
           
 boolean isUnsupportedWeightsAdded()
           
protected  void modifyPotential(ACRF.UnrolledGraph unrolledGraph, ACRF.UnrolledVarSet clique, AbstractTableFactor ptl)
          Modifies a factor computed from this template.
 void setDefaultWeight(int i, double w)
           
 void setDefaultWeights(SparseVector w)
           
 void setTrainable(boolean tr)
           
 void setWeights(SparseVector[] w)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

weights

protected SparseVector[] weights

index

public int index
Constructor Detail

ACRF.Template

public ACRF.Template()
Method Detail

addInstantiatedCliques

public abstract void addInstantiatedCliques(ACRF.UnrolledGraph graph,
                                            Instance instance)
Adds all instiated cliques for an instance. This method is called as a graph is being unrolled for an instance.

Parameters:
graph - The graph that the cliques will be added to.
instance - Instance to unroll grpah for. Subclasses are free to specify what types they expect in the Instance's slots.

modifyPotential

protected void modifyPotential(ACRF.UnrolledGraph unrolledGraph,
                               ACRF.UnrolledVarSet clique,
                               AbstractTableFactor ptl)
Modifies a factor computed from this template. This is useful for templates that wish to implement special normalization, etc. The default implementation does nothing.

WARNING: If you implement this method, it is likely that you will change the derivative of this factor with respect to weights[]. This means that you will not be able to use the default ACRFTrainer for this template.

Parameters:
unrolledGraph - The graph in which the factor sits
clique - The set of nodes which are the domain of the factor
ptl - The factor to modify

isSupportedOnly

protected boolean isSupportedOnly()

isUnsupportedWeightsAdded

public boolean isUnsupportedWeightsAdded()

getAssignmentsPresent

protected java.util.BitSet getAssignmentsPresent()

getWeights

public SparseVector[] getWeights()
Returns the weights for this clique template. Each possible assignment to the clique can in general have a different set of weights ,so this method returns an array of SparseVectors w, where w[i] are the weights for assignment i.


setWeights

public void setWeights(SparseVector[] w)

initWeights

public int initWeights(InstanceList training)
Initializes the weight vectors to the appropriate size for a set of training data.

Returns:
Number of weights created.

addSomeUnsupportedWeights

public int addSomeUnsupportedWeights(InstanceList training)

computeFactor

public AbstractTableFactor computeFactor(ACRF.UnrolledVarSet clique)

createFactorMatrix

protected Matrix createFactorMatrix(ACRF.UnrolledVarSet clique)
Creates an empty matrix for use in storing factor values when this template is unrolled. By overriding this method, subclasses may enforce that factors generated be sparse.

Parameters:
clique -
Returns:
An empty Matrixn

getDefaultWeight

public double getDefaultWeight(int i)

getDefaultWeights

public SparseVector getDefaultWeights()

setDefaultWeights

public void setDefaultWeights(SparseVector w)

setDefaultWeight

public void setDefaultWeight(int i,
                             double w)

isTrainable

public boolean isTrainable()

setTrainable

public void setTrainable(boolean tr)

computeAssignment

protected Assignment computeAssignment(Assignment graphAssn,
                                       VarSet vs)