Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Simulator/Connections/Neuro/ConnStatic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,15 @@ void ConnStatic::loadParameters()
void ConnStatic::printParameters() const
{
}

/// Update the connections status in every epoch.
///
/// @param vertices The vertex list to search from.
/// @return true if successful, false otherwise.
bool ConnStatic::updateConnections(AllVertices &vertices)
{
AllNeuroEdges &synapses = dynamic_cast<AllNeuroEdges &>(*edges_);
synapses.outputWeights(Simulator::getInstance().getCurrentStep());

return true;
}
6 changes: 6 additions & 0 deletions Simulator/Connections/Neuro/ConnStatic.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ class ConnStatic : public Connections {
return destVertexIndexCurrentEpoch_;
}

/// Update the connections status in every epoch.
///
/// @param vertices The vertex list to search from.
/// @return true if successful, false otherwise.
virtual bool updateConnections(AllVertices &vertices) override;

/// Cereal serialization method
template <class Archive> void serialize(Archive &archive);

Expand Down
3 changes: 3 additions & 0 deletions Simulator/Edges/Neuro/AllNeuroEdges.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class AllNeuroEdges : public AllEdges {
/// Cereal serialization method
template <class Archive> void serialize(Archive &archive);

/// Output weights and srcIndex to xml
virtual void outputWeights(int epochNum) = 0;

protected:
/// Setup the internal structure of the class (allocate memories and initialize them).
///
Expand Down
58 changes: 58 additions & 0 deletions Simulator/Edges/Neuro/AllSpikingSynapses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,61 @@ void AllSpikingSynapses::printSynapsesProps() const
}
}
}

string vectorToXML(const vector<BGFLOAT> &matrix, int rows, int cols, const string &name)
{
ostringstream os;
os << "<" << name << " rows=\"" << rows << "\" columns=\"" << cols << "\">\n";

int index = 0;
for_each(matrix.begin(), matrix.end(), [&](BGFLOAT value) mutable {
os << " <value" << index << ">" << value << "</value" << index << ">\n";
index++;
});

os << "</" << name << ">\n";
return os.str();
}

string vectorToXML(const vector<int> &matrix, int rows, int cols, const string &name)
{
ostringstream os;
os << "<" << name << " rows=\"" << rows << "\" columns=\"" << cols << "\">\n";

int index = 0;
for_each(matrix.begin(), matrix.end(), [&](int value) mutable {
os << " <value" << index << ">" << value << "</value" << index << ">\n";

index++;
});

os << "</" << name << ">\n";
return os.str();
}

void AllSpikingSynapses::outputWeights(int epochNum)
{
const std::string filename = "./Output/Results/weights-epoch-" + std::to_string(epochNum)
+ ".xml"; // Hardcoded filename
int vertexCount = Simulator::getInstance().getTotalVertices();

ofstream outFile(filename);
if (!outFile) {
cerr << "Error: Unable to open file " << filename << endl;
cerr << "Error details: " << strerror(errno) << endl;
return;
}

int maxEdges = Simulator::getInstance().getMaxEdgesPerVertex();

string wContent = vectorToXML(W_, vertexCount, maxEdges, "WeightMatrix");
string srcContent = vectorToXML(sourceVertexIndex_, vertexCount, maxEdges, "SourceVertexIndex");

outFile << "<Graph>\n";
outFile << wContent;
outFile << srcContent;
outFile << "</Graph>";
outFile.close();

cout << "Success: XML written to " << filename << endl;
}
3 changes: 3 additions & 0 deletions Simulator/Edges/Neuro/AllSpikingSynapses.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class AllSpikingSynapses : public AllNeuroEdges {
/// Cereal serialization method
template <class Archive> void serialize(Archive &archive);

/// Output weights and srcIndex to xml
virtual void outputWeights(int epochNum);

protected:
/// Setup the internal structure of the class (allocate memories and initialize them).
///
Expand Down