OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
stochastic_gradient_descent.h
Go to the documentation of this file.
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// S T O C H A S T I C G R A D I E N T D E S C E N T C L A S S H E A D E R
5//
6// Artificial Intelligence Techniques SL
7// artelnics@artelnics.com
8
9#pragma once
10
11#include "optimizer.h"
12
13namespace opennn
14{
15
16struct BackPropagation;
17
20{
21
22public:
23
26
29
32
34 void set_batch_size(const Index);
35
37 Index get_samples_number() const;
38
40 void set_initial_learning_rate(const float);
42 void set_initial_decay(const float);
44 void set_momentum(const float);
46 void set_nesterov(bool);
47
50
53
55 void from_JSON(const JsonDocument&) override;
56
58 void to_JSON(JsonWriter&) const override;
59
60private:
61
62 float initial_learning_rate;
63
64 float initial_decay;
65
66 float momentum = 0.0f;
67
68 bool nesterov = false;
69
70 Index batch_size = 0;
71};
72
73}
74
75// OpenNN: Open Neural Networks Library.
76// Copyright(C) 2005-2026 Artificial Intelligence Techniques, SL.
77// Licensed under the GNU Lesser General Public License v2.1 or later.
Definition json.h:72
Definition json.h:85
Unified loss container supporting MSE, cross-entropy, Minkowski, weighted, and regularized variants.
Definition loss.h:24
Optimizer(Loss *=nullptr)
Constructs an optimizer optionally bound to a Loss instance.
void set_batch_size(const Index)
Sets the minibatch size used by train().
void set_nesterov(bool)
Enables or disables Nesterov-accelerated momentum.
void set_initial_decay(const float)
Sets the learning-rate decay applied each epoch.
void to_JSON(JsonWriter &) const override
Serializes hyperparameters to JSON.
void set_default()
Resets all hyperparameters (learning rate, decay, momentum, Nesterov) to library defaults.
void update_parameters(BackPropagation &, OptimizerData &, float) const
Applies one SGD update to the network parameters using the gradient and current learning rate.
void set_initial_learning_rate(const float)
Sets the initial learning rate eta_0.
Index get_samples_number() const
Returns the number of training samples seen by the bound dataset.
TrainingResults train() override
Runs the SGD training loop and returns the recorded error history.
StochasticGradientDescent(Loss *=nullptr)
Constructs SGD optionally bound to a Loss instance.
void from_JSON(const JsonDocument &) override
Restores hyperparameters from a JSON document.
DataSlot
Slot index into the optimizer scratch buffer (momentum velocity).
Definition stochastic_gradient_descent.h:25
@ Velocity
Definition stochastic_gradient_descent.h:25
void set_momentum(const float)
Sets the momentum coefficient (0 disables momentum).
Definition adaptive_moment_estimation.h:14
Workspace holding parameter gradients and per-layer deltas during a backward pass.
Definition back_propagation.h:21
Per-optimizer scratch state (moments, directions, iteration counter) backing the update step.
Definition optimizer.h:182
History and final metrics produced by a training run.
Definition optimizer.h:204