public abstract class AbstractStochasticCachingDiffFunction extends AbstractCachingDiffFunction
Modifier and Type | Class and Description |
---|---|
static class |
AbstractStochasticCachingDiffFunction.SamplingMethod |
Modifier and Type | Field and Description |
---|---|
protected java.util.List<java.lang.Integer> |
allIndices |
protected int |
curElement |
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 java.util.Random |
randGenerator |
boolean |
recalculatePrevBatch |
boolean |
returnPreviousValues |
AbstractStochasticCachingDiffFunction.SamplingMethod |
sampleMethod |
protected boolean |
scaleUp |
protected int[] |
thisBatch |
protected double[] |
xPerturbed |
derivative, value
Constructor and Description |
---|
AbstractStochasticCachingDiffFunction() |
Modifier and Type | Method and Description |
---|---|
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 :-).
|
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) |
protected void |
getBatch(int batchSize)
getBatch is used to generate the next sequence of indices to be passed to the actual function.
|
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) |
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.
|
calculate, copy, derivativeAt, ensure, getDerivative, gradientCheck, gradientCheck, randomInitial, valueAt
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
domainDimension
public boolean hasNewVals
public boolean recalculatePrevBatch
public boolean returnPreviousValues
protected int lastBatchSize
protected int[] lastBatch
protected int[] thisBatch
protected double[] lastXBatch
protected double[] lastVBatch
protected int lastElement
protected double[] HdotV
protected double[] gradPerturbed
protected double[] xPerturbed
protected int curElement
protected java.util.List<java.lang.Integer> allIndices
protected java.util.Random randGenerator
protected boolean scaleUp
public StochasticCalculateMethods method
public AbstractStochasticCachingDiffFunction.SamplingMethod sampleMethod
protected double finiteDifferenceStepSize
public AbstractStochasticCachingDiffFunction()
public void incrementRandom(int numTimes)
public void scaleUp(boolean toScaleUp)
public 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 implementation.public abstract int dataDimension()
protected void clearCache()
clearCache
in class AbstractCachingDiffFunction
public double[] initial()
HasInitial
initial
in interface HasInitial
initial
in class AbstractCachingDiffFunction
public void decrementBatch(int batchSize)
public void incrementBatch(int batchSize)
protected void getBatch(int batchSize)
public double valueAt(double[] x, int batchSize)
public double[] derivativeAt(double[] x, int batchSize)
public double valueAt(double[] x, double[] v, int batchSize)
public double[] derivativeAt(double[] x, double[] v, int batchSize)
public double[] HdotVAt(double[] x, double[] v, int 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