Skip to content

Commit 004f58c

Browse files
Merge pull request #820 from UWB-Biocomputing/SainiSTDPDevelopment
[ISSUE-734] Add full graph for STDP simulations
2 parents 8e4d9ea + 17dbb50 commit 004f58c

File tree

8 files changed

+104
-169
lines changed

8 files changed

+104
-169
lines changed
Lines changed: 47 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/**
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+
*/
98

109
#include "ConnStatic.h"
1110
#include "AllEdges.h"
1211
#include "AllNeuroEdges.h"
1312
#include "AllVertices.h"
13+
#include "GraphManager.h"
1414
#include "OperationManager.h"
1515
#include "ParameterManager.h"
1616
#include "ParseParamError.h"
@@ -22,129 +22,70 @@
2222

2323
#include <algorithm>
2424

25+
/// @brief Default constructor for ConnStatic
2526
ConnStatic::ConnStatic()
2627
{
27-
threshConnsRadius_ = 0;
28-
connsPerVertex_ = 0;
29-
rewiringProbability_ = 0;
30-
radiiSize_ = 0;
3128
}
3229

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
3731
void ConnStatic::setup()
3832
{
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
4037
Layout &layout = Simulator::getInstance().getModel().getLayout();
4138
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
5040
AllNeuroEdges &neuroEdges = dynamic_cast<AllNeuroEdges &>(*edges_);
5141

52-
radiiSize_ = numVertices;
53-
int added = 0;
5442

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();
5646

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);
10054

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;
10757

108-
int nRewiring = added * rewiringProbability_;
58+
// Log edge data
59+
LOG4CPLUS_DEBUG(edgeLogger_, "Source: " << srcVertex << ", Dest: " << destVertex
60+
<< ", Dist: " << dist << ", Weight: " << weight);
10961

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+
}
11168

69+
// Log the total number of connections added
11270
LOG4CPLUS_DEBUG(fileLogger_, "Added connections: " << added);
71+
}
11372

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);
11781
}
11882

119-
/// Load member variables from configuration file.
120-
/// Registered to OperationManager as Operations::op::loadParameters
83+
/// @brief Loads parameters related to connections
12184
void ConnStatic::loadParameters()
12285
{
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]);
13286
}
13387

134-
/// Prints out all parameters to logging file.
135-
/// Registered to OperationManager as Operation::printParameters
88+
/// @brief Prints the parameters of the connection
13689
void ConnStatic::printParameters() const
13790
{
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);
15091
}

Simulator/Connections/Neuro/ConnStatic.h

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
* every neighbor of \f$v\f$ is connected to every other neighbor of \f$v\f$).
1818
* Let \f$C_v\f$ denote the fracion of these allowable edges that actually exist.
1919
* Define \f$C\f$ as the average of \f$C_v\f$ overall \f$v\f$ (Watts et al. 1998).
20-
*
21-
* We first create a regular network characterized by two parameters: the number of maximum
22-
* connections per neuron and connection radius threshold, then rewire it according
23-
* to the small-world rewiring probability.
2420
*/
2521

2622
#pragma once
@@ -48,6 +44,9 @@ class ConnStatic : public Connections {
4844
return new ConnStatic();
4945
}
5046

