forked from cryptixcoder/neural-ocr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayer.h
48 lines (40 loc) · 982 Bytes
/
Layer.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
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
class Layer {
private:
int numNeurons;
std::vector<Neuron*>* neurons;
public:
Layer() {}
// Create the vector of neurons for this layer.
Layer(int neuronCount, int inputsPerNeuron) {
numNeurons = neuronCount;
neurons = new std::vector<Neuron*>(numNeurons);
for (int i = 0; i < neuronCount; i++) {
(*neurons)[i] = new Neuron(inputsPerNeuron);
}
}
~Layer() {
for (int i = 0; i < neurons->size(); i++) {
delete (*neurons)[i];
}
delete neurons;
}
// Get the number of neurons in this layer.
int neuronCount() const {
return numNeurons;
}
// Get the neuron at the given position.
Neuron *getNeuron(int n) const {
return (*neurons)[n];
}
void printNeurons() {
for (int i = 0; i < neurons->size(); i++) {
std::cout << "Neuron #" << i << "\n";
(*neurons)[i]->printWeights();
}
std::cout << "\n\n";
}
};