Class OneLabelL2IndPRConstraints
- java.lang.Object
-
- 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
Nested Classes Modifier and Type Class Description protected class
OneLabelL2IndPRConstraints.OneLabelL2IndPRConstraint
-
Field Summary
Fields Modifier and Type Field Description protected com.carrotsearch.hppc.IntArrayList
cache
protected com.carrotsearch.hppc.IntObjectHashMap<OneLabelL2IndPRConstraints.OneLabelL2IndPRConstraint>
constraints
protected StateLabelMap
map
protected boolean
normalized
protected int
numDimensions
-
Constructor Summary
Constructors Modifier Constructor Description OneLabelL2IndPRConstraints(boolean normalized)
protected
OneLabelL2IndPRConstraints(com.carrotsearch.hppc.IntObjectHashMap<OneLabelL2IndPRConstraints.OneLabelL2IndPRConstraint> constraints, StateLabelMap map, boolean normalized)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.
-
-
-
Field Detail
-
normalized
protected boolean normalized
-
numDimensions
protected int numDimensions
-
constraints
protected com.carrotsearch.hppc.IntObjectHashMap<OneLabelL2IndPRConstraints.OneLabelL2IndPRConstraint> constraints
-
map
protected StateLabelMap map
-
cache
protected com.carrotsearch.hppc.IntArrayList cache
-
-
Constructor Detail
-
OneLabelL2IndPRConstraints
public OneLabelL2IndPRConstraints(boolean normalized)
-
OneLabelL2IndPRConstraints
protected OneLabelL2IndPRConstraints(com.carrotsearch.hppc.IntObjectHashMap<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 interfacePRConstraint
- 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 interfacePRConstraint
-
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 interfacePRConstraint
- 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 interfacePRConstraint
- Parameters:
fv
- FeatureVector input
-
preProcess
public java.util.BitSet preProcess(InstanceList data)
- Specified by:
preProcess
in 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:
getScore
in interfacePRConstraint
-
incrementExpectations
public void incrementExpectations(FeatureVector input, int inputPosition, int srcIndex, int destIndex, double prob)
- Specified by:
incrementExpectations
in interfacePRConstraint
-
getExpectations
public void getExpectations(double[] expectations)
- Specified by:
getExpectations
in interfacePRConstraint
-
addExpectations
public void addExpectations(double[] expectations)
- Specified by:
addExpectations
in interfacePRConstraint
-
zeroExpectations
public void zeroExpectations()
Description copied from interface:PRConstraint
Zero expectation values. Called before re-computing gradient.- Specified by:
zeroExpectations
in interfacePRConstraint
-
getAuxiliaryValueContribution
public double getAuxiliaryValueContribution(double[] parameters)
- Specified by:
getAuxiliaryValueContribution
in interfacePRConstraint
-
getCompleteValueContribution
public double getCompleteValueContribution(double[] parameters)
- Specified by:
getCompleteValueContribution
in interfacePRConstraint
-
getGradient
public void getGradient(double[] parameters, double[] gradient)
- Specified by:
getGradient
in interfacePRConstraint
-
-