|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.stanford.nlp.optimization.AbstractCachingDiffFunction
edu.stanford.nlp.optimization.AbstractStochasticCachingDiffFunction
public abstract class AbstractStochasticCachingDiffFunction
Nested Class Summary | |
---|---|
static class |
AbstractStochasticCachingDiffFunction.SamplingMethod
|
Field Summary | |
---|---|
protected List<Integer> |
allIndices
|
protected int |
curElement
|
protected double[] |
extFiniteDiffDerivative
|
protected double |
finiteDifferenceStepSize
finiteDifferenceStepSize - this is the fixed step size for the finite difference approximation. |
protected double[] |
gradPerturbed
|
boolean |
hasNewVals
|
protected double[] |
HdotV
|
protected int[] |
lastBatch
|
protected int |
lastBatchSize
|
protected int |
lastElement
|
protected double[] |
lastVBatch
|
protected double[] |
lastXBatch
|
StochasticCalculateMethods |
method
|
protected Random |
randGenerator
|
boolean |
recalculatePrevBatch
|
boolean |
returnPreviousValues
|
AbstractStochasticCachingDiffFunction.SamplingMethod |
sampleMethod
|
protected boolean |
scaleUp
|
protected double[] |
xPerturbed
|
Fields inherited from class edu.stanford.nlp.optimization.AbstractCachingDiffFunction |
---|
derivative, value |
Constructor Summary | |
---|---|
AbstractStochasticCachingDiffFunction()
|
Method Summary | |
---|---|
protected abstract 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. |
protected void |
clearCache()
Clears the cache in a way that doesn't require reallocation :-) |
protected void |
copy(double[] y,
double[] x)
|
abstract int |
dataDimension()
Data dimension must return the size of the data used by the function. |
void |
decrementBatch(int batchSize)
decrementBatch - This decrements the curElement variable by the amount batchSize. |
double[] |
derivativeAt(double[] x,
double[] v,
int batchSize)
|
double[] |
derivativeAt(double[] x,
int batchSize)
|
double[] |
HdotVAt(double[] x,
double[] v)
|
double[] |
HdotVAt(double[] x,
double[] v,
double[] curDerivative,
int batchSize)
|
double[] |
HdotVAt(double[] x,
double[] v,
int batchSize)
HdotVAt will return the hessian vector product H.v at the point x for a batchSize subset of the data There are several ways to perform this calculation, as of now Finite Difference, and Algorithmic Differentiation are the methods that have been used. |
void |
incrementBatch(int batchSize)
incrementBatch will shift the curElement variable to mark the next batch. |
void |
incrementRandom(int numTimes)
|
double[] |
initial()
Returns the intitial point in the domain (but not necessarily a feasible one). |
double[] |
lastDerivative()
|
double |
lastValue()
|
void |
scaleUp(boolean toScaleUp)
|
void |
setValue(double v)
|
double |
valueAt(double[] x,
double[] v,
int batchSize)
This function will return the stochastic approximation at the point x. |
double |
valueAt(double[] x,
int batchSize)
valueAt(x,batchSize) derivativeAt(x,batchSize) invokes the calculateStochastic function to get the current value at x for the next batchSize data points. |
Methods inherited from class edu.stanford.nlp.optimization.AbstractCachingDiffFunction |
---|
calculate, derivativeAt, domainDimension, valueAt |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public boolean hasNewVals
public boolean recalculatePrevBatch
public boolean returnPreviousValues
protected int lastBatchSize
protected int[] lastBatch
protected double[] lastXBatch
protected double[] lastVBatch
protected double[] extFiniteDiffDerivative
protected int lastElement
protected double[] HdotV
protected double[] gradPerturbed
protected double[] xPerturbed
protected int curElement
protected List<Integer> allIndices
protected Random randGenerator
protected boolean scaleUp
public StochasticCalculateMethods method
public AbstractStochasticCachingDiffFunction.SamplingMethod sampleMethod
protected double finiteDifferenceStepSize
Constructor Detail |
---|
public AbstractStochasticCachingDiffFunction()
Method Detail |
---|
public void incrementRandom(int numTimes)
public void scaleUp(boolean toScaleUp)
protected abstract void calculateStochastic(double[] x, double[] v, int[] batch)
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.
x
- - value to evaluate atv
- - the vector for the Hessian vector product H.vbatch
- - 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.public abstract int dataDimension()
protected void clearCache()
clearCache
in class AbstractCachingDiffFunction
public double[] initial()
HasInitial
initial
in interface HasInitial
initial
in class AbstractCachingDiffFunction
protected void copy(double[] y, double[] x)
copy
in class AbstractCachingDiffFunction
public void decrementBatch(int batchSize)
batchSize
- public void incrementBatch(int batchSize)
batchSize
- public double valueAt(double[] x, int batchSize)
x
- batchSize
-
public double[] derivativeAt(double[] x, int batchSize)
public double valueAt(double[] x, double[] v, int batchSize)
x
- v
- batchSize
-
public double[] derivativeAt(double[] x, double[] v, int batchSize)
public double[] HdotVAt(double[] x, double[] v, int batchSize)
x
- v
- batchSize
-
public double[] HdotVAt(double[] x, double[] v, double[] curDerivative, int batchSize)
public double[] HdotVAt(double[] x, double[] v)
public double[] lastDerivative()
public double lastValue()
lastValue
in class AbstractCachingDiffFunction
public void setValue(double v)
setValue
in class AbstractCachingDiffFunction
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |