-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNeuralNetwork.cpp
107 lines (87 loc) · 2.07 KB
/
NeuralNetwork.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "NeuralNetwork.hpp"
#include <QDebug>
void NeuralNetwork::swap(NeuralNetwork &neuralNetwork) noexcept
{
m_layers.swap(neuralNetwork.m_layers);
}
bool NeuralNetwork::empty() const
{
return m_layers.empty();
}
int NeuralNetwork::layerNumber() const
{
return m_layers.size();
}
NeuralLayer &NeuralNetwork::layer(const int index)
{
Q_ASSERT(0 <= index && index < layerNumber());
return m_layers[index];
}
const NeuralLayer &NeuralNetwork::layer(const int index) const
{
Q_ASSERT(0 <= index && index < layerNumber());
return m_layers[index];
}
NeuralLayer &NeuralNetwork::inputLayer()
{
Q_ASSERT(!empty());
return m_layers.first();
}
const NeuralLayer &NeuralNetwork::inputLayer() const
{
Q_ASSERT(!empty());
return m_layers.first();
}
NeuralLayer &NeuralNetwork::outputLayer()
{
Q_ASSERT(!empty());
return m_layers.last();
}
const NeuralLayer &NeuralNetwork::outputLayer() const
{
Q_ASSERT(!empty());
return m_layers.last();
}
void NeuralNetwork::pushFront(const NeuralLayer &layer)
{
Q_ASSERT(empty() || inputNumber() == layer.outputNumber());
m_layers.push_front(layer);
}
void NeuralNetwork::pushBack(const NeuralLayer &layer)
{
Q_ASSERT(empty() || outputNumber() == layer.inputNumber());
m_layers.push_back(layer);
}
void NeuralNetwork::popFront()
{
m_layers.pop_front();
}
void NeuralNetwork::popBack()
{
m_layers.pop_back();
}
void NeuralNetwork::clear()
{
m_layers.clear();
}
void NeuralNetwork::setActivationFunction(const ActivationFunctionPointer &activationFunction)
{
for (NeuralLayer &layer: m_layers)
layer.setActivationFunction(activationFunction);
}
int NeuralNetwork::inputNumber() const
{
return inputLayer().inputNumber();
}
int NeuralNetwork::outputNumber() const
{
return outputLayer().outputNumber();
}
DataVector NeuralNetwork::transform_(const DataVector &input) const
{
DataVector v = input;
for (const NeuralLayer &layer: m_layers)
v = layer.transform(v);
return v;
}
static const int neuralNetworkId = qRegisterMetaType<NeuralNetwork>();