nnlib
GPU-accelerated, C/C++ neural network library.
network.h
Go to the documentation of this file.
1 
8 #ifndef NNLIB_NETWORK_H
9 #define NNLIB_NETWORK_H
10 
11 #include "layer.h"
12 #include "loss.h"
13 #include <vector>
14 
18 #define NO_SEED (-1)
19 
23 class Network {
30 
34  std::vector<Layer> layers;
35 
39  long long seed;
40 
48  size_t previousSize;
49 
60 public:
61  explicit Network(size_t inputSize, bool useGPU = true, long long seed = NO_SEED);
62 
73  void add(size_t numNeurons, const std::string& activation = "linear");
74 
83  sTensor forward(const sTensor& batch);
84 
99  //NOLINTNEXTLINE(readability-identifier-naming)
100  void train(sTensor& X, sTensor& y, int epochs, size_t batchSize, float learningRate, Loss* loss,
101  std::vector<Metric*>& metrics);
102 
103 private:
118  void processEpoch(std::vector<sTensor>& batches, std::vector<sTensor>& targets, std::vector<sTensor>& targetsOnHost,
119  float learningRate, Loss* loss, std::vector<Metric*>& metrics);
120 };
121 
122 
123 #endif //NNLIB_NETWORK_H
DataLocation
Enumerate to specify where data is located.
Definition: cache.h:24
Abstract class representing a loss function.
Definition: loss.h:21
Represents a neural network.
Definition: network.h:23
DataLocation location
The location of the network.
Definition: network.h:29
sTensor forward(const sTensor &batch)
Forward-propagate a batch through the network.
Definition: network.cpp:186
void train(sTensor &X, sTensor &y, int epochs, size_t batchSize, float learningRate, Loss *loss, std::vector< Metric * > &metrics)
Train the network.
Definition: network.cpp:198
std::vector< Layer > layers
List of network layers.
Definition: network.h:34
long long seed
Seed used for random initialization.
Definition: network.h:39
void processEpoch(std::vector< sTensor > &batches, std::vector< sTensor > &targets, std::vector< sTensor > &targetsOnHost, float learningRate, Loss *loss, std::vector< Metric * > &metrics)
Trains the model on a single epoch.
Definition: network.cpp:229
void add(size_t numNeurons, const std::string &activation="linear")
Add a new layer to the network.
Definition: network.cpp:178
size_t previousSize
Keeps track of the size of the previous layer.
Definition: network.h:48
Network(size_t inputSize, bool useGPU=true, long long seed=NO_SEED)
Construct a new network.
Definition: network.cpp:166
Header file declaring the Layer class.
Header file declaring different loss functions.
#define NO_SEED
Integer to mean that no seed was specified for the network.
Definition: network.h:18