nnlib
GPU-accelerated, C/C++ neural network library.
layer.h
Go to the documentation of this file.
1 
8 #ifndef NNLIB_LAYER_H
9 #define NNLIB_LAYER_H
10 
11 #include "tensor.h"
12 #include <string>
13 
17 class Layer {
23 public:
25 
31  size_t outSize;
32 
38  size_t inSize;
39 
45  std::string activation;
46 
50  sTensor weights;
51 
55  sTensor biases;
56 
68  Layer(size_t inSize, size_t outSize, std::string activation, DataLocation location);
69 
73  ~Layer();
74 
84  // You might want to ignore the return value of forward, so don't use [[nodiscard]]
85  // NOLINTNEXTLINE(modernize-use-nodiscard)
86  sTensor forward(const sTensor& batch) const;
87 
96  void applyGradients(size_t batchSize, float learningRate = 0.01);
97 };
98 
99 #endif //NNLIB_LAYER_H
DataLocation
Enumerate to specify where data is located.
Definition: cache.h:24
Represents a single layer of a neural network.
Definition: layer.h:17
size_t outSize
The output size of the layer.
Definition: layer.h:31
~Layer()
The destructor of the layer object.
DataLocation location
The location of the layer.
Definition: layer.h:24
sTensor biases
The biases of the layer. Stored as a vector.
Definition: layer.h:55
size_t inSize
The input size to the layer.
Definition: layer.h:38
sTensor forward(const sTensor &batch) const
Forward one batch of data through the layer.
Definition: layer.cpp:86
Layer(size_t inSize, size_t outSize, std::string activation, DataLocation location)
Construct a new layer.
Definition: layer.cpp:68
std::string activation
The activation function.
Definition: layer.h:45
void applyGradients(size_t batchSize, float learningRate=0.01)
Apply the computed gradients.
Definition: layer.cpp:98
sTensor weights
The weights of the layer. Stored as a matrix.
Definition: layer.h:50
Header file declaring the Tensor class to represent multidimensional arrays.