-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnn.hpp
75 lines (71 loc) · 1.89 KB
/
nn.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma once
#include <memory>
#include <vector>
#include "aliases.hpp"
#include "activations.hpp"
class NeuralNetwork {
public:
///
/// \brief NeuralNetwork constructor for a new model
/// \param layers - describes number of nodes for each layer
/// \param activation - activation function object
/// \param rate - learning rate
///
NeuralNetwork(const std::vector<size_t>& layers, std::unique_ptr<Activation> activation, double rate);
///
/// \brief NeuralNetwork constructor from dumped model or config file
/// \param fname - file name of dumped model
/// \param isDump - dump or config
///
NeuralNetwork(const std::string& fname, bool isDump);
///
/// \brief Dump
/// \param fname
/// \param isDump
///
void SaveModel(const std::string& fname, bool isDump);
///
/// \brief Destructor
///
~NeuralNetwork() {}
///
/// \brief ForwardProp
/// \param x
/// \param values
/// \param derivs
/// \return
///
RowVec ForwardProp(const RowVec& x, std::vector<RowVec>& values, std::vector<RowVec>& derivs) const;
///
/// \brief BackProp
/// \param x
/// \param y
///
std::vector<Matrix> BackProp(const RowVec& x, const RowVec& y);
///
/// \brief UpdateWeights
/// \param deltas
///
void UpdateWeights(std::vector<Matrix> deltas);
///
/// \brief Train make training step with one example
/// \param x
/// \param y
///
void Train(const RowVec& x, const RowVec& y);
const std::vector<Matrix>& GetNeurons() const;
void SetNeurons(std::vector<Matrix> neurons);
///
/// \brief Predict one example
/// \param x
/// \return
///
RowVec Predict(const RowVec& x) const;
public:
size_t XSize;
size_t YSize;
private:
std::vector<Matrix> mNeurons;
std::unique_ptr<Activation> mActivation;
double mRate;
};