-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathneuralnetwork.hpp
60 lines (55 loc) · 2.42 KB
/
neuralnetwork.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
#ifndef NEURALNETWORK_HPP_
#define NEURALNETWORK_HPP_
#include "denselayer.hpp"
/**
* @brief Class for neural network.
*
* @param[in] num_inputs number of input signals (training data)
* @param[in] num_hidden_layers number of hidden layers
* @param[in] num_hidden_nodes number of nodes per hidden layer
* @param[in] num_outputs number of output signals (training data)
* @param[in] ao option to select an activation method
*/
class NeuralNetwork
{
protected:
std::vector<DenseLayer> hidden_layers_;
DenseLayer output_layer_;
std::vector<std::vector<double>> train_x_in_;
std::vector<std::vector<double>> train_yref_out_;
std::vector<std::size_t> train_order_;
void check_training_data_size(void);
void init_training_order(void);
void feedforward(const std::vector<double> &input);
void backpropagate(const std::vector<double> &reference);
void optimize(const std::vector<double> &input,
const double learning_rate);
void randomize_training_order(void);
public:
NeuralNetwork(void) {}
NeuralNetwork(const std::size_t num_inputs,
const std::size_t num_hidden_layers,
const std::size_t num_hidden_nodes,
const std::size_t num_outputs,
const activation_option ao = activation_option::TANH);
~NeuralNetwork(void) { this->clear(); }
void init(const std::size_t num_inputs,
std::size_t num_hidden_layers,
std::size_t num_hidden_nodes,
const std::size_t num_outputs,
const activation_option ao = activation_option::TANH);
void add_hidden_layers(std::size_t num_hidden_layers,
std::size_t num_hidden_nodes,
const activation_option ao = activation_option::TANH);
void clear(void);
void set_training_data(const std::vector<std::vector<double>> &train_in,
const std::vector<std::vector<double>> &train_out);
void train(const std::size_t num_epochs,
const double learning_rate);
const std::vector<double> &predict(const std::vector<double> &input);
void print_result(const std::size_t num_decimals = 1,
std::ostream &ostream = std::cout);
void print_network(print_option po = print_option::LITE,
std::ostream &ostream = std::cout);
};
#endif /* NEURALNETWORK_HPP_ */