forked from kevinking/Ranklibc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayer.h
83 lines (73 loc) · 1.64 KB
/
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
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
#ifndef LAYER_H
#define LAYER_H
#include <vector>
#include <iostream>
using std::vector;
using std::cout;
#include "Neuron.h"
class Layer
{
public:
Layer() { }
Layer(int n)
{
size_ = n;
neurons = new vector<Neuron*>();
for (int i = 0; i < n; i++)
neurons->push_back(new Neuron());
}
virtual ~Layer()
{
if (neurons)
{
for (std::size_t i = 0; i < neurons->size(); i++)
if(neurons->at(i))
delete neurons->at(i);
}
}
vector<Neuron*> *neurons;
int size_;
Neuron* get(int k)
{
return neurons->at(k);
}
int size()
{
return size_;
}
//
void computerDeltaForOutputlayer(PropParameter *param)
{
for (std::size_t i = 0; i < neurons->size(); i++)
{
neurons->at(i)->computerDeltaOfOuputLayer(param);
}
}
void updateDelta(PropParameter *param)
{
for (std::size_t i = 0; i < neurons->size(); i++)
neurons->at(i)->updateDelta(param);
}
void updateWeight(PropParameter *param)
{
for (std::size_t i = 0; i < neurons->size(); i++)
neurons->at(i)->updateWeight(param);
}
void computeOutput()
{
for (vector<Neuron*>::iterator it = neurons->begin(); it != neurons->end(); it++)
{
(*it)->computeOutput();
}
}
void computeOutput(int i)
{
for (vector<Neuron*>::iterator it = neurons->begin(); it != neurons->end(); it++)
{
(*it)->computeOutput(i);
}
}
protected:
private:
};
#endif // LAYER_H