public abstract class AbstractBatchOptimizer
extends java.lang.Object
Abstract base of all the different kinds of optimizers. This exists to both facilitate sharing test between optimizers and to share certain basic bits of functionality useful for batch optimizers, like intelligent multi-thread management and user interrupt handling.
Modifier and Type | Class and Description |
---|---|
protected class |
AbstractBatchOptimizer.OptimizationState
This is subclassed by children to store any state they need to perform optimization
|
Constructor and Description |
---|
AbstractBatchOptimizer() |
Modifier and Type | Method and Description |
---|---|
void |
addDenseConstraint(int component,
double[] arr)
This adds a constraint on the weight vector, that a certain component must be set to a dense array
|
void |
addSparseConstraint(int component,
int index,
double value)
This adds a constraint on the weight vector, that a certain component must be set to a sparse index=value
|
protected abstract AbstractBatchOptimizer.OptimizationState |
getFreshOptimizationState(ConcatVector initialWeights)
This is called at the beginning of each batch optimization.
|
<T> ConcatVector |
optimize(T[] dataset,
AbstractDifferentiableFunction<T> fn) |
<T> ConcatVector |
optimize(T[] dataset,
AbstractDifferentiableFunction<T> fn,
ConcatVector initialWeights,
double l2regularization,
double convergenceDerivativeNorm,
boolean quiet) |
abstract boolean |
updateWeights(ConcatVector weights,
ConcatVector gradient,
double logLikelihood,
AbstractBatchOptimizer.OptimizationState state,
boolean quiet)
This is the hook for subclassing batch optimizers to override in order to have their optimizer work.
|
public <T> ConcatVector optimize(T[] dataset, AbstractDifferentiableFunction<T> fn)
public <T> ConcatVector optimize(T[] dataset, AbstractDifferentiableFunction<T> fn, ConcatVector initialWeights, double l2regularization, double convergenceDerivativeNorm, boolean quiet)
public void addSparseConstraint(int component, int index, double value)
component
- the component to fixindex
- the index of the fixed sparse componentvalue
- the value to fix atpublic void addDenseConstraint(int component, double[] arr)
component
- the component to fixarr
- the dense array to setpublic abstract boolean updateWeights(ConcatVector weights, ConcatVector gradient, double logLikelihood, AbstractBatchOptimizer.OptimizationState state, boolean quiet)
weights
- the current weights (update these in place)gradient
- the gradient at these weightslogLikelihood
- the log likelihood at these weightsstate
- any saved state the optimizer wants to keep and pass around during each optimization runquiet
- whether or not to dump output about progress to the consoleprotected abstract AbstractBatchOptimizer.OptimizationState getFreshOptimizationState(ConcatVector initialWeights)
initialWeights
- the initial weights for the optimizer to use