blob: 2d3b902679c4e5b2c6f009e8cfa00bcdf0c1ead1 (
plain)
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
|
#include "brain/neural_network.h"
#include "brain/neuron.h"
NeuralNetwork::NeuralNetwork(std::istream &&networkConfigFile, int numberOfSensors, int numberOfOutputs)
{
for (int i=0; i<numberOfSensors; ++i)
{
_sensors.push_back(std::make_shared<Sensor>(i));
}
for (int i=0; i<numberOfOutputs; ++i)
{
_outputs.push_back(std::make_shared<Neuron>(i));
}
}
void NeuralNetwork::setInput(int inputIndex, double activation)
{
for (auto sensor : _sensors)
{
if (sensor->id() == inputIndex)
{
sensor->setActivation(activation);
}
}
}
int NeuralNetwork::findMaxOutputIndex() const
{
double currentMaxActivation = 0;
int currentMaxIndex = 0;
for (auto output : _outputs)
{
double activation = output->activation();
if (activation >= currentMaxActivation)
{
currentMaxActivation = activation;
currentMaxIndex = output->id();
}
}
return currentMaxIndex;
}
|