-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNeuron.h
98 lines (78 loc) · 2.11 KB
/
Neuron.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef NEURON_H
#define NEURON_H
#include <QtCore/QList>
#include "Link.h"
using namespace std;
/*
* Abstract class for a neuron.
*/
class Neuron
{
public:
enum Layer {
InputLayer, HiddenLayer, OutputLayer
};
explicit Neuron(int, Layer);
explicit Neuron(int, Neuron *); /* create this neuron from another one */
virtual ~Neuron();
/*
* Neuron identifier (unique inside the network)
*/
virtual int id() const;
/*
* Neuron layer (see enum above)
*/
virtual Layer layer() const;
/*
* This is used to compute the gradients.
*/
virtual double signalError() const;
/*
* The last output computed by this neuron.
*/
virtual double output() const;
/*
* Returns the connections going to or coming from this neuron, as Link classes.
*/
virtual QList< Link* > outConnections() const;
virtual QList< Link* > inConnections() const;
/*
* Manages connections.
*/
virtual void addInConnection(Link *);
virtual void removeInConnection(Link *);
virtual void addOutConnection(Link *);
virtual void removeOutConnection(Link *);
virtual void removeOutTowards(Neuron *); /* removes the link going to the specified neuron, if there is one */
virtual void setId(int);
virtual void setSignalError(double);
/*
* Each neuron computes the output in its specific way.
*/
virtual void computeOutput() = 0;
bool operator==(const Neuron &) const;
protected:
int m_id;
Layer m_layer;
double m_sigError;
double m_lastOutput;
QList< Link* > m_inConnections;
QList< Link* > m_outConnections;
};
class SigmoidNeuron : public Neuron
{
public:
explicit SigmoidNeuron(int, Neuron::Layer);
explicit SigmoidNeuron(int, Neuron *);
virtual ~SigmoidNeuron();
virtual void computeOutput();
};
class TangentNeuron : public Neuron
{
public:
explicit TangentNeuron(int, Neuron::Layer);
explicit TangentNeuron(int, Neuron *);
virtual ~TangentNeuron();
virtual void computeOutput();
};
#endif