Class TwoLabelGEConstraints
- java.lang.Object
-
- cc.mallet.fst.semi_supervised.constraints.TwoLabelGEConstraints
-
- All Implemented Interfaces:
GEConstraint
- Direct Known Subclasses:
TwoLabelKLGEConstraints
,TwoLabelL2GEConstraints
public abstract class TwoLabelGEConstraints extends java.lang.Object implements GEConstraint
A set of constraints on distributions over pairs of consecutive labels conditioned on the presence of input features. Subclasses are to be used with GE. Multiple constraints are grouped together here to make things more efficient.- Author:
- Gregory Druck
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
TwoLabelGEConstraints.TwoLabelGEConstraint
-
Field Summary
Fields Modifier and Type Field Description protected com.carrotsearch.hppc.IntArrayList
cache
protected java.util.ArrayList<TwoLabelGEConstraints.TwoLabelGEConstraint>
constraintsList
protected com.carrotsearch.hppc.IntIntHashMap
constraintsMap
protected StateLabelMap
map
-
Constructor Summary
Constructors Modifier Constructor Description TwoLabelGEConstraints()
protected
TwoLabelGEConstraints(java.util.ArrayList<TwoLabelGEConstraints.TwoLabelGEConstraint> constraintsList, com.carrotsearch.hppc.IntIntHashMap constraintsMap, StateLabelMap map)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
addConstraint(int fi, double[][] target, double weight)
void
computeExpectations(java.util.ArrayList<SumLattice> lattices)
Compute expectations using cached lattices.double
getCompositeConstraintFeatureValue(FeatureVector fv, int ip, int si1, int si2)
Computes the composite constraint feature value (over all constraint features) for FeatureVector fv and a transition from state li1 to li2.abstract double
getValue()
Returns the total constraint value.boolean
isOneStateConstraint()
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
-
Methods inherited from interface cc.mallet.fst.semi_supervised.constraints.GEConstraint
copy
-
-
-
-
Field Detail
-
constraintsList
protected java.util.ArrayList<TwoLabelGEConstraints.TwoLabelGEConstraint> constraintsList
-
constraintsMap
protected com.carrotsearch.hppc.IntIntHashMap constraintsMap
-
map
protected StateLabelMap map
-
cache
protected com.carrotsearch.hppc.IntArrayList cache
-
-
Constructor Detail
-
TwoLabelGEConstraints
public TwoLabelGEConstraints()
-
TwoLabelGEConstraints
protected TwoLabelGEConstraints(java.util.ArrayList<TwoLabelGEConstraints.TwoLabelGEConstraint> constraintsList, com.carrotsearch.hppc.IntIntHashMap constraintsMap, StateLabelMap map)
-
-
Method Detail
-
addConstraint
public abstract void addConstraint(int fi, double[][] target, double weight)
- Parameters:
fi
- Input feature indextarget
- Target distribution over pairs of labelsweight
- Weight of this constraint
-
isOneStateConstraint
public boolean isOneStateConstraint()
- Specified by:
isOneStateConstraint
in interfaceGEConstraint
- Returns:
- true if constraint feature only considers one state
-
setStateLabelMap
public void setStateLabelMap(StateLabelMap map)
Description copied from interface:GEConstraint
Sets that map between the state indices and label indices.- Specified by:
setStateLabelMap
in interfaceGEConstraint
- Parameters:
map
- StateLabelMap
-
preProcess
public void preProcess(FeatureVector fv)
Description copied from interface:GEConstraint
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 interfaceGEConstraint
- Parameters:
fv
- FeatureVector input
-
preProcess
public java.util.BitSet preProcess(InstanceList data)
- Specified by:
preProcess
in interfaceGEConstraint
- 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.
-
getCompositeConstraintFeatureValue
public double getCompositeConstraintFeatureValue(FeatureVector fv, int ip, int si1, int si2)
Description copied from interface:GEConstraint
Computes the composite constraint feature value (over all constraint features) for FeatureVector fv and a transition from state li1 to li2.- Specified by:
getCompositeConstraintFeatureValue
in interfaceGEConstraint
- Parameters:
fv
- FeatureVector on transitionip
- Position of input in sequencesi1
- Source state index for transitionsi2
- Destination state index for transition- Returns:
- Constraint feature value
-
getValue
public abstract double getValue()
Description copied from interface:GEConstraint
Returns the total constraint value.- Specified by:
getValue
in interfaceGEConstraint
- Returns:
- Constraint value
-
zeroExpectations
public void zeroExpectations()
Description copied from interface:GEConstraint
Zero expectation values. Called before re-computing gradient.- Specified by:
zeroExpectations
in interfaceGEConstraint
-
computeExpectations
public void computeExpectations(java.util.ArrayList<SumLattice> lattices)
Description copied from interface:GEConstraint
Compute expectations using cached lattices.- Specified by:
computeExpectations
in interfaceGEConstraint
- Parameters:
lattices
- Cached SumLattices
-
-