23 SGD(
double lr,
double decay = 0.0,
double momentum = 0.0) :
Optimizer(lr, decay),
24 _momentum(momentum) {}
33 Eigen::MatrixXd weights = layer->weights();
34 Eigen::MatrixXd biases = layer->biases();
35 Eigen::MatrixXd dweights = layer->dweights();
36 Eigen::MatrixXd dbiases = layer->dbiases();
38 Eigen::MatrixXd weights_updates;
39 Eigen::MatrixXd bias_updates;
42 Eigen::MatrixXd weights_momentums = layer->weights_optimizer();
43 Eigen::MatrixXd biases_momentums = layer->biases_optimizer();
45 weights_updates = _momentum * weights_momentums -
_current_lr * dweights;
47 bias_updates = _momentum * biases_momentums -
_current_lr * dbiases;
49 layer->weights_optimizer(weights_updates);
50 layer->biases_optimizer(bias_updates);
58 weights += weights_updates;
59 biases += bias_updates;
61 layer->weights(weights);
62 layer->biases(biases);
Base class for all optimizers.
Definition Optimizer.hpp:15
double _current_lr
Definition Optimizer.hpp:78
Stochastic Gradient Descent optimizer.
Definition SGD.hpp:14
SGD(double lr, double decay=0.0, double momentum=0.0)
Construct a new SGD object.
Definition SGD.hpp:23
void update_params(std::shared_ptr< Dense > &layer)
Update the parameters of the layer.
Definition SGD.hpp:31
Definition Activation.hpp:6