Class BaseOptimizer
- java.lang.Object
-
- org.deeplearning4j.optimize.solvers.BaseOptimizer
-
- All Implemented Interfaces:
Serializable
,ConvexOptimizer
- Direct Known Subclasses:
ConjugateGradient
,LBFGS
,LineGradientDescent
,StochasticGradientDescent
public abstract class BaseOptimizer extends Object implements ConvexOptimizer
Base optimizer- Author:
- Adam Gibson
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected GradientsAccumulator
accumulator
protected ComputationGraphUpdater
computationGraphUpdater
protected NeuralNetConfiguration
conf
static String
GRADIENT_KEY
protected BackTrackLineSearch
lineMaximizer
protected static org.slf4j.Logger
log
protected Model
model
protected double
oldScore
static String
PARAMS_KEY
protected double
score
static String
SCORE_KEY
static String
SEARCH_DIR
protected Map<String,Object>
searchState
protected double
step
protected StepFunction
stepFunction
protected double
stepMax
protected Collection<TrainingListener>
trainingListeners
protected Updater
updater
-
Constructor Summary
Constructors Constructor Description BaseOptimizer(NeuralNetConfiguration conf, StepFunction stepFunction, Collection<TrainingListener> trainingListeners, Model model)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
applyConstraints(Model model)
int
batchSize()
The batch size for the optimizerComputationGraphUpdater
getComputationGraphUpdater()
ComputationGraphUpdater
getComputationGraphUpdater(boolean initializIfReq)
NeuralNetConfiguration
getConf()
static StepFunction
getDefaultStepFunctionForOptimizer(Class<? extends ConvexOptimizer> optimizerClass)
static int
getEpochCount(Model model)
GradientsAccumulator
getGradientsAccumulator()
This method returns GradientsAccumulator instance used in this optimizer.static int
getIterationCount(Model model)
Updater
getUpdater()
Updater
getUpdater(boolean initializeIfReq)
Pair<Gradient,Double>
gradientAndScore(LayerWorkspaceMgr workspaceMgr)
The gradient and score for this optimizerstatic void
incrementIterationCount(Model model, int incrementBy)
boolean
optimize(LayerWorkspaceMgr workspaceMgr)
Optimize call.protected void
postFirstStep(INDArray gradient)
void
postStep(INDArray gradient)
Post step to update searchDirection with new gradient and parameter informationvoid
preProcessLine()
Pre preProcess to setup initial searchDirection approximationdouble
score()
The score for the optimizer so farvoid
setBatchSize(int batchSize)
Set the batch size for the optimizervoid
setGradientsAccumulator(GradientsAccumulator accumulator)
This method specifies GradientsAccumulator instance to be used for updates sharing across multiple modelsvoid
setListeners(Collection<TrainingListener> listeners)
void
setUpdater(Updater updater)
void
setUpdaterComputationGraph(ComputationGraphUpdater updater)
void
setupSearchState(Pair<Gradient,Double> pair)
Setup the initial search statevoid
updateGradientAccordingToParams(Gradient gradient, Model model, int batchSize, LayerWorkspaceMgr workspaceMgr)
Update the gradient according to the configuration such as adagrad, momentum, and sparsity-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.deeplearning4j.optimize.api.ConvexOptimizer
getStepFunction
-
-
-
-
Field Detail
-
conf
protected NeuralNetConfiguration conf
-
log
protected static final org.slf4j.Logger log
-
stepFunction
protected StepFunction stepFunction
-
trainingListeners
protected Collection<TrainingListener> trainingListeners
-
model
protected Model model
-
lineMaximizer
protected BackTrackLineSearch lineMaximizer
-
updater
protected Updater updater
-
computationGraphUpdater
protected ComputationGraphUpdater computationGraphUpdater
-
step
protected double step
-
score
protected double score
-
oldScore
protected double oldScore
-
stepMax
protected double stepMax
-
GRADIENT_KEY
public static final String GRADIENT_KEY
- See Also:
- Constant Field Values
-
SCORE_KEY
public static final String SCORE_KEY
- See Also:
- Constant Field Values
-
PARAMS_KEY
public static final String PARAMS_KEY
- See Also:
- Constant Field Values
-
SEARCH_DIR
public static final String SEARCH_DIR
- See Also:
- Constant Field Values
-
accumulator
protected GradientsAccumulator accumulator
-
-
Constructor Detail
-
BaseOptimizer
public BaseOptimizer(NeuralNetConfiguration conf, StepFunction stepFunction, Collection<TrainingListener> trainingListeners, Model model)
- Parameters:
conf
-stepFunction
-trainingListeners
-model
-
-
-
Method Detail
-
setGradientsAccumulator
public void setGradientsAccumulator(GradientsAccumulator accumulator)
Description copied from interface:ConvexOptimizer
This method specifies GradientsAccumulator instance to be used for updates sharing across multiple models- Specified by:
setGradientsAccumulator
in interfaceConvexOptimizer
-
getGradientsAccumulator
public GradientsAccumulator getGradientsAccumulator()
Description copied from interface:ConvexOptimizer
This method returns GradientsAccumulator instance used in this optimizer. This method can return null.- Specified by:
getGradientsAccumulator
in interfaceConvexOptimizer
- Returns:
-
score
public double score()
Description copied from interface:ConvexOptimizer
The score for the optimizer so far- Specified by:
score
in interfaceConvexOptimizer
- Returns:
- the score for this optimizer so far
-
getUpdater
public Updater getUpdater()
- Specified by:
getUpdater
in interfaceConvexOptimizer
-
getUpdater
public Updater getUpdater(boolean initializeIfReq)
- Specified by:
getUpdater
in interfaceConvexOptimizer
-
setUpdater
public void setUpdater(Updater updater)
- Specified by:
setUpdater
in interfaceConvexOptimizer
-
getComputationGraphUpdater
public ComputationGraphUpdater getComputationGraphUpdater()
- Specified by:
getComputationGraphUpdater
in interfaceConvexOptimizer
-
getComputationGraphUpdater
public ComputationGraphUpdater getComputationGraphUpdater(boolean initializIfReq)
- Specified by:
getComputationGraphUpdater
in interfaceConvexOptimizer
-
setUpdaterComputationGraph
public void setUpdaterComputationGraph(ComputationGraphUpdater updater)
- Specified by:
setUpdaterComputationGraph
in interfaceConvexOptimizer
-
setListeners
public void setListeners(Collection<TrainingListener> listeners)
- Specified by:
setListeners
in interfaceConvexOptimizer
-
getConf
public NeuralNetConfiguration getConf()
- Specified by:
getConf
in interfaceConvexOptimizer
-
gradientAndScore
public Pair<Gradient,Double> gradientAndScore(LayerWorkspaceMgr workspaceMgr)
Description copied from interface:ConvexOptimizer
The gradient and score for this optimizer- Specified by:
gradientAndScore
in interfaceConvexOptimizer
- Returns:
- the gradient and score for this optimizer
-
optimize
public boolean optimize(LayerWorkspaceMgr workspaceMgr)
Optimize call. This runs the optimizer.- Specified by:
optimize
in interfaceConvexOptimizer
- Returns:
- whether it converged or not
-
postFirstStep
protected void postFirstStep(INDArray gradient)
-
batchSize
public int batchSize()
Description copied from interface:ConvexOptimizer
The batch size for the optimizer- Specified by:
batchSize
in interfaceConvexOptimizer
- Returns:
-
setBatchSize
public void setBatchSize(int batchSize)
Description copied from interface:ConvexOptimizer
Set the batch size for the optimizer- Specified by:
setBatchSize
in interfaceConvexOptimizer
-
preProcessLine
public void preProcessLine()
Pre preProcess to setup initial searchDirection approximation- Specified by:
preProcessLine
in interfaceConvexOptimizer
-
postStep
public void postStep(INDArray gradient)
Post step to update searchDirection with new gradient and parameter information- Specified by:
postStep
in interfaceConvexOptimizer
-
updateGradientAccordingToParams
public void updateGradientAccordingToParams(Gradient gradient, Model model, int batchSize, LayerWorkspaceMgr workspaceMgr)
Description copied from interface:ConvexOptimizer
Update the gradient according to the configuration such as adagrad, momentum, and sparsity- Specified by:
updateGradientAccordingToParams
in interfaceConvexOptimizer
- Parameters:
gradient
- the gradient to modifymodel
- the model with the parameters to updatebatchSize
- batchSize for update
-
setupSearchState
public void setupSearchState(Pair<Gradient,Double> pair)
Setup the initial search state- Specified by:
setupSearchState
in interfaceConvexOptimizer
- Parameters:
pair
-
-
getDefaultStepFunctionForOptimizer
public static StepFunction getDefaultStepFunctionForOptimizer(Class<? extends ConvexOptimizer> optimizerClass)
-
getIterationCount
public static int getIterationCount(Model model)
-
incrementIterationCount
public static void incrementIterationCount(Model model, int incrementBy)
-
getEpochCount
public static int getEpochCount(Model model)
-
applyConstraints
public static void applyConstraints(Model model)
-
-