Skip to content

Commit 2647cdf

Browse files
authored
Merge pull request #823 from UWB-Biocomputing/recorder-updates-neuro-ng911
Recorder Updates for Neuro and NG911
2 parents 6428101 + 9e927ec commit 2647cdf

38 files changed

Lines changed: 403 additions & 73 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ ThirdParty/log4cplus-2.0.7/src/liblog4cplus.so.2.0.7
4141
graphitti
4242
ggraphitti
4343
cgraphitti
44+
compare_matrices
4445
tests
4546
serialFullTest
4647
serialFirstHalfTest

Simulator/Connections/Connections.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ Connections::Connections()
4444
function<void()> regGraphPropsFunc = bind(&Connections::registerGraphProperties, this);
4545
opsManager.registerOperation(Operations::registerGraphProperties, regGraphPropsFunc);
4646

47+
// Register registerHistoryVariables function as a registerHistoryVariables operation in the OperationManager
48+
function<void()> registerHistoryVarsFunc = bind(&Connections::registerHistoryVariables, this);
49+
opsManager.registerOperation(Operations::registerHistoryVariables, registerHistoryVarsFunc);
50+
4751
// Get a copy of the file logger to use log4cplus macros
4852
fileLogger_ = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("file"));
4953
edgeLogger_ = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("edge"));

Simulator/Connections/Connections.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ class Connections {
6565
/// Registered to OperationManager as Operation::printParameters
6666
virtual void printParameters() const = 0;
6767

68+
/// Registers history variables for recording during simulation
69+
virtual void registerHistoryVariables() = 0;
70+
6871
/// Update the connections status in every epoch.
6972
///
7073
/// @return true if successful, false otherwise.

Simulator/Connections/NG911/Connections911.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ bool Connections911::updateConnections()
7474
int numVertices = Simulator::getInstance().getTotalVertices();
7575
Layout &layout = Simulator::getInstance().getModel().getLayout();
7676
AllVertices &vertices = layout.getVertices();
77-
oldTypeMap_ = layout.vertexTypeMap_;
7877

7978
// Erase PSAPs
8079
for (int i = 0; i < psapsToErase_; i++) {
@@ -184,7 +183,7 @@ bool Connections911::erasePSAP(AllVertices &vertices, Layout &layout)
184183
erasedEdge.srcV = srcVertex;
185184
erasedEdge.destV = destVertex;
186185
erasedEdge.eType = layout.edgType(srcVertex, destVertex);
187-
edgesErased.push_back(erasedEdge);
186+
edgesErased_.push_back(erasedEdge);
188187

189188
changesMade = true;
190189
edges_->eraseEdge(destVertex, iEdg);
@@ -205,7 +204,7 @@ bool Connections911::erasePSAP(AllVertices &vertices, Layout &layout)
205204

206205
if (changesMade) {
207206
// This is here so that we don't delete the vertex if we can't find any edges
208-
verticesErased.push_back(randPSAP);
207+
verticesErased_.push_back(randPSAP);
209208
layout.vertexTypeMap_[randPSAP] = vertexType::VTYPE_UNDEF;
210209
}
211210

@@ -239,7 +238,7 @@ bool Connections911::erasePSAP(AllVertices &vertices, Layout &layout)
239238
addedEdge.srcV = srcVertex;
240239
addedEdge.destV = closestPSAP;
241240
addedEdge.eType = edgeType::CP;
242-
edgesAdded.push_back(addedEdge);
241+
edgesAdded_.push_back(addedEdge);
243242
}
244243

245244
// For each psap-less responder, find closest match
@@ -267,7 +266,7 @@ bool Connections911::erasePSAP(AllVertices &vertices, Layout &layout)
267266
addedEdge.srcV = closestPSAP;
268267
addedEdge.destV = destVertex;
269268
addedEdge.eType = edgeType::PR;
270-
edgesAdded.push_back(addedEdge);
269+
edgesAdded_.push_back(addedEdge);
271270
}
272271

273272
return changesMade;
@@ -318,7 +317,7 @@ bool Connections911::eraseRESP(AllVertices &vertices, Layout &layout)
318317
erasedEdge.srcV = srcVertex;
319318
erasedEdge.destV = destVertex;
320319
erasedEdge.eType = layout.edgType(srcVertex, destVertex);
321-
edgesErased.push_back(erasedEdge);
320+
edgesErased_.push_back(erasedEdge);
322321

323322
changesMade = true;
324323
edges_->eraseEdge(destVertex, iEdg);
@@ -327,7 +326,7 @@ bool Connections911::eraseRESP(AllVertices &vertices, Layout &layout)
327326

