Class OneLabelL2PRConstraints

  • All Implemented Interfaces:

    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.
    Gregory Druck
    • Field Detail

      • constraintIndices

        protected com.carrotsearch.hppc.IntIntHashMap constraintIndices
      • normalized

        protected boolean normalized
      • cache

        protected com.carrotsearch.hppc.IntArrayList cache
    • Constructor Detail

      • OneLabelL2PRConstraints

        public OneLabelL2PRConstraints​(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
        A copy of the GEConstraint.
      • addConstraint

        public void addConstraint​(int fi,
                                  double[] target,
                                  double weight)
      • isOneStateConstraint

        public boolean isOneStateConstraint()
      • 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
        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
        fv - FeatureVector input
      • preProcess

        public java.util.BitSet preProcess​(InstanceList data)
        Specified by:
        preProcess in interface PRConstraint
        data - Unlabeled data
        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
      • zeroExpectations

        public void zeroExpectations()
        Description copied from interface: PRConstraint
        Zero expectation values. Called before re-computing gradient.
        Specified by:
        zeroExpectations in interface PRConstraint
      • getGradient

        public void getGradient​(double[] parameters,
                                double[] gradient)
        Specified by:
        getGradient in interface PRConstraint