NeuralNet 1.0
Loading...
Searching...
No Matches
SGD.hpp
1#pragma once
2
3#include "Optimizer.hpp"
4
5namespace NeuralNet {
9class SGD : public Optimizer {
10 public:
11 SGD(double alpha) : Optimizer(alpha){};
12
13 ~SGD() override = default;
14
15 void updateWeights(Eigen::MatrixXd &weights,
16 const Eigen::MatrixXd &weightsGrad) override {
17 weights = weights.array() - (this->alpha * weightsGrad).array();
18 };
19
20 void updateBiases(Eigen::MatrixXd &biases,
21 const Eigen::MatrixXd &biasesGrad) override {
22 biases = biases.array() - (this->alpha * biasesGrad).array();
23 };
24
25 private:
26 void insiderInit(size_t size) override{};
27};
28} // namespace NeuralNet
Definition Optimizer.hpp:6
Definition SGD.hpp:9
void updateWeights(Eigen::MatrixXd &weights, const Eigen::MatrixXd &weightsGrad) override
This function updates the weights passed based on the selected Optimizer and the weights gradients.
Definition SGD.hpp:15
void updateBiases(Eigen::MatrixXd &biases, const Eigen::MatrixXd &biasesGrad) override
This function updates the biases passed based based on the Optimizer and the biases gradients.
Definition SGD.hpp:20