|
1 | 1 | /** |
2 | | - * @file ConnStatic.cpp |
3 | | - * |
4 | | - * @ingroup Simulator/Connections |
5 | | - * |
6 | | - * @brief The model of the small world network |
7 | | - */ |
8 | | - |
| 2 | +* @file ConnStatic.cpp |
| 3 | +* |
| 4 | +* @ingroup Simulator/Connections/Neuro |
| 5 | +* |
| 6 | +* @brief This class manages the Connections of the Neuro STDP network |
| 7 | +*/ |
9 | 8 |
|
10 | 9 | #include "ConnStatic.h" |
11 | 10 | #include "AllEdges.h" |
12 | 11 | #include "AllNeuroEdges.h" |
13 | 12 | #include "AllVertices.h" |
| 13 | +#include "GraphManager.h" |
14 | 14 | #include "OperationManager.h" |
15 | 15 | #include "ParameterManager.h" |
16 | 16 | #include "ParseParamError.h" |
|
22 | 22 |
|
23 | 23 | #include <algorithm> |
24 | 24 |
|
| 25 | +/// @brief Default constructor for ConnStatic |
25 | 26 | ConnStatic::ConnStatic() |
26 | 27 | { |
27 | | - threshConnsRadius_ = 0; |
28 | | - connsPerVertex_ = 0; |
29 | | - rewiringProbability_ = 0; |
30 | | - radiiSize_ = 0; |
31 | 28 | } |
32 | 29 |
|
33 | | -/// Setup the internal structure of the class (allocate memories and initialize them). |
34 | | -/// Initialize the small world network characterized by parameters: |
35 | | -/// number of maximum connections per vertex, connection radius threshold, and |
36 | | -/// small-world rewiring probability. |
| 30 | +/// @brief Set up the connections in the network |
37 | 31 | void ConnStatic::setup() |
38 | 32 | { |
39 | | - // we can obtain the Layout, which holds the vertices, from the Model |
| 33 | + int added = 0; |
| 34 | + LOG4CPLUS_INFO(fileLogger_, "Initializing connections"); |
| 35 | + |
| 36 | + // Obtain Vertices and Layout from the Model |
40 | 37 | Layout &layout = Simulator::getInstance().getModel().getLayout(); |
41 | 38 | AllVertices &vertices = layout.getVertices(); |
42 | | - |
43 | | - Simulator &simulator = Simulator::getInstance(); |
44 | | - int numVertices = simulator.getTotalVertices(); |
45 | | - vector<DistDestVertex> distDestVertices[numVertices]; |
46 | | - BGSIZE maxTotalEdges = simulator.getMaxEdgesPerVertex() * simulator.getTotalVertices(); |
47 | | - WCurrentEpoch_.resize(maxTotalEdges); |
48 | | - sourceVertexIndexCurrentEpoch_.resize(maxTotalEdges); |
49 | | - destVertexIndexCurrentEpoch_.resize(maxTotalEdges); |
| 39 | + // All Edges object for Connections |
50 | 40 | AllNeuroEdges &neuroEdges = dynamic_cast<AllNeuroEdges &>(*edges_); |
51 | 41 |
|
52 | | - radiiSize_ = numVertices; |
53 | | - int added = 0; |
54 | 42 |
|
55 | | - LOG4CPLUS_INFO(fileLogger_, "Initializing connections"); |
| 43 | + // Iterator to traverse edges |
| 44 | + GraphManager<NeuralVertexProperties>::EdgeIterator ei, ei_end; |
| 45 | + GraphManager<NeuralVertexProperties> &gm = GraphManager<NeuralVertexProperties>::getInstance(); |
56 | 46 |
|
57 | | - for (int srcVertex = 0; srcVertex < numVertices; srcVertex++) { |
58 | | - distDestVertices[srcVertex].clear(); |
59 | | - |
60 | | - // pick the connections shorter than threshConnsRadius |
61 | | - for (int destVertex = 0; destVertex < numVertices; destVertex++) { |
62 | | - if (srcVertex != destVertex) { |
63 | | - BGFLOAT dist = layout.dist_(srcVertex, destVertex); |
64 | | - if (dist <= threshConnsRadius_) { |
65 | | - DistDestVertex distDestVertex {dist, destVertex}; |
66 | | - distDestVertices[srcVertex].push_back(distDestVertex); |
67 | | - } |
68 | | - } |
69 | | - } |
70 | | - |
71 | | - // sort ascendant |
72 | | - sort(distDestVertices[srcVertex].begin(), distDestVertices[srcVertex].end()); |
73 | | - // pick the shortest connsPerVertex_ connections |
74 | | - for (BGSIZE i = 0; i < distDestVertices[srcVertex].size() && (int)i < connsPerVertex_; i++) { |
75 | | - int destVertex = distDestVertices[srcVertex][i].destVertex; |
76 | | - edgeType type = layout.edgType(srcVertex, destVertex); |
77 | | - |
78 | | - LOG4CPLUS_DEBUG(fileLogger_, |
79 | | - "Source: " << srcVertex << " Dest: " << destVertex |
80 | | - << " Dist: " << distDestVertices[srcVertex][i].dist); |
81 | | - |
82 | | - BGSIZE iEdg = edges_->addEdge(type, srcVertex, destVertex, simulator.getDeltaT()); |
83 | | - added++; |
84 | | - |
85 | | - // set edge weight |
86 | | - // TODO: we need another synaptic weight distibution mode (normal distribution) |
87 | | - if (neuroEdges.edgSign(type) > 0) { |
88 | | - neuroEdges.W_[iEdg] = initRNG.inRange(excWeight_[0], excWeight_[1]); |
89 | | - } else { |
90 | | - neuroEdges.W_[iEdg] = initRNG.inRange(inhWeight_[0], inhWeight_[1]); |
91 | | - } |
92 | | - } |
93 | | - } |
94 | | - |
95 | | - string weight_str = ""; |
96 | | - for (int i = 0; i < maxTotalEdges; i++) { |
97 | | - WCurrentEpoch_[i] = neuroEdges.W_[i]; |
98 | | - sourceVertexIndexCurrentEpoch_[i] = neuroEdges.sourceVertexIndex_[i]; |
99 | | - destVertexIndexCurrentEpoch_[i] = neuroEdges.destVertexIndex_[i]; |
| 47 | + // Initialize GraphManager and iterate through edges |
| 48 | + for (boost::tie(ei, ei_end) = gm.edges(); ei != ei_end; ++ei) { |
| 49 | + int srcVertex = gm.source(*ei); |
| 50 | + int destVertex = gm.target(*ei); |
| 51 | + double weight = gm.weight(*ei); |
| 52 | + edgeType type = layout.edgType(srcVertex, destVertex); |
| 53 | + BGFLOAT dist = layout.dist_(srcVertex, destVertex); |
100 | 54 |
|
101 | | - if (WCurrentEpoch_[i] != 0) { |
102 | | - // LOG4CPLUS_DEBUG(edgeLogger_,i << WCurrentEpoch_[i]); |
103 | | - weight_str += to_string(WCurrentEpoch_[i]) + " "; |
104 | | - } |
105 | | - } |
106 | | - // LOG4CPLUS_DEBUG(edgeLogger_, "Weights are " << weight_str); |
| 55 | + // Debug |
| 56 | + // cout << "Source: " << srcVertex << " Dest: " << destVertex << " Dist: " << dist << " Weight: " << weight << endl; |
107 | 57 |
|
108 | | - int nRewiring = added * rewiringProbability_; |
| 58 | + // Log edge data |
| 59 | + LOG4CPLUS_DEBUG(edgeLogger_, "Source: " << srcVertex << ", Dest: " << destVertex |
| 60 | + << ", Dist: " << dist << ", Weight: " << weight); |
109 | 61 |
|
110 | | - LOG4CPLUS_DEBUG(fileLogger_, "Rewiring connections: " << nRewiring); |
| 62 | + // Add edge and store weight |
| 63 | + BGSIZE iEdg |
| 64 | + = edges_->addEdge(type, srcVertex, destVertex, Simulator::getInstance().getDeltaT()); |
| 65 | + neuroEdges.W_[iEdg] = weight; |
| 66 | + added++; |
| 67 | + } |
111 | 68 |
|
| 69 | + // Log the total number of connections added |
112 | 70 | LOG4CPLUS_DEBUG(fileLogger_, "Added connections: " << added); |
| 71 | +} |
113 | 72 |
|
114 | | - // Register variable weight if need |
115 | | - // Recorder &recorder = Simulator::getInstance().getModel().getRecorder(); |
116 | | - // recorder.registerVariable("weight", WCurrentEpoch_, Recorder::UpdatedType::DYNAMIC); |
| 73 | +/// @brief Register graph properties to NeuralVertexProperties |
| 74 | +void ConnStatic::registerGraphProperties() |
| 75 | +{ |
| 76 | + Connections::registerGraphProperties(); |
| 77 | + GraphManager<NeuralVertexProperties> &gm = GraphManager<NeuralVertexProperties>::getInstance(); |
| 78 | + gm.registerProperty("source", &NeuralEdgeProperties::source); |
| 79 | + gm.registerProperty("target", &NeuralEdgeProperties::target); |
| 80 | + gm.registerProperty("weight", &NeuralEdgeProperties::weight); |
117 | 81 | } |
118 | 82 |
|
119 | | -/// Load member variables from configuration file. |
120 | | -/// Registered to OperationManager as Operations::op::loadParameters |
| 83 | +/// @brief Loads parameters related to connections |
121 | 84 | void ConnStatic::loadParameters() |
122 | 85 | { |
123 | | - ParameterManager::getInstance().getBGFloatByXpath("//threshConnsRadius/text()", |
124 | | - threshConnsRadius_); |
125 | | - ParameterManager::getInstance().getIntByXpath("//connsPerNeuron/text()", connsPerVertex_); |
126 | | - ParameterManager::getInstance().getBGFloatByXpath("//rewiringProbability/text()", |
127 | | - rewiringProbability_); |
128 | | - //ParameterManager::getInstance().getBGFloatByXpath("//excWeight/min/text()", excWeight_[0]); |
129 | | - //ParameterManager::getInstance().getBGFloatByXpath("//excWeight/max/text()", excWeight_[1]); |
130 | | - //ParameterManager::getInstance().getBGFloatByXpath("//inhWeight/min/text()", inhWeight_[0]); |
131 | | - //ParameterManager::getInstance().getBGFloatByXpath("//inhWeight/max/text()", inhWeight_[1]); |
132 | 86 | } |
133 | 87 |
|
134 | | -/// Prints out all parameters to logging file. |
135 | | -/// Registered to OperationManager as Operation::printParameters |
| 88 | +/// @brief Prints the parameters of the connection |
136 | 89 | void ConnStatic::printParameters() const |
137 | 90 | { |
138 | | - LOG4CPLUS_DEBUG(fileLogger_, "CONNECTIONS PARAMETERS" |
139 | | - << endl |
140 | | - << "\tConnections Type: ConnStatic" << endl |
141 | | - << "\tConnection radius threshold: " << threshConnsRadius_ |
142 | | - << endl |
143 | | - << "\tConnections per neuron: " << connsPerVertex_ << endl |
144 | | - << "\tRewiring probability: " << rewiringProbability_ << endl |
145 | | - << "\tExhitatory min weight: " << excWeight_[0] << endl |
146 | | - << "\tExhitatory max weight: " << excWeight_[1] << endl |
147 | | - << "\tInhibitory min weight: " << inhWeight_[0] << endl |
148 | | - << "\tInhibitory max weight: " << inhWeight_[1] << endl |
149 | | - << endl); |
150 | 91 | } |
0 commit comments