edu.stanford.nlp.optimization
Class AbstractStochasticCachingDiffUpdateFunction

java.lang.Object
  extended by edu.stanford.nlp.optimization.AbstractCachingDiffFunction
      extended by edu.stanford.nlp.optimization.AbstractStochasticCachingDiffFunction
          extended by edu.stanford.nlp.optimization.AbstractStochasticCachingDiffUpdateFunction
All Implemented Interfaces:
DiffFunction, Function, HasInitial
Direct Known Subclasses:
LogConditionalObjectiveFunction

public abstract class AbstractStochasticCachingDiffUpdateFunction
extends AbstractStochasticCachingDiffFunction

Function for stochastic calculations that does update in place (instead of maintaining and returning the derivative) Weights are represented by an array of doubles and a scalar that indicates how much to scale all weights by This allows all weights to be scaled by just modifying the scalar

Author:
Angel Chang

Nested Class Summary
 
Nested classes/interfaces inherited from class edu.stanford.nlp.optimization.AbstractStochasticCachingDiffFunction
AbstractStochasticCachingDiffFunction.SamplingMethod
 
Field Summary
 
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
 
Constructor Summary
AbstractStochasticCachingDiffUpdateFunction()
           
 
Method Summary
abstract  double calculateStochasticUpdate(double[] x, double xscale, int[] batch, double gain)
          Performs stochastic update of weights x (scaled by xscale) based on samples indexed by batch
 double calculateStochasticUpdate(double[] x, double xscale, int batchSize, double gain)
          Performs stochastic update of weights x (scaled by xscale) based on next batch of batchSize
 int[] getSample(int sampleSize)
          Gets a random sample (this is sampling with replacement)
abstract  double valueAt(double[] x, double xscale, int[] batch)
          Computes value of function for specified value of x (scaled by xcale) only over samples indexed by batch
 
Methods inherited from class edu.stanford.nlp.optimization.AbstractStochasticCachingDiffFunction
calculateStochastic, clearCache, dataDimension, 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
calculate, copy, derivativeAt, domainDimension, valueAt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractStochasticCachingDiffUpdateFunction

public AbstractStochasticCachingDiffUpdateFunction()
Method Detail

getSample

public int[] getSample(int sampleSize)
Gets a random sample (this is sampling with replacement)

Parameters:
sampleSize - number of samples to generate
Returns:
array of indices for random sample of sampleSize

valueAt

public abstract double valueAt(double[] x,
                               double xscale,
                               int[] batch)
Computes value of function for specified value of x (scaled by xcale) only over samples indexed by batch

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

calculateStochasticUpdate

public abstract double calculateStochasticUpdate(double[] x,
                                                 double xscale,
                                                 int[] batch,
                                                 double gain)
Performs stochastic update of weights x (scaled by xscale) based on samples indexed by batch

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

calculateStochasticUpdate

public double calculateStochasticUpdate(double[] x,
                                        double xscale,
                                        int batchSize,
                                        double gain)
Performs stochastic update of weights x (scaled by xscale) based on next batch of batchSize

Parameters:
x - - unscaled weights
xscale - - how much to scale x by when performing calculations
batchSize - - number of samples to pick next
gain - - how much to scale adjustments to x
Returns:
value of function at specified x (scaled by xscale) for samples


Stanford NLP Group