cc.mallet.fst.semi_supervised.pr.constraints
Class OneLabelL2PRConstraints

java.lang.Object
  extended by cc.mallet.fst.semi_supervised.pr.constraints.OneLabelL2PRConstraints
All Implemented Interfaces:
PRConstraint

public class OneLabelL2PRConstraints
extends java.lang.Object
implements PRConstraint

A set of constraints on distributions over single labels conditioned on the presence of input features. This is to be used with PR, and penalizes L_2^2 difference from target expectations. Multiple constraints are grouped together here to make things more efficient.

Author:
Gregory Druck

Nested Class Summary
protected  class OneLabelL2PRConstraints.OneLabelPRConstraint
           
 
Field Summary
protected  gnu.trove.TIntArrayList cache
           
protected  gnu.trove.TIntIntHashMap constraintIndices
           
protected  gnu.trove.TIntObjectHashMap<OneLabelL2PRConstraints.OneLabelPRConstraint> constraints
           
protected  StateLabelMap map
           
protected  boolean normalized
           
 
Constructor Summary
  OneLabelL2PRConstraints(boolean normalized)
           
protected OneLabelL2PRConstraints(gnu.trove.TIntObjectHashMap<OneLabelL2PRConstraints.OneLabelPRConstraint> constraints, gnu.trove.TIntIntHashMap constraintIndices, StateLabelMap map, boolean normalized)
           
 
Method Summary
 void addConstraint(int fi, double[] target, double weight)
           
 void addExpectations(double[] expectations)
           
 PRConstraint copy()
          This is used in multi-threading.
 double getAuxiliaryValueContribution(double[] parameters)
           
 double getCompleteValueContribution(double[] parameters)
           
 void getExpectations(double[] expectations)
           
 void getGradient(double[] parameters, double[] gradient)
           
 double getScore(FeatureVector input, int inputPosition, int srcIndex, int destIndex, double[] parameters)
           
 void incrementExpectations(FeatureVector input, int inputPosition, int srcIndex, int destIndex, double prob)
           
 boolean isOneStateConstraint()
           
 int numDimensions()
           
 void preProcess(FeatureVector fv)
          Gives the constraint the option to do some caching using only the FeatureVector.
 java.util.BitSet preProcess(InstanceList data)
           
 void setStateLabelMap(StateLabelMap map)
          Sets that map between the state indices and label indices.
 void zeroExpectations()
          Zero expectation values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

constraints

protected gnu.trove.TIntObjectHashMap<OneLabelL2PRConstraints.OneLabelPRConstraint> constraints

constraintIndices

protected gnu.trove.TIntIntHashMap constraintIndices

map

protected StateLabelMap map

normalized

protected boolean normalized

cache

protected gnu.trove.TIntArrayList cache
Constructor Detail

OneLabelL2PRConstraints

public OneLabelL2PRConstraints(boolean normalized)

OneLabelL2PRConstraints

protected OneLabelL2PRConstraints(gnu.trove.TIntObjectHashMap<OneLabelL2PRConstraints.OneLabelPRConstraint> constraints,
                                  gnu.trove.TIntIntHashMap constraintIndices,
                                  StateLabelMap map,
                                  boolean normalized)
Method Detail

copy

public PRConstraint copy()
Description copied from interface: PRConstraint
This is used in multi-threading.

Specified by:
copy in interface PRConstraint
Returns:
A copy of the GEConstraint.

addConstraint

public void addConstraint(int fi,
                          double[] target,
                          double weight)

numDimensions

public int numDimensions()
Specified by:
numDimensions in interface PRConstraint

isOneStateConstraint

public boolean isOneStateConstraint()

setStateLabelMap

public void setStateLabelMap(StateLabelMap map)
Description copied from interface: PRConstraint
Sets that map between the state indices and label indices.

Specified by:
setStateLabelMap in interface PRConstraint
Parameters:
map - StateLabelMap

preProcess

public void preProcess(FeatureVector fv)
Description copied from interface: PRConstraint
Gives the constraint the option to do some caching using only the FeatureVector. For example, the constrained input features could be cached.

Specified by:
preProcess in interface PRConstraint
Parameters:
fv - FeatureVector input

preProcess

public java.util.BitSet preProcess(InstanceList data)
Specified by:
preProcess in interface PRConstraint
Parameters:
data - Unlabeled data
Returns:
Returns a bitset of the size of the data, with the bit set if a constraint feature fires in that instance.

getScore

public double getScore(FeatureVector input,
                       int inputPosition,
                       int srcIndex,
                       int destIndex,
                       double[] parameters)
Specified by:
getScore in interface PRConstraint

incrementExpectations

public void incrementExpectations(FeatureVector input,
                                  int inputPosition,
                                  int srcIndex,
                                  int destIndex,
                                  double prob)
Specified by:
incrementExpectations in interface PRConstraint

getExpectations

public void getExpectations(double[] expectations)
Specified by:
getExpectations in interface PRConstraint

addExpectations

public void addExpectations(double[] expectations)
Specified by:
addExpectations in interface PRConstraint

zeroExpectations

public void zeroExpectations()
Description copied from interface: PRConstraint
Zero expectation values. Called before re-computing gradient.

Specified by:
zeroExpectations in interface PRConstraint

getAuxiliaryValueContribution

public double getAuxiliaryValueContribution(double[] parameters)
Specified by:
getAuxiliaryValueContribution in interface PRConstraint

getCompleteValueContribution

public double getCompleteValueContribution(double[] parameters)
Specified by:
getCompleteValueContribution in interface PRConstraint

getGradient

public void getGradient(double[] parameters,
                        double[] gradient)
Specified by:
getGradient in interface PRConstraint