cc.mallet.classify.constraints.ge
Class MaxEntRangeL2FLGEConstraints

java.lang.Object
  extended by cc.mallet.classify.constraints.ge.MaxEntRangeL2FLGEConstraints
All Implemented Interfaces:
MaxEntGEConstraint

public class MaxEntRangeL2FLGEConstraints
extends java.lang.Object
implements MaxEntGEConstraint

Expectation constraint for use with GE. Penalizes L_2^2 difference from zero-penalty region [lower,upper]. Multiple constraints are grouped together here to make things more efficient.

Author:
Gregory Druck

Nested Class Summary
protected  class MaxEntRangeL2FLGEConstraints.MaxEntL2IndGEConstraint
           
 
Field Summary
protected  gnu.trove.TIntObjectHashMap<MaxEntRangeL2FLGEConstraints.MaxEntL2IndGEConstraint> constraints
           
protected  gnu.trove.TIntArrayList indexCache
           
protected  gnu.trove.TDoubleArrayList valueCache
           
 
Constructor Summary
MaxEntRangeL2FLGEConstraints(int numFeatures, int numLabels, boolean useValues, boolean normalize)
           
 
Method Summary
 void addConstraint(int fi, int li, double lower, double upper, double weight)
           
 void computeExpectations(FeatureVector input, double[] dist, double weight)
          Compute expectations using provided distribution over labels.
 double getCompositeConstraintFeatureValue(FeatureVector input, int label)
          Computes the composite constraint feature value (over all constraint features) for FeatureVector fv and label label.
 double getValue()
          Returns the total constraint value.
 void preProcess(FeatureVector input)
          Gives the constraint the option to do some caching using only the FeatureVector.
 java.util.BitSet preProcess(InstanceList data)
           
 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<MaxEntRangeL2FLGEConstraints.MaxEntL2IndGEConstraint> constraints

indexCache

protected gnu.trove.TIntArrayList indexCache

valueCache

protected gnu.trove.TDoubleArrayList valueCache
Constructor Detail

MaxEntRangeL2FLGEConstraints

public MaxEntRangeL2FLGEConstraints(int numFeatures,
                                    int numLabels,
                                    boolean useValues,
                                    boolean normalize)
Method Detail

addConstraint

public void addConstraint(int fi,
                          int li,
                          double lower,
                          double upper,
                          double weight)

preProcess

public java.util.BitSet preProcess(InstanceList data)
Specified by:
preProcess in interface MaxEntGEConstraint
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.

preProcess

public void preProcess(FeatureVector input)
Description copied from interface: MaxEntGEConstraint
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 MaxEntGEConstraint
Parameters:
input - FeatureVector input

getCompositeConstraintFeatureValue

public double getCompositeConstraintFeatureValue(FeatureVector input,
                                                 int label)
Description copied from interface: MaxEntGEConstraint
Computes the composite constraint feature value (over all constraint features) for FeatureVector fv and label label.

Specified by:
getCompositeConstraintFeatureValue in interface MaxEntGEConstraint
Parameters:
input - input FeatureVector
label - output label index
Returns:
Constraint feature value

computeExpectations

public void computeExpectations(FeatureVector input,
                                double[] dist,
                                double weight)
Description copied from interface: MaxEntGEConstraint
Compute expectations using provided distribution over labels.

Specified by:
computeExpectations in interface MaxEntGEConstraint
Parameters:
input - FeatureVector
dist - Distribution over labels

getValue

public double getValue()
Description copied from interface: MaxEntGEConstraint
Returns the total constraint value.

Specified by:
getValue in interface MaxEntGEConstraint
Returns:
Constraint value

zeroExpectations

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

Specified by:
zeroExpectations in interface MaxEntGEConstraint