328327
if (changesMade) {
329328
// This is here so that we don't delete the vertex if we can't find any edges
330-
verticesErased.push_back(randRESP);
329+
verticesErased_.push_back(randRESP);
331330
layout.vertexTypeMap_[randRESP] = vertexType::VTYPE_UNDEF;
332331
}
333332

@@ -371,16 +370,23 @@ string Connections911::ChangedEdge::toString()
371370
return os.str();
372371
}
373372

373+
/// Registers variable to be recorded
374+
void Connections911::registerHistoryVariables()
375+
{
376+
Recorder &recorder = Simulator::getInstance().getModel().getRecorder();
377+
recorder.registerVariable("verticesDeleted", verticesErased_, Recorder::UpdatedType::DYNAMIC);
378+
}
379+
374380
/// Returns the complete list of all deleted or added edges as a string.
375381
string Connections911::changedEdgesToXML(bool added)
376382
{
377383
stringstream os;
378384

379-
vector<ChangedEdge> changed = edgesErased;
385+
vector<ChangedEdge> changed = edgesErased_;
380386
string name = "edgesDeleted";
381387

382388
if (added) {
383-
changed = edgesAdded;
389+
changed = edgesAdded_;
384390
name = "edgesAdded";
385391
}
386392

@@ -395,22 +401,24 @@ string Connections911::changedEdgesToXML(bool added)
395401
return os.str();
396402
}
397403

404+
/*
398405
/// Returns the complete list of deleted vertices as a string.
399406
string Connections911::erasedVerticesToXML()
400407
{
401408
stringstream os;
402409
403410
os << "<Matrix name=\"verticesDeleted\" type=\"complete\" rows=\"1\" columns=\""
404-
<< verticesErased.size() << "\" multiplier=\"1.0\">" << endl;
411+
<< verticesErased_.size() << "\" multiplier=\"1.0\">" << endl;
405412
os << " ";
406413
407-
sort(verticesErased.begin(), verticesErased.end());
408-
for (int i = 0; i < verticesErased.size(); i++) {
409-
os << verticesErased[i] << " ";
414+
sort(verticesErased_.begin(), verticesErased_.end());
415+
for (int i = 0; i < verticesErased_.size(); i++) {
416+
os << verticesErased_[i] << " ";
410417
}
411418
412419
os << endl << "</Matrix>";
413420
return os.str();
414421
}
422+
*/
415423

416424
#endif

Simulator/Connections/NG911/Connections911.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "Connections.h"
1717
#include "InputEvent.h"
18+
#include "RecordableVector.h"
1819
#include <vector>
1920

2021
using namespace std;
@@ -33,7 +34,7 @@ class Connections911 : public Connections {
3334
return new Connections911();
3435
}
3536
/// Records typeMap history for recorders
36-
vector<vertexType> oldTypeMap_;
37+
/// vector<vertexType> oldTypeMap_;
3738

3839
/// Setup the internal structure of the class (allocate memories and initialize them).
3940
/// Initialize the network characterized by parameters:
@@ -48,6 +49,9 @@ class Connections911 : public Connections {
4849
/// Registered to OperationManager as Operation::printParameters
4950
virtual void printParameters() const override;
5051

52+
/// Registers history variables for recording during simulation
53+
virtual void registerHistoryVariables() override;
54+
5155
private:
5256
/// number of psaps to erase at the end of 1 epoch
5357
int psapsToErase_;
@@ -58,13 +62,13 @@ class Connections911 : public Connections {
5862
struct ChangedEdge;
5963

6064
// Edges that were added but later removed are still here
61-
vector<ChangedEdge> edgesAdded;
65+
vector<ChangedEdge> edgesAdded_;
6266

6367
// New edges = (old edges + edgesAdded) - edgesErased <-- works
6468
// New edges = (old edges - edgesErased) + edgesAdded <-- does not work
65-
vector<ChangedEdge> edgesErased;
69+
vector<ChangedEdge> edgesErased_;
6670

67-
vector<int> verticesErased;
71+
RecordableVector<int> verticesErased_;
6872

6973
#if !defined(USE_GPU)
7074

Simulator/Connections/Neuro/ConnGrowth.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,7 @@ void ConnGrowth::printRadii() const
330330
cout << "radii[" << i << "] = " << radii_[i] << endl;
331331
}
332332
}
333+
334+
void ConnGrowth::registerHistoryVariables()
335+
{
336+
}

