-
Notifications
You must be signed in to change notification settings - Fork 7
/
NeuralNetwork.h
69 lines (51 loc) · 1.64 KB
/
NeuralNetwork.h
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
#pragma once
#include <iostream>
#include <vector>
class Neuron {
public:
Neuron(int n_weights);
~Neuron();
void activate(std::vector<float> inputs);
void transfer();
float transfer_derivative() { return static_cast<float>(m_output * (1.0 - m_output)); };
// return mutable reference to the neuron weights
std::vector<float>& get_weights(void) { return m_weights; };
float get_output(void) { return m_output; };
float get_activation(void) { return m_activation; };
float get_delta(void) { return m_delta; };
void set_delta(float delta) { m_delta = delta; };
private:
size_t m_nWeights;
std::vector<float> m_weights;
float m_activation;
float m_output;
float m_delta;
private:
void initWeights(int n_weights);
};
class Layer {
public:
Layer(int n_neurons, int n_weights);
~Layer();
// return mutable reference to the neurons
std::vector<Neuron>& get_neurons(void) { return m_neurons; };
private:
void initNeurons(int n_neurons, int n_weights);
std::vector<Neuron> m_neurons;
};
class Network {
public:
Network();
~Network();
void initialize_network(int n_inputs, int n_hidden, int n_outputs);
void add_layer(int n_neurons, int n_weights);
std::vector<float> forward_propagate(std::vector<float> inputs);
void backward_propagate_error(std::vector<float> expected);
void update_weights(std::vector<float> inputs, float l_rate);
void train(std::vector<std::vector<float>>trainings_data, float l_rate, size_t n_epoch, size_t n_outputs);
int predict(std::vector<float> input);
void display_human();
private:
size_t m_nLayers;
std::vector<Layer> m_layers;
};