Package com.jml.optimizers
Class Momentum
java.lang.Object
com.jml.optimizers.Optimizer
com.jml.optimizers.Momentum
The momentum based gradient descent optimizer. This is similar to vanilla gradient descent but will dampen oscillations
during optimization by helping accelerate the optimization in the relevant direction where the gradient may be steeper
than in other directions.
Applies the following update rule:
Applies the following update rule:
Note: If the momentum term is zero, then this optimizer is equivalent tovt = y*vt-1 + a*grad( wt )
wt+1 = wt - vt
Wherea
is the learning rate andy
is the momentum with0 <= y <= 1
Vanilla Gradient Descent
.-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionGets the details of this optimizer.linalg.Matrix[]
step(boolean flag, linalg.Matrix... params)
Steps the optimizer a single iteration by applying the update rule of the optimizer to the matrix w.linalg.Matrix[]
step(linalg.Matrix... params)
Steps the optimizer a single iteration by applying the update rule of the optimizer to the matrix w.Methods inherited from class com.jml.optimizers.Optimizer
getLearningRate, setScheduler
-
Field Details
-
OPTIM_NAME
- See Also:
- Constant Field Values
-
-
Constructor Details
-
Momentum
public Momentum(double learningRate)Creates a Momentum optimizer with specified learning rate. A default momentum of 0.9 will be used. To specify a momentum, seeMomentum(double, double)
.- Parameters:
learningRate
- The learning rate to use in the update rule of the Momentum optimizer.
-
Momentum
public Momentum(double learningRate, double momentum)Creates a Momentum optimizer with specified learning rate and momentum.- Parameters:
learningRate
- Learning rate to use when applying this optimizer.momentum
- Momentum value to use when applying this optimizer.
-
-
Method Details
-
step
public linalg.Matrix[] step(linalg.Matrix... params)Steps the optimizer a single iteration by applying the update rule of the optimizer to the matrix w.- Specified by:
step
in classOptimizer
- Parameters:
params
- An array of matrices containing strictly {w, wGrad, v} where w is a matrix containing the weights to apply the update to, wGrad is the gradient of the objective function with respect to w, and v is the update vector for the momentum optimizer.- Returns:
- The result of applying the update rule of the optimizer to the matrix w.
-
step
public linalg.Matrix[] step(boolean flag, linalg.Matrix... params)Steps the optimizer a single iteration by applying the update rule of the optimizer to the matrix w.- Specified by:
step
in classOptimizer
- Parameters:
flag
- Does nothing for the momentum optimizer.params
- An array of matrices containing strictly {w, wGrad, v} where w is a matrix containing the weights to apply the update to, wGrad is the gradient of the objective function with respect to w, and v is the update vector for the momentum optimizer.- Returns:
- The result of applying the update rule of the optimizer to the matrix w.
-
getDetails
Gets the details of this optimizer.- Specified by:
getDetails
in classOptimizer
- Returns:
- Important details of this optimizer as a string.
-