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 GradientsAccumulatoraccumulatorprotected ComputationGraphUpdatercomputationGraphUpdaterprotected NeuralNetConfigurationconfstatic StringGRADIENT_KEYprotected BackTrackLineSearchlineMaximizerprotected static org.slf4j.Loggerlogprotected Modelmodelprotected doubleoldScorestatic StringPARAMS_KEYprotected doublescorestatic StringSCORE_KEYstatic StringSEARCH_DIRprotected Map<String,Object>searchStateprotected doublestepprotected StepFunctionstepFunctionprotected doublestepMaxprotected Collection<TrainingListener>trainingListenersprotected Updaterupdater
-
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 voidapplyConstraints(Model model)intbatchSize()The batch size for the optimizerComputationGraphUpdatergetComputationGraphUpdater()ComputationGraphUpdatergetComputationGraphUpdater(boolean initializIfReq)NeuralNetConfigurationgetConf()static StepFunctiongetDefaultStepFunctionForOptimizer(Class<? extends ConvexOptimizer> optimizerClass)static intgetEpochCount(Model model)GradientsAccumulatorgetGradientsAccumulator()This method returns GradientsAccumulator instance used in this optimizer.static intgetIterationCount(Model model)UpdatergetUpdater()UpdatergetUpdater(boolean initializeIfReq)Pair<Gradient,Double>gradientAndScore(LayerWorkspaceMgr workspaceMgr)The gradient and score for this optimizerstatic voidincrementIterationCount(Model model, int incrementBy)booleanoptimize(LayerWorkspaceMgr workspaceMgr)Optimize call.protected voidpostFirstStep(INDArray gradient)voidpostStep(INDArray gradient)Post step to update searchDirection with new gradient and parameter informationvoidpreProcessLine()Pre preProcess to setup initial searchDirection approximationdoublescore()The score for the optimizer so farvoidsetBatchSize(int batchSize)Set the batch size for the optimizervoidsetGradientsAccumulator(GradientsAccumulator accumulator)This method specifies GradientsAccumulator instance to be used for updates sharing across multiple modelsvoidsetListeners(Collection<TrainingListener> listeners)voidsetUpdater(Updater updater)voidsetUpdaterComputationGraph(ComputationGraphUpdater updater)voidsetupSearchState(Pair<Gradient,Double> pair)Setup the initial search statevoidupdateGradientAccordingToParams(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:ConvexOptimizerThis method specifies GradientsAccumulator instance to be used for updates sharing across multiple models- Specified by:
setGradientsAccumulatorin interfaceConvexOptimizer
-
getGradientsAccumulator
public GradientsAccumulator getGradientsAccumulator()
Description copied from interface:ConvexOptimizerThis method returns GradientsAccumulator instance used in this optimizer. This method can return null.- Specified by:
getGradientsAccumulatorin interfaceConvexOptimizer- Returns:
-
score
public double score()
Description copied from interface:ConvexOptimizerThe score for the optimizer so far- Specified by:
scorein interfaceConvexOptimizer- Returns:
- the score for this optimizer so far
-
getUpdater
public Updater getUpdater()
- Specified by:
getUpdaterin interfaceConvexOptimizer
-
getUpdater
public Updater getUpdater(boolean initializeIfReq)
- Specified by:
getUpdaterin interfaceConvexOptimizer
-
setUpdater
public void setUpdater(Updater updater)
- Specified by:
setUpdaterin interfaceConvexOptimizer
-
getComputationGraphUpdater
public ComputationGraphUpdater getComputationGraphUpdater()
- Specified by:
getComputationGraphUpdaterin interfaceConvexOptimizer
-
getComputationGraphUpdater
public ComputationGraphUpdater getComputationGraphUpdater(boolean initializIfReq)
- Specified by:
getComputationGraphUpdaterin interfaceConvexOptimizer
-
setUpdaterComputationGraph
public void setUpdaterComputationGraph(ComputationGraphUpdater updater)
- Specified by:
setUpdaterComputationGraphin interfaceConvexOptimizer
-
setListeners
public void setListeners(Collection<TrainingListener> listeners)
- Specified by:
setListenersin interfaceConvexOptimizer
-
getConf
public NeuralNetConfiguration getConf()
- Specified by:
getConfin interfaceConvexOptimizer
-
gradientAndScore
public Pair<Gradient,Double> gradientAndScore(LayerWorkspaceMgr workspaceMgr)
Description copied from interface:ConvexOptimizerThe gradient and score for this optimizer- Specified by:
gradientAndScorein interfaceConvexOptimizer- Returns:
- the gradient and score for this optimizer
-
optimize
public boolean optimize(LayerWorkspaceMgr workspaceMgr)
Optimize call. This runs the optimizer.- Specified by:
optimizein interfaceConvexOptimizer- Returns:
- whether it converged or not
-
postFirstStep
protected void postFirstStep(INDArray gradient)
-
batchSize
public int batchSize()
Description copied from interface:ConvexOptimizerThe batch size for the optimizer- Specified by:
batchSizein interfaceConvexOptimizer- Returns:
-
setBatchSize
public void setBatchSize(int batchSize)
Description copied from interface:ConvexOptimizerSet the batch size for the optimizer- Specified by:
setBatchSizein interfaceConvexOptimizer
-
preProcessLine
public void preProcessLine()
Pre preProcess to setup initial searchDirection approximation- Specified by:
preProcessLinein interfaceConvexOptimizer
-
postStep
public void postStep(INDArray gradient)
Post step to update searchDirection with new gradient and parameter information- Specified by:
postStepin interfaceConvexOptimizer
-
updateGradientAccordingToParams
public void updateGradientAccordingToParams(Gradient gradient, Model model, int batchSize, LayerWorkspaceMgr workspaceMgr)
Description copied from interface:ConvexOptimizerUpdate the gradient according to the configuration such as adagrad, momentum, and sparsity- Specified by:
updateGradientAccordingToParamsin 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:
setupSearchStatein 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)
-
-