-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinkMatrix.h
70 lines (56 loc) · 1.65 KB
/
LinkMatrix.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
/*
* This class holds all the links in a network, indexed by the identifiers of the two neurons
* connected by the link.
*
* I didn't use a matrix because I need to add and remove neurons during training, and reallocating memory for a matrix
* each time was too computationally-expensive.
*/
#ifndef LINKMATRIX_H
#define LINKMATRIX_H
#include <QMap>
#include <QPair>
#include <QHash>
#include "Link.h"
class LinkMatrix
{
public:
explicit LinkMatrix();
virtual ~LinkMatrix();
/*
* Returns the link between the neurons identified by the two parameters, or NULL
* if none exists.
*/
Link* link(int, int) const;
/*
* Returns all the pairs used as keys internally.
*/
QList< QPair<int, int> > keys() const;
/*
* Returns a list with all the links.
*/
QList< Link* > links() const;
/*
* Returns the number of links.
*/
int complexity() const;
/*
* Add a new link between two neurons.
*/
void addLink(int, int, Link *);
/*
* Remove a link between two neurons.
*/
void removeLink(int, int);
/*
* Remove all links going to or coming from @neuron. @maxId is the maximum neuron ID currently active,
* while the @neurons hash is needed to remove the link from inConnections or outConnections lists.
*/
void removeAllLinks(int neuron, int maxId, const QHash< int, Neuron* >& neurons);
/*
* This must be called when changing the ID of a neuron: updates all the links concerning it.
*/
void changeId(int oldId, int newId);
private:
QMap< QPair<int, int>, Link* > m_links;
};
#endif