Simulator/Connections/Neuro/ConnGrowth.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class ConnGrowth : public Connections {
9797
/// Registered to OperationManager as Operations::op::loadParameters
9898
virtual void loadParameters() override;
9999

100+
/// Registers history variables for recording during simulation
101+
virtual void registerHistoryVariables() override;
102+
100103
/// Prints out all parameters to logging file.
101104
/// Registered to OperationManager as Operation::printParameters
102105
virtual void printParameters() const override;

Simulator/Connections/Neuro/ConnStatic.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,14 @@ void ConnStatic::printParameters() const
9090
{
9191
}
9292

93-
/// Output the weights matrix after every epoch.
94-
///
95-
/// @return true if successful, false otherwise.
96-
bool ConnStatic::updateConnections()
93+
void ConnStatic::registerHistoryVariables()
9794
{
98-
AllNeuroEdges &synapses = dynamic_cast<AllNeuroEdges &>(*edges_);
99-
synapses.outputWeights(Simulator::getInstance().getCurrentStep());
100-
101-
return true;
95+
// Register the following variables to be recorded
96+
// Note: There may be potential duplicate weight, source, destination vertices
97+
Recorder &recorder = Simulator::getInstance().getModel().getRecorder();
98+
recorder.registerVariable("weight", WCurrentEpoch_, Recorder::UpdatedType::DYNAMIC);
99+
recorder.registerVariable("sourceVertex", sourceVertexIndexCurrentEpoch_,
100+
Recorder::UpdatedType::DYNAMIC);
101+
recorder.registerVariable("destinationVertex", destVertexIndexCurrentEpoch_,
102+
Recorder::UpdatedType::DYNAMIC);
102103
}

Simulator/Connections/Neuro/ConnStatic.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class ConnStatic : public Connections {
6161
/// Registered to OperationManager as Operation::printParameters
6262
virtual void printParameters() const override;
6363

64+
/// Registers history variables for recording during simulation
65+
virtual void registerHistoryVariables() override;
66+
6467
/// Get array of vertex weights
6568
const vector<BGFLOAT> &getWCurrentEpoch() const
6669
{
@@ -71,29 +74,24 @@ class ConnStatic : public Connections {
7174
/// Get all edge source vertex indices
7275
const vector<int> &getSourceVertexIndexCurrentEpoch() const
7376
{
74-
return sourceVertexIndexCurrentEpoch_;
77+
return sourceVertexIndexCurrentEpoch_.getVector();
7578
}
7679

7780
/// Get all edge destination vertex indices
7881
const vector<int> &getDestVertexIndexCurrentEpoch() const
7982
{
80-
return destVertexIndexCurrentEpoch_;
83+
return destVertexIndexCurrentEpoch_.getVector();
8184
}
8285

83-
/// Output the weights matrix after every epoch.
84-
///
85-
/// @return true if successful, false otherwise.
86-
virtual bool updateConnections() override;
87-
8886
/// Cereal serialization method
8987
template <class Archive> void serialize(Archive &archive);
9088

9189
private:
9290
/// Indices of the source vertex for each edge
93-
vector<int> sourceVertexIndexCurrentEpoch_;
91+
RecordableVector<int> sourceVertexIndexCurrentEpoch_;
9492

9593
/// Indices of the destination vertex for each edge
96-
vector<int> destVertexIndexCurrentEpoch_;
94+
RecordableVector<int> destVertexIndexCurrentEpoch_;
9795

9896
/// The weight (scaling factor, strength, maximal amplitude) of each vertex for the current epoch.
9997
// vector<BGFLOAT> changes to RecordableVector for recording purpose

Simulator/Layouts/Layout.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ void Layout::setup()
117117
// Finally take the square root to get the distances
118118
dist_ = sqrt(dist2_);
119119

120-
// Register variable: vertex locations if need
121-
//Recorder &recorder = Simulator::getInstance().getModel().getRecorder();
122-
//string baseName = "Location";
123-
//string xLocation = "x_" + baseName;
124-
//string yLocation = "y_" + baseName;
125-
//recorder.registerVariable(xLocation, xloc_, Recorder::UpdatedType::CONSTANT);
126-
//recorder.registerVariable(yLocation, yloc_, Recorder::UpdatedType::CONSTANT);
120+
//Register variable: vertex locations
121+
Recorder &recorder = Simulator::getInstance().getModel().getRecorder();
122+
string baseName = "Location";
123+
string xLocation = "x_" + baseName;
124+
string yLocation = "y_" + baseName;
125+
recorder.registerVariable(xLocation, xloc_, Recorder::UpdatedType::CONSTANT);
126+
recorder.registerVariable(yLocation, yloc_, Recorder::UpdatedType::CONSTANT);
127127

128128
// test purpose
129129
// cout << "xloc_: " << &xloc_ << endl;

0 commit comments

Comments
 (0)