OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
back_propagation.h
Go to the documentation of this file.
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// B A C K P R O P A G A T I O N H E A D E R
5//
6// Artificial Intelligence Techniques SL
7// artelnics@artelnics.com
8
9#pragma once
10
11#include "tensor_utilities.h"
12
13namespace opennn
14{
15
16class Loss;
17class NeuralNetwork;
18
21{
25 BackPropagation(const Index = 0, Loss* = nullptr);
26
27 virtual ~BackPropagation() = default;
28
32 void set(const Index = 0, Loss* = nullptr);
33
36 void accumulate_output_deltas(size_t layer_index);
37
38 const NeuralNetwork* neural_network = nullptr;
39
41 vector<vector<TensorView>> gradient_views;
42
44 vector<vector<TensorView>> delta_views;
45
46 vector<vector<pair<size_t, size_t>>> consumer_edges;
47
50
53
55 void print() const;
56
57 Index batch_size = 0;
58
59 Loss* loss = nullptr;
60
61 float error = 0.0f;
62 float accuracy = 0.0f;
63 float loss_value = 0.0f;
65
66private:
67
68 void setup_delta_pool(const vector<vector<TensorSpec>>& backward_specs);
69};
70
71}
72
73// OpenNN: Open Neural Networks Library.
74// Copyright(C) 2005-2026 Artificial Intelligence Techniques, SL.
75// Licensed under the GNU Lesser General Public License v2.1 or later.
Unified loss container supporting MSE, cross-entropy, Minkowski, weighted, and regularized variants.
Definition loss.h:24
Container of layers forming a feed-forward neural network, with parameter storage and I/O.
Definition neural_network.h:20
Definition adaptive_moment_estimation.h:14
vector< vector< TensorView > > gradient_views
Definition back_propagation.h:41
Buffer gradient
Definition back_propagation.h:40
vector< vector< TensorView > > delta_views
Definition back_propagation.h:44
virtual ~BackPropagation()=default
const NeuralNetwork * neural_network
Definition back_propagation.h:38
BackPropagation(const Index=0, Loss *=nullptr)
Constructs a workspace for the given batch size and loss.
Index active_tokens_count
Definition back_propagation.h:64
Buffer delta_pool
Definition back_propagation.h:43
void print() const
Prints a human-readable summary of the workspace contents.
void accumulate_output_deltas(size_t layer_index)
Accumulates deltas from all consumer edges into the given layer's output delta.
const TensorView & get_output_delta() const
Returns the output delta of the network (gradient w.r.t. the final outputs).
float accuracy
Definition back_propagation.h:62
Index batch_size
Definition back_propagation.h:57
float loss_value
Definition back_propagation.h:63
vector< vector< pair< size_t, size_t > > > consumer_edges
Definition back_propagation.h:46
float error
Definition back_propagation.h:61
void set(const Index=0, Loss *=nullptr)
Reconfigures the workspace for a new batch size or loss; reuses allocations when possible.
TensorView & get_output_delta()
Returns the output delta of the network (gradient w.r.t. the final outputs).
Loss * loss
Definition back_propagation.h:59
Owning raw byte buffer that lives on CPU or CUDA memory, with aligned (re)allocation.
Definition tensor_utilities.h:166
Non-owning view over a tensor: pointer, shape, and data type with rich reshape helpers.
Definition tensor_utilities.h:293