-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneuron.cpp
More file actions
86 lines (72 loc) · 1.69 KB
/
neuron.cpp
File metadata and controls
86 lines (72 loc) · 1.69 KB
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
#include "neuron.h"
Neuron::Neuron(int t) : threshold(t){}
Neuron::~Neuron(){}
int Neuron::thresholdFunc() const
{
return this->value >= this->threshold ? 1 : 0;
}
void Neuron::setValue(int val)
{
this->value = val;
}
void Neuron::incValue()
{
this->addValue(1);
}
void Neuron::addValue(int n)
{
this->value += n;
}
int Neuron::getValue() const
{
return this->value;
}
QList<int> Neuron::getLinks() const
{
return this->links;
}
Sensor::Sensor(int edges) : Neuron()
{
for(int i = 0; i < edges; ++i)
// инициализация весов S-A в интервале [-1,1]
this->links << qrand() % 3 - 1;
}
Associative::Associative(int edges, int weight) : Neuron(qrand() % 3 - 1)
{
// задание случайного порога
// this->threshold = qrand() % 3 - 1;
for (int i = 0; i < edges; ++i)
// инициализация весов значениями weight
this->links << weight;
}
void Associative::setLinkWeight(int idx, int weight)
{
this->links[idx] = weight;
}
Resulting::Resulting(int t) : Neuron(t){}
Layer::Layer(LayerType type, int cnt, int out)
{
this->type = type;
switch (type) {
case SensorType:
for(int i = 0; i < cnt; ++i)
this->neurons << new Sensor(out);
break;
case AssociativeType:
for(int i = 0; i < cnt; ++i)
this->neurons << new Associative(out,/*qrand() % 3 - */1);
break;
case ResultingType:
for(int i = 0; i < cnt; ++i)
this->neurons << new Resulting(0);
break;
default:
break;
}
}
void Layer::setValue(int val)
{
foreach (Neuron* n, this->neurons) {
n->setValue(val);
}
}