Class OneLabelL2PRConstraints
- java.lang.Object
-
- 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
Nested Classes Modifier and Type Class Description protected classOneLabelL2PRConstraints.OneLabelPRConstraint
-
Field Summary
Fields Modifier and Type Field Description protected com.carrotsearch.hppc.IntArrayListcacheprotected com.carrotsearch.hppc.IntIntHashMapconstraintIndicesprotected com.carrotsearch.hppc.IntObjectHashMap<OneLabelL2PRConstraints.OneLabelPRConstraint>constraintsprotected StateLabelMapmapprotected booleannormalized
-
Constructor Summary
Constructors Modifier Constructor Description OneLabelL2PRConstraints(boolean normalized)protectedOneLabelL2PRConstraints(com.carrotsearch.hppc.IntObjectHashMap<OneLabelL2PRConstraints.OneLabelPRConstraint> constraints, com.carrotsearch.hppc.IntIntHashMap constraintIndices, StateLabelMap map, boolean normalized)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConstraint(int fi, double[] target, double weight)voidaddExpectations(double[] expectations)PRConstraintcopy()This is used in multi-threading.doublegetAuxiliaryValueContribution(double[] parameters)doublegetCompleteValueContribution(double[] parameters)voidgetExpectations(double[] expectations)voidgetGradient(double[] parameters, double[] gradient)doublegetScore(FeatureVector input, int inputPosition, int srcIndex, int destIndex, double[] parameters)voidincrementExpectations(FeatureVector input, int inputPosition, int srcIndex, int destIndex, double prob)booleanisOneStateConstraint()intnumDimensions()voidpreProcess(FeatureVector fv)Gives the constraint the option to do some caching using only the FeatureVector.java.util.BitSetpreProcess(InstanceList data)voidsetStateLabelMap(StateLabelMap map)Sets that map between the state indices and label indices.voidzeroExpectations()Zero expectation values.
-
-
-
Field Detail
-
constraints
protected com.carrotsearch.hppc.IntObjectHashMap<OneLabelL2PRConstraints.OneLabelPRConstraint> constraints
-
constraintIndices
protected com.carrotsearch.hppc.IntIntHashMap constraintIndices
-
map
protected StateLabelMap map
-
normalized
protected boolean normalized
-
cache
protected com.carrotsearch.hppc.IntArrayList cache
-
-
Constructor Detail
-
OneLabelL2PRConstraints
public OneLabelL2PRConstraints(boolean normalized)
-
OneLabelL2PRConstraints
protected OneLabelL2PRConstraints(com.carrotsearch.hppc.IntObjectHashMap<OneLabelL2PRConstraints.OneLabelPRConstraint> constraints, com.carrotsearch.hppc.IntIntHashMap constraintIndices, StateLabelMap map, boolean normalized)
-
-
Method Detail
-
copy
public PRConstraint copy()
Description copied from interface:PRConstraintThis is used in multi-threading.- Specified by:
copyin interfacePRConstraint- Returns:
- A copy of the GEConstraint.
-
addConstraint
public void addConstraint(int fi, double[] target, double weight)
-
numDimensions
public int numDimensions()
- Specified by:
numDimensionsin interfacePRConstraint
-
isOneStateConstraint
public boolean isOneStateConstraint()
-
setStateLabelMap
public void setStateLabelMap(StateLabelMap map)
Description copied from interface:PRConstraintSets that map between the state indices and label indices.- Specified by:
setStateLabelMapin interfacePRConstraint- Parameters:
map- StateLabelMap
-
preProcess
public void preProcess(FeatureVector fv)
Description copied from interface:PRConstraintGives the constraint the option to do some caching using only the FeatureVector. For example, the constrained input features could be cached.- Specified by:
preProcessin interfacePRConstraint- Parameters:
fv- FeatureVector input
-
preProcess
public java.util.BitSet preProcess(InstanceList data)
- Specified by:
preProcessin interfacePRConstraint- 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:
getScorein interfacePRConstraint
-
incrementExpectations
public void incrementExpectations(FeatureVector input, int inputPosition, int srcIndex, int destIndex, double prob)
- Specified by:
incrementExpectationsin interfacePRConstraint
-
getExpectations
public void getExpectations(double[] expectations)
- Specified by:
getExpectationsin interfacePRConstraint
-
addExpectations
public void addExpectations(double[] expectations)
- Specified by:
addExpectationsin interfacePRConstraint
-
zeroExpectations
public void zeroExpectations()
Description copied from interface:PRConstraintZero expectation values. Called before re-computing gradient.- Specified by:
zeroExpectationsin interfacePRConstraint
-
getAuxiliaryValueContribution
public double getAuxiliaryValueContribution(double[] parameters)
- Specified by:
getAuxiliaryValueContributionin interfacePRConstraint
-
getCompleteValueContribution
public double getCompleteValueContribution(double[] parameters)
- Specified by:
getCompleteValueContributionin interfacePRConstraint
-
getGradient
public void getGradient(double[] parameters, double[] gradient)- Specified by:
getGradientin interfacePRConstraint
-
-