-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSynapse.cpp
100 lines (82 loc) · 1.99 KB
/
Synapse.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
#include "Synapse.h"
#include <cmath>
Synapse::Synapse()
{
//ctor
}
Synapse::Synapse(Neuron* target, Neuron* origin) {
this->target = target;
weight = INITIAL_SYNAPSE_WEIGHT;
lifespan = 100;
permanent = true;
next = NULL;
this->origin = origin;
// Add this connection to target.
target->addConnection(origin);
}
Synapse::Synapse(float weight, Neuron* target, Neuron* origin) {
this->target = target;
this->weight = weight;
lifespan = 2;
permanent = false;
next = NULL;
this->origin = origin;
// Add this connection to target.
target->addConnection(origin);
}
void Synapse::trigger(float value, bool train) {
target->acceptSignal(value, origin);
// Increment weight/lifespan. Use only when reinforcement of action is required. Won't need this until the system is autonomous.
//changeWeight(0.01);
if (train)
changeLifespan(LIFESPAN_INCREASE);
}
Neuron* Synapse::getTarget() {
return target;
}
void Synapse::setTarget(Neuron* target) {
this->target = target;
}
Synapse* Synapse::getNext() {
return next;
}
void Synapse::setNext(Synapse* next) {
this->next = next;
}
// Might not use.
void Synapse::depreciate(float value) {
// Decrease weight/lifespan by something related to the value (or something constant).
}
void Synapse::changeWeight(float value) {
// Adds value to the weight.
if (std::abs(weight + value) < MAX_WEIGHT) {
weight += value;
}
// char buff[50];
// sprintf(buff, "%lf ", weight);
// logger(file, buff);
// printf ("%lf ", weight);
}
void Synapse::changeLifespan(float lifespan) {
if (permanent)
this->lifespan += lifespan;
}
void Synapse::makePerm() {
permanent = true;
}
float Synapse::getWeight() {
return weight;
}
float Synapse::getLifespan() {
return lifespan;
}
Synapse::~Synapse()
{
// target->removeConnection(origin);
}
void Synapse::deleteAll() {
if (next != NULL) {
next->deleteAll();
}
delete this;
}