edu.stanford.nlp.ie.crf
Class CRFLogConditionalObjectiveFunction

java.lang.Object
  extended by edu.stanford.nlp.optimization.AbstractCachingDiffFunction
      extended by edu.stanford.nlp.optimization.AbstractStochasticCachingDiffFunction
          extended by edu.stanford.nlp.optimization.AbstractStochasticCachingDiffUpdateFunction
              extended by edu.stanford.nlp.ie.crf.CRFLogConditionalObjectiveFunction
All Implemented Interfaces:
DiffFunction, Function, HasInitial

public class CRFLogConditionalObjectiveFunction
extends AbstractStochasticCachingDiffUpdateFunction

Author:
Jenny Finkel

Nested Class Summary
 
Nested classes/interfaces inherited from class edu.stanford.nlp.optimization.AbstractStochasticCachingDiffFunction
AbstractStochasticCachingDiffFunction.SamplingMethod
 
Field Summary
protected  double epsilon
           
static int HUBER_PRIOR
           
static int NO_PRIOR
           
protected  int prior
           
static int QUADRATIC_PRIOR
           
static int QUARTIC_PRIOR
           
protected  double sigma
           
static boolean VERBOSE
           
 
Fields inherited from class edu.stanford.nlp.optimization.AbstractStochasticCachingDiffFunction
allIndices, curElement, finiteDifferenceStepSize, gradPerturbed, hasNewVals, HdotV, lastBatch, lastBatchSize, lastElement, lastVBatch, lastXBatch, method, randGenerator, recalculatePrevBatch, returnPreviousValues, sampleMethod, scaleUp, thisBatch, xPerturbed
 
Fields inherited from class edu.stanford.nlp.optimization.AbstractCachingDiffFunction
derivative, value
 
Method Summary
 void calculate(double[] x)
          Calculates both value and partial derivatives at the point x, and save them internally.
 void calculateStochastic(double[] x, double[] v, int[] batch)
          calculateStochastic needs to calculate a stochastic approximation to the derivative and value of of a function for a given batch of the data.
 void calculateStochasticGradientOnly(double[] x, int[] batch)
           
 double calculateStochasticUpdate(double[] x, double xscale, int[] batch, double gscale)
          Performs stochastic update of weights x (scaled by xscale) based on samples indexed by batch NOTE: This function does not do regularization (regularization is done by minimizer)
 int dataDimension()
          Data dimension must return the size of the data used by the function.
 int domainDimension()
          Returns the number of dimensions in the function's domain
 double[][] empty2D()
           
static int getPriorType(String priorTypeStr)
           
 int[][] getWeightIndices()
           
 double[] to1D(double[][] weights)
           
 double[][] to2D(double[] weights)
          Takes a double array of weights and creates a 2D array where: the first element is the mapped index of featuresIndex the second element is the index of the of the element
 double valueAt(double[] x, double xscale, int[] batch)
          Computes value of function for specified value of x (scaled by xscale) only over samples indexed by batch NOTE: This function does not do regularization (regularization is done by minimizer)
 
Methods inherited from class edu.stanford.nlp.optimization.AbstractStochasticCachingDiffUpdateFunction
calculateStochasticUpdate, getSample
 
Methods inherited from class edu.stanford.nlp.optimization.AbstractStochasticCachingDiffFunction
clearCache, decrementBatch, derivativeAt, derivativeAt, getBatch, HdotVAt, HdotVAt, HdotVAt, incrementBatch, incrementRandom, initial, lastDerivative, lastValue, scaleUp, setValue, valueAt, valueAt
 
Methods inherited from class edu.stanford.nlp.optimization.AbstractCachingDiffFunction
copy, derivativeAt, valueAt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_PRIOR

public static final int NO_PRIOR
See Also:
Constant Field Values

QUADRATIC_PRIOR

public static final int QUADRATIC_PRIOR
See Also:
Constant Field Values

HUBER_PRIOR

public static final int HUBER_PRIOR
See Also:
Constant Field Values

QUARTIC_PRIOR

public static final int QUARTIC_PRIOR
See Also:
Constant Field Values

prior

protected int prior

sigma

protected double sigma

epsilon

protected double epsilon

VERBOSE

public static boolean VERBOSE
Method Detail

getPriorType

public static int getPriorType(String priorTypeStr)

domainDimension

public int domainDimension()
Description copied from interface: Function
Returns the number of dimensions in the function's domain

Specified by:
domainDimension in interface Function
Specified by:
domainDimension in class AbstractCachingDiffFunction
Returns:
the number of domain dimensions

to2D

public double[][] to2D(double[] weights)
Takes a double array of weights and creates a 2D array where: the first element is the mapped index of featuresIndex the second element is the index of the of the element

Returns:
a 2D weight array

to1D

public double[] to1D(double[][] weights)

getWeightIndices

public int[][] getWeightIndices()

empty2D

public double[][] empty2D()

calculate

public void calculate(double[] x)
Calculates both value and partial derivatives at the point x, and save them internally.

Specified by:
calculate in class AbstractCachingDiffFunction

calculateStochastic

public void calculateStochastic(double[] x,
                                double[] v,
                                int[] batch)
Description copied from class: AbstractStochasticCachingDiffFunction
calculateStochastic needs to calculate a stochastic approximation to the derivative and value of of a function for a given batch of the data. The approximation to the derivative must be stored in the array derivative , the approximation to the value in value and the approximation to the Hessian vector product H.v in the array HdotV . Note that the hessian vector product is used primarily with the Stochastic Meta Descent optimization routine SMDMinimizer . Important: The stochastic approximation must be such that the sum of all stochastic calculations over each of the batches in the data must equal the full calculation. i.e. for a data set of size 100 the sum of the gradients for batches 1-10 , 11-20 , 21-30 .... 91-100 must be the same as the gradient for the full calculation (at the very least in expectation). Be sure to take into account the priors.

Specified by:
calculateStochastic in class AbstractStochasticCachingDiffFunction
Parameters:
x - - value to evaluate at
v - - the vector for the Hessian vector product H.v
batch - - an array containing the indices of the data to use in the calculation, this array is being calculated internal to the abstract, and only needs to be handled not generated by the implemenation.

dataDimension

public int dataDimension()
Description copied from class: AbstractStochasticCachingDiffFunction
Data dimension must return the size of the data used by the function.

Specified by:
dataDimension in class AbstractStochasticCachingDiffFunction

calculateStochasticGradientOnly

public void calculateStochasticGradientOnly(double[] x,
                                            int[] batch)

calculateStochasticUpdate

public double calculateStochasticUpdate(double[] x,
                                        double xscale,
                                        int[] batch,
                                        double gscale)
Performs stochastic update of weights x (scaled by xscale) based on samples indexed by batch NOTE: This function does not do regularization (regularization is done by minimizer)

Specified by:
calculateStochasticUpdate in class AbstractStochasticCachingDiffUpdateFunction
Parameters:
x - - unscaled weights
xscale - - how much to scale x by when performing calculations
batch - - indices of which samples to compute function over
gscale - - how much to scale adjustments to x
Returns:
value of function at specified x (scaled by xscale) for samples

valueAt

public double valueAt(double[] x,
                      double xscale,
                      int[] batch)
Computes value of function for specified value of x (scaled by xscale) only over samples indexed by batch NOTE: This function does not do regularization (regularization is done by minimizer)

Specified by:
valueAt in class AbstractStochasticCachingDiffUpdateFunction
Parameters:
x - - unscaled weights
xscale - - how much to scale x by when performing calculations
batch - - indices of which samples to compute function over
Returns:
value of function at specified x (scaled by xscale) for samples


Stanford NLP Group