public abstract class BaseOptimizer extends java.lang.Object implements ConvexOptimizer
Modifier and Type | Field and Description |
---|---|
protected ComputationGraphUpdater |
computationGraphUpdater |
protected NeuralNetConfiguration |
conf |
static java.lang.String |
GRADIENT_KEY |
protected java.util.Collection<IterationListener> |
iterationListeners |
protected BackTrackLineSearch |
lineMaximizer |
protected static org.slf4j.Logger |
log |
protected Model |
model |
protected double |
oldScore |
static java.lang.String |
PARAMS_KEY |
protected double |
score |
static java.lang.String |
SCORE_KEY |
static java.lang.String |
SEARCH_DIR |
protected java.util.Map<java.lang.String,java.lang.Object> |
searchState |
protected double |
step |
protected StepFunction |
stepFunction |
protected double |
stepMax |
protected java.util.Collection<TerminationCondition> |
terminationConditions |
protected Updater |
updater |
Constructor and Description |
---|
BaseOptimizer(NeuralNetConfiguration conf,
StepFunction stepFunction,
java.util.Collection<IterationListener> iterationListeners,
java.util.Collection<TerminationCondition> terminationConditions,
Model model) |
BaseOptimizer(NeuralNetConfiguration conf,
StepFunction stepFunction,
java.util.Collection<IterationListener> iterationListeners,
Model model) |
Modifier and Type | Method and Description |
---|---|
int |
batchSize()
The batch size for the optimizer
|
boolean |
checkTerminalConditions(org.nd4j.linalg.api.ndarray.INDArray gradient,
double oldScore,
double score,
int i)
Check termination conditions
setup a search state
|
ComputationGraphUpdater |
getComputationGraphUpdater() |
NeuralNetConfiguration |
getConf() |
static StepFunction |
getDefaultStepFunctionForOptimizer(java.lang.Class<? extends ConvexOptimizer> optimizerClass) |
static int |
getIterationCount(Model model) |
Updater |
getUpdater() |
Pair<Gradient,java.lang.Double> |
gradientAndScore()
The gradient and score for this optimizer
|
static void |
incrementIterationCount(Model model,
int incrementBy) |
boolean |
optimize()
Optimize call.
|
protected void |
postFirstStep(org.nd4j.linalg.api.ndarray.INDArray gradient) |
void |
postStep(org.nd4j.linalg.api.ndarray.INDArray gradient)
Post step to update searchDirection with new gradient and parameter information
|
void |
preProcessLine()
Pre preProcess to setup initial searchDirection approximation
|
double |
score()
The score for the optimizer so far
|
void |
setBatchSize(int batchSize)
Set the batch size for the optimizer
|
void |
setListeners(java.util.Collection<IterationListener> listeners) |
void |
setUpdater(Updater updater) |
void |
setUpdaterComputationGraph(ComputationGraphUpdater updater) |
void |
setupSearchState(Pair<Gradient,java.lang.Double> pair)
Setup the initial search state
|
void |
updateGradientAccordingToParams(Gradient gradient,
Model model,
int batchSize)
Update the gradient according to the configuration such as adagrad, momentum, and sparsity
|
protected NeuralNetConfiguration conf
protected static final org.slf4j.Logger log
protected StepFunction stepFunction
protected java.util.Collection<IterationListener> iterationListeners
protected java.util.Collection<TerminationCondition> terminationConditions
protected Model model
protected BackTrackLineSearch lineMaximizer
protected Updater updater
protected ComputationGraphUpdater computationGraphUpdater
protected double step
protected double score
protected double oldScore
protected double stepMax
public static final java.lang.String GRADIENT_KEY
public static final java.lang.String SCORE_KEY
public static final java.lang.String PARAMS_KEY
public static final java.lang.String SEARCH_DIR
protected java.util.Map<java.lang.String,java.lang.Object> searchState
public BaseOptimizer(NeuralNetConfiguration conf, StepFunction stepFunction, java.util.Collection<IterationListener> iterationListeners, Model model)
conf
- stepFunction
- iterationListeners
- model
- public BaseOptimizer(NeuralNetConfiguration conf, StepFunction stepFunction, java.util.Collection<IterationListener> iterationListeners, java.util.Collection<TerminationCondition> terminationConditions, Model model)
conf
- stepFunction
- iterationListeners
- terminationConditions
- model
- public double score()
ConvexOptimizer
score
in interface ConvexOptimizer
public Updater getUpdater()
getUpdater
in interface ConvexOptimizer
public void setUpdater(Updater updater)
setUpdater
in interface ConvexOptimizer
public ComputationGraphUpdater getComputationGraphUpdater()
getComputationGraphUpdater
in interface ConvexOptimizer
public void setUpdaterComputationGraph(ComputationGraphUpdater updater)
setUpdaterComputationGraph
in interface ConvexOptimizer
public void setListeners(java.util.Collection<IterationListener> listeners)
setListeners
in interface ConvexOptimizer
public NeuralNetConfiguration getConf()
getConf
in interface ConvexOptimizer
public Pair<Gradient,java.lang.Double> gradientAndScore()
ConvexOptimizer
gradientAndScore
in interface ConvexOptimizer
public boolean optimize()
optimize
in interface ConvexOptimizer
protected void postFirstStep(org.nd4j.linalg.api.ndarray.INDArray gradient)
public boolean checkTerminalConditions(org.nd4j.linalg.api.ndarray.INDArray gradient, double oldScore, double score, int i)
ConvexOptimizer
checkTerminalConditions
in interface ConvexOptimizer
gradient
- layer gradientsi
- what iteration the optimizer is onpublic int batchSize()
ConvexOptimizer
batchSize
in interface ConvexOptimizer
public void setBatchSize(int batchSize)
ConvexOptimizer
setBatchSize
in interface ConvexOptimizer
public void preProcessLine()
preProcessLine
in interface ConvexOptimizer
public void postStep(org.nd4j.linalg.api.ndarray.INDArray gradient)
postStep
in interface ConvexOptimizer
public void updateGradientAccordingToParams(Gradient gradient, Model model, int batchSize)
ConvexOptimizer
updateGradientAccordingToParams
in interface ConvexOptimizer
gradient
- the gradient to modifymodel
- the model with the parameters to updatebatchSize
- batchSize for updatepublic void setupSearchState(Pair<Gradient,java.lang.Double> pair)
setupSearchState
in interface ConvexOptimizer
pair
- public static StepFunction getDefaultStepFunctionForOptimizer(java.lang.Class<? extends ConvexOptimizer> optimizerClass)
public static int getIterationCount(Model model)
public static void incrementIterationCount(Model model, int incrementBy)