NNFS
Neural network library from scratch
|
#include <Dense.hpp>
Public Member Functions | |
Dense (int n_input, int n_output, double l1_weights_regularizer=.0, double l1_biases_regularizer=.0, double l2_weights_regularizer=.0, double l2_biases_regularizer=.0) | |
Construct a new Dense object. | |
void | forward (Eigen::MatrixXd &out, const Eigen::MatrixXd &x) |
Forward pass of the dense layer. | |
void | backward (Eigen::MatrixXd &out, const Eigen::MatrixXd &dx) |
Backward pass of the dense layer. | |
const Eigen::MatrixXd & | weights () const |
Get weights. | |
const Eigen::MatrixXd & | biases () const |
Get biases. | |
const Eigen::MatrixXd & | dweights () const |
Get weights gradients. | |
const Eigen::MatrixXd & | dbiases () const |
Get biases gradients. | |
void | weights (Eigen::MatrixXd &weights) |
Set's the weights of the dense layer. | |
void | biases (Eigen::MatrixXd &biases) |
Set's the biases of the dense layer. | |
void | weights_optimizer (Eigen::MatrixXd woptimizer) |
Set's the weights optimizer matrix of the dense layer. | |
void | biases_optimizer (Eigen::MatrixXd boptimizer) |
Set's the biases optimizer matrix of the dense layer. | |
const Eigen::MatrixXd & | weights_optimizer () const |
Get weights optimizer matrix. | |
const Eigen::MatrixXd & | biases_optimizer () const |
Get biases optimizer matrix. | |
void | weights_optimizer_additional (Eigen::MatrixXd woptimizer) |
Set's the additional weights optimizer matrix of the dense layer. | |
void | biases_optimizer_additional (Eigen::MatrixXd boptimizer) |
Set's the additional biases optimizer matrix of the dense layer. | |
const Eigen::MatrixXd & | weights_optimizer_additional () const |
Get additional weights optimizer matrix. | |
const Eigen::MatrixXd & | biases_optimizer_additional () const |
Get additional biases optimizer matrix. | |
const double & | l1_weights_regularizer () const |
Get L1 weights regularizer. | |
const double & | l2_weights_regularizer () const |
Get L2 weights regularizer. | |
const double & | l1_biases_regularizer () const |
Get L1 biases regularizer. | |
const double & | l2_biases_regularizer () const |
Get L2 biases regularizer. | |
int | parameters () const |
Calculates the number of trainable of the dense layer. | |
void | shape (int &n_input, int &n_output) const |
Gives the shape of the dense layer. | |
Public Member Functions inherited from NNFS::Layer | |
Layer (LayerType type) | |
Construct a new Layer object. | |
virtual | ~Layer ()=default |
Basic destructor. | |
virtual void | forward (Eigen::MatrixXd &out, const Eigen::MatrixXd &x)=0 |
Forward pass of the layer. | |
virtual void | backward (Eigen::MatrixXd &out, const Eigen::MatrixXd &dx)=0 |
Backward pass of the layer. | |
Additional Inherited Members | |
Public Attributes inherited from NNFS::Layer | |
LayerType | type |
Dense layer.
This class implements the dense layer. It is the most basic layer in a neural network.
|
inline |
Construct a new Dense object.
This constructor initializes the weights and biases of the layer. It also sets all regularization matrices to zero.
n_input | Number of input neurons |
n_output | Number of output neurons |
l1_weights_regularizer | L1 regularization for weights (default: 0.0) |
l1_biases_regularizer | L1 regularization for biases (default: 0.0) |
l2_weights_regularizer | L2 regularization for weights (default: 0.0) |
l2_biases_regularizer | L2 regularization for biases (default: 0.0) |
|
inlinevirtual |
Backward pass of the dense layer.
[out] | out | Input gradient |
[in] | dx | Output gradient |
Implements NNFS::Layer.
|
inline |
Get biases.
|
inline |
Set's the biases of the dense layer.
This function sets the biases of the dense layer. The shape of the new biases matrix must match the shape of the initial biases matrix.
[in] | biases | New biases matrix |
std::invalid_argument | if the shape of the new biases matrix does not match the shape of the initial biases matrix. |
|
inline |
Get biases optimizer matrix.
|
inline |
Set's the biases optimizer matrix of the dense layer.
boptimizer | New biases optimizer matrix |
|
inline |
Get additional biases optimizer matrix.
|
inline |
Set's the additional biases optimizer matrix of the dense layer.
boptimizer | New additional biases optimizer matrix |
|
inline |
Get biases gradients.
|
inline |
Get weights gradients.
|
inlinevirtual |
Forward pass of the dense layer.
[out] | out | Output of the layer |
[in] | x | Input of the layer |
Implements NNFS::Layer.
|
inline |
Get L1 biases regularizer.
|
inline |
Get L1 weights regularizer.
|
inline |
Get L2 biases regularizer.
|
inline |
Get L2 weights regularizer.
|
inline |
Calculates the number of trainable of the dense layer.
|
inline |
Gives the shape of the dense layer.
[out] | n_input | Number of input neurons |
[out] | n_output | Number of output neurons |
|
inline |
Get weights.
|
inline |
Set's the weights of the dense layer.
This function sets the weights of the dense layer. The shape of the new weights matrix must match the shape of the initial weights matrix.
[in] | weights | New weights matrix |
std::invalid_argument | if the shape of the new weights matrix does not match the shape of the initial weights matrix. |
|
inline |
Get weights optimizer matrix.
|
inline |
Set's the weights optimizer matrix of the dense layer.
woptimizer | New weights optimizer matrix |
|
inline |
Get additional weights optimizer matrix.
|
inline |
Set's the additional weights optimizer matrix of the dense layer.
woptimizer | New additional weights optimizer matrix |