47+
/// Register vertex properties with the GraphManager
48+
virtual void registerGraphProperties() override;
49+
5150
/// Setup the internal structure of the class (allocate memories and initialize them).
5251
/// Initialize the small world network characterized by parameters:
5352
/// number of maximum connections per vertex, connection radius threshold, and
@@ -62,12 +61,6 @@ class ConnStatic : public Connections {
6261
/// Registered to OperationManager as Operation::printParameters
6362
virtual void printParameters() const override;
6463

65-
/// Get connection radius threshold
66-
BGFLOAT getConnsRadiusThresh() const
67-
{
68-
return threshConnsRadius_;
69-
}
70-
7164
/// Get array of vertex weights
7265
const vector<BGFLOAT> &getWCurrentEpoch() const
7366
{
@@ -102,24 +95,6 @@ class ConnStatic : public Connections {
10295
RecordableVector<BGFLOAT> WCurrentEpoch_;
10396
// vector<BGFLOAT> WCurrentEpoch_;
10497

105-
/// radii size (2020/2/13 add radiiSize for use in serialization/deserialization)
106-
int radiiSize_;
107-
108-
/// number of maximum connections per vertex
109-
int connsPerVertex_;
110-
111-
/// Connection radius threshold
112-
BGFLOAT threshConnsRadius_;
113-
114-
/// Small-world rewiring probability
115-
BGFLOAT rewiringProbability_;
116-
117-
/// Min/max values of excitatory neuron's synapse weight
118-
BGFLOAT excWeight_[2];
119-
120-
/// Min/max values of inhibitory neuron's synapse weight
121-
BGFLOAT inhWeight_[2];
122-
12398
struct DistDestVertex {
12499
BGFLOAT dist; ///< distance to the destination vertex
125100
int destVertex; ///< index of the destination vertex
@@ -139,10 +114,5 @@ template <class Archive> void ConnStatic::serialize(Archive &archive)
139114
archive(cereal::base_class<Connections>(this),
140115
cereal::make_nvp("sourceVertexIndexCurrentEpoch", sourceVertexIndexCurrentEpoch_),
141116
cereal::make_nvp("destVertexIndexCurrentEpoch", destVertexIndexCurrentEpoch_),
142-
cereal::make_nvp("WCurrentEpoch", WCurrentEpoch_),
143-
cereal::make_nvp("radiiSize", radiiSize_),
144-
cereal::make_nvp("connsPerVertex", connsPerVertex_),
145-
cereal::make_nvp("threshConnsRadius", threshConnsRadius_),
146-
cereal::make_nvp("rewiringProbability", rewiringProbability_),
147-
cereal::make_nvp("excWeight", excWeight_), cereal::make_nvp("inhWeight", inhWeight_));
117+
cereal::make_nvp("WCurrentEpoch", WCurrentEpoch_));
148118
}

Simulator/Core/Core.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,25 @@ int Core::runSimulation(string executableName, string cmdLineArguments)
146146
}
147147

148148
// Ask all objects to register their Graph properties
149+
LOG4CPLUS_TRACE(consoleLogger, "Registering Graph Properties");
149150
OperationManager::getInstance().executeOperation(Operations::registerGraphProperties);
150151

151152
// Retrieve class attribute from the 'LayoutParams' in the config file
152153
// This value indicate the simulation type (Neural or NG911) for graph manager configuration
153154
// Log fatal error if no simulation type is found and terminate
155+
// Retrieve class attribute from the 'LayoutParams' in the config file
156+
// This value indicates the simulation type (Neural or NG911) for graph manager configuration
157+
154158
string configData;
155159
ParameterManager::getInstance().getStringByXpath("//LayoutParams/@class", configData);
156-
157-
if (configData.find("Neur")) {
160+
if (configData == "LayoutNeuro") {
158161
GraphManager<NeuralVertexProperties>::getInstance().readGraph();
159-
}
160-
if (configData.find("91")) {
162+
LOG4CPLUS_TRACE(consoleLogger, "Reading Neural Vertex Properties");
163+
} else if (configData.find("Layout911") != std::string::npos) {
161164
GraphManager<NG911VertexProperties>::getInstance().readGraph();
165+
LOG4CPLUS_TRACE(consoleLogger, "Reading NG911 Vertex Properties");
162166
} else {
163-
LOG4CPLUS_FATAL(consoleLogger, "ERROR: Unknown simulation type'");
167+
LOG4CPLUS_FATAL(consoleLogger, "ERROR: Unknown simulation type");
164168
return -1;
165169
}
166170

Simulator/Utils/Global.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,14 @@ struct NeuralVertexProperties : public VertexProperties {
286286
bool active;
287287
};
288288

289-
/// @brief The structure to hold the edge properties
290-
struct EdgeProperties {
291-
// TODO: Edge Properties
289+
/// @brief The structure to hold the edge properties
290+
struct NeuralEdgeProperties {
291+
int source;
292+
int target;
293+
double weight;
292294
};
293295

296+
294297
/// @brief The structure to hold the Graph properties
295298
struct GraphProperties {
296299
// TODO: Graph Properties

Simulator/Utils/GraphManager.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ template <typename VertexProperties> class GraphManager {
5252
public:
5353
/// Using directive for graphml graph type (adjacency list)
5454
using Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperties,
55-
EdgeProperties, GraphProperties>;
55+
NeuralEdgeProperties, GraphProperties>;
5656

5757
using EdgeIterator = typename boost::graph_traits<Graph>::edge_iterator;
5858
using VertexIterator = typename boost::graph_traits<Graph>::vertex_iterator;
@@ -109,6 +109,11 @@ template <typename VertexProperties> class GraphManager {
109109
/// @return the target vertex index for the given Edge
110110
size_t target(const EdgeDescriptor &edge) const;
111111

112+
/// @brief Retrieves the weight of an edge
113+
/// @param edge the EdgeDescriptor
114+
/// @return the weight of the given edge
115+
double weight(const EdgeDescriptor &edge) const;
116+
112117
/// @brief Direct access to the VertexProperties of a vertex descriptor
113118
/// @param vertex the vertex descriptor (index)
114119
/// @return the VertexProperties of the vertex descriptor
@@ -175,7 +180,6 @@ template <typename VertexProperties> bool GraphManager<VertexProperties>::readGr
175180

176181
// If graphFilePath_ isn't already defined, get it from ParameterManager
177182
if (graphFilePath_ == "") {
178-
// string file_name;
179183
string path = "//graphmlFile/text()";
180184
if (!ParameterManager::getInstance().getStringByXpath(path, graphFilePath_)) {
181185
cerr << "Could not find XML path: " << path << ".\n";
@@ -233,6 +237,16 @@ size_t GraphManager<VertexProperties>::target(
233237
return boost::target(edge, graph_);
234238
}
235239

240+
/// @brief Retrieves the weight of an edge
241+
/// @param edge the EdgeDescriptor
242+
/// @return the weight of the given edge
243+
template <typename VertexProperties>
244+
double GraphManager<VertexProperties>::weight(
245+
const typename GraphManager<VertexProperties>::EdgeDescriptor &edge) const
246+
{
247+
return boost::get(&NeuralEdgeProperties::weight, graph_, edge);
248+
}
249+
236250
/// @brief Directly access the VertexProperties of a vertex descriptor.
237251
/// @param vertex The vertex descriptor (index).
238252
/// @return The VertexProperties of the vertex.

configfiles/graphs/test-tiny.graphml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<key id="active" for="node" attr.name="active" attr.type="boolean" />
55
<key id="y" for="node" attr.name="y" attr.type="double" />
66
<key id="x" for="node" attr.name="x" attr.type="double" />
7+
<key id="weight" for="edge" attr.name="weight" attr.type="double" />
78
<graph edgedefault="directed">
89
<node id="0">
910
<data key="x">0</data>
@@ -29,5 +30,17 @@
2930
<data key="active">0</data>
3031
<data key="type">EXC</data>
3132
</node>
33+
<edge id="e1" source="0" target="1">
34+
<data key="weight">5.0e-9</data>
35+
</edge>
36+
<edge id="e2" source="1" target="2">
37+
<data key="weight">-3.2e-8</data>
38+
</edge>
39+
<edge id="e3" source="2" target="3">
40+
<data key="weight">3.3e-8</data>
41+
</edge>
42+
<edge id="e4" source="3" target="0">
43+
<data key="weight">6.4e-8</data>
44+
</edge>
3245
</graph>
3346
</graphml>

0 commit comments

Comments
 (0)