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

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

public class OneLabelL2IndPRConstraints
extends java.lang.Object
implements PRConstraint

A set of constraints on individual input feature label pairs. 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 OneLabelL2IndPRConstraints.OneLabelL2IndPRConstraint
           
 
Field Summary
protected  gnu.trove.TIntArrayList cache
           
protected  gnu.trove.TIntObjectHashMap<OneLabelL2IndPRConstraints.OneLabelL2IndPRConstraint> constraints
           
protected  StateLabelMap map
           
protected  boolean normalized
           
protected  int numDimensions
           
 
Constructor Summary
  OneLabelL2IndPRConstraints(boolean normalized)
           
protected OneLabelL2IndPRConstraints(gnu.trove.TIntObjectHashMap<OneLabelL2IndPRConstraints.OneLabelL2IndPRConstraint> constraints, StateLabelMap map, boolean normalized)
           
 
Method Summary
 void addConstraint(int fi, int li, 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)
           
 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

normalized

protected boolean normalized

numDimensions

protected int numDimensions

constraints

protected gnu.trove.TIntObjectHashMap<OneLabelL2IndPRConstraints.OneLabelL2IndPRConstraint> constraints

map

protected StateLabelMap map

cache

protected gnu.trove.TIntArrayList cache
Constructor Detail

OneLabelL2IndPRConstraints

public OneLabelL2IndPRConstraints(boolean normalized)

OneLabelL2IndPRConstraints

protected OneLabelL2IndPRConstraints(gnu.trove.TIntObjectHashMap<OneLabelL2IndPRConstraints.OneLabelL2IndPRConstraint> constraints,
                                     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,
                          int li,
                          double target,
                          double weight)

numDimensions

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

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