Skip to content

Commit d81a604

Browse files
committed
Clang Update
1 parent b36ecf6 commit d81a604

File tree

3 files changed

+521
-524
lines changed

3 files changed

+521
-524
lines changed

Simulator/Layouts/Layout.cpp

Lines changed: 171 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -6,175 +6,174 @@
66
* @brief The Layout class defines the layout of neurons in neural networks
77
*/
88

9-
#include "Layout.h"
10-
#include "Factory.h"
11-
#include "GraphManager.h"
12-
#include "OperationManager.h"
13-
#include "ParameterManager.h"
14-
#include "ParseParamError.h"
15-
#include "RecordableBase.h"
16-
#include "Simulator.h"
17-
#include "Util.h"
18-
19-
/// Constructor
20-
Layout::Layout() : numEndogenouslyActiveNeurons_(0)
21-
{
22-
// Get a copy of the console logger to use in the case of errors
23-
log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console"));
24-
25-
// Create Vertices/Neurons class using type definition in configuration file
26-
string type;
27-
ParameterManager::getInstance().getStringByXpath("//VerticesParams/@class", type);
28-
vertices_ = Factory<AllVertices>::getInstance().createType(type);
29-
30-
// If the factory returns an error (nullptr), exit
31-
if (vertices_ == nullptr) {
32-
LOG4CPLUS_INFO(consoleLogger, "INVALID CLASS: " + type);
33-
exit(EXIT_FAILURE);
34-
}
35-
36-
// Register loadParameters function as a loadParameters operation in the Operation Manager
37-
function<void()> loadParametersFunc = std::bind(&Layout::loadParameters, this);
38-
OperationManager::getInstance().registerOperation(Operations::loadParameters,
39-
loadParametersFunc);
40-
41-
// Register printParameters function as a printParameters operation in the OperationManager
42-
function<void()> printParametersFunc = bind(&Layout::printParameters, this);
43-
OperationManager::getInstance().registerOperation(Operations::printParameters,
44-
printParametersFunc);
45-
46-
// Register registerGraphProperties method as registerGraphProperties operation
47-
// in the OperationManager
48-
function<void()> registerGraphPropertiesFunc = bind(&Layout::registerGraphProperties, this);
49-
OperationManager::getInstance().registerOperation((Operations::registerGraphProperties),
50-
registerGraphPropertiesFunc);
51-
52-
// Get a copy of the file logger to use log4cplus macros
53-
fileLogger_ = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("file"));
54-
}
55-
56-
AllVertices &Layout::getVertices() const
57-
{
58-
return *vertices_;
59-
}
60-
61-
int Layout::getNumVertices() const
62-
{
63-
return numVertices_;
64-
}
65-
66-
/// Load member variables from configuration file. Registered to OperationManager as Operations::op::loadParameters
67-
void Layout::loadParameters()
68-
{
69-
numVertices_ = GraphManager<NeuralVertexProperties>::getInstance().numVertices();
70-
}
71-
72-
void Layout::registerGraphProperties()
73-
{
74-
GraphManager<NeuralVertexProperties> &gm = GraphManager<NeuralVertexProperties>::getInstance();
75-
gm.registerProperty("y", &VertexProperties::y);
76-
gm.registerProperty("x", &VertexProperties::x);
77-
gm.registerProperty("type", &VertexProperties::type);
78-
}
79-
80-
81-
/// Setup the internal structure of the class.
82-
/// Allocate memories to store all layout state, no sequential dependency in this method
83-
void Layout::setup()
84-
{
85-
// Allocate memory
86-
xloc_ = VectorMatrix(MATRIX_TYPE, MATRIX_INIT, 1, numVertices_);
87-
yloc_ = VectorMatrix(MATRIX_TYPE, MATRIX_INIT, 1, numVertices_);
88-
dist2_ = CompleteMatrix(MATRIX_TYPE, MATRIX_INIT, numVertices_, numVertices_);
89-
dist_ = CompleteMatrix(MATRIX_TYPE, MATRIX_INIT, numVertices_, numVertices_);
90-
91-
// more allocation of internal memory
92-
starterMap_.assign(numVertices_, false);
93-
vertexTypeMap_.assign(numVertices_, vertexType::VTYPE_UNDEF);
94-
95-
// Loop over all vertices and set their x and y locations
96-
GraphManager<NeuralVertexProperties>::VertexIterator vi, vi_end;
97-
GraphManager<NeuralVertexProperties> &gm = GraphManager<NeuralVertexProperties>::getInstance();
98-
for (boost::tie(vi, vi_end) = gm.vertices(); vi != vi_end; ++vi) {
99-
assert(*vi < numVertices_);
100-
xloc_[*vi] = gm[*vi].x;
101-
yloc_[*vi] = gm[*vi].y;
102-
}
103-
104-
// Now we calculate the distance and distance^2
105-
// between each pair of vertices
106-
for (int n = 0; n < numVertices_ - 1; n++) {
107-
for (int n2 = n + 1; n2 < numVertices_; n2++) {
108-
// distance^2 between two points in point-slope form
109-
dist2_(n, n2) = (xloc_[n] - xloc_[n2]) * (xloc_[n] - xloc_[n2])
110-
+ (yloc_[n] - yloc_[n2]) * (yloc_[n] - yloc_[n2]);
111-
112-
// both points are equidistant from each other
113-
dist2_(n2, n) = dist2_(n, n2);
114-
}
115-
}
116-
117-
// Finally take the square root to get the distances
118-
dist_ = sqrt(dist2_);
119-
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);
127-
128-
// test purpose
129-
// cout << "xloc_: " << &xloc_ << endl;
130-
// RecordableBase& location = xloc_;
131-
// cout << "location: " << &location << endl;
132-
}
133-
134-
135-
/// Prints out all parameters to logging file. Registered to OperationManager as Operation::printParameters
136-
void Layout::printParameters() const
137-
{
138-
GraphManager<NeuralVertexProperties>::VertexIterator vi, vi_end;
139-
GraphManager<NeuralVertexProperties> &gm = GraphManager<NeuralVertexProperties>::getInstance();
140-
stringstream output;
141-
output << "\nLAYOUT PARAMETERS" << endl;
142-
output << "\tEndogenously active neuron positions: ";
143-
144-
for (boost::tie(vi, vi_end) = gm.vertices(); vi != vi_end; ++vi) {
145-
assert(*vi < numVertices_);
146-
if (gm[*vi].active) {
147-
output << *vi << " ";
148-
}
149-
}
150-
output << endl;
151-
152-
output << "\tInhibitory neuron positions: ";
153-
154-
for (boost::tie(vi, vi_end) = gm.vertices(); vi != vi_end; ++vi) {
155-
assert(*vi < numVertices_);
156-
if (gm[*vi].type == "INH") {
157-
output << *vi << " ";
158-
}
159-
}
160-
output << endl;
161-
162-
LOG4CPLUS_DEBUG(fileLogger_, output.str());
163-
}
164-
165-
/// Creates a vertex type map.
166-
/// @param numVertices number of the vertices to have in the type map.
167-
void Layout::generateVertexTypeMap()
168-
{
169-
DEBUG(cout << "\nInitializing vertex type map: VTYPE_UNDEF" << endl;);
170-
vertexTypeMap_.assign(numVertices_, vertexType::VTYPE_UNDEF);
171-
}
172-
173-
/// Populates the starter map.
174-
/// Selects num_endogenously_active_neurons excitory neurons and converts them into starter neurons.
175-
/// @param numVertices number of vertices to have in the map.
176-
void Layout::initStarterMap()
177-
{
178-
starterMap_.assign(numVertices_, false);
179-
}
180-
9+
#include "Layout.h"
10+
#include "Factory.h"
11+
#include "GraphManager.h"
12+
#include "OperationManager.h"
13+
#include "ParameterManager.h"
14+
#include "ParseParamError.h"
15+
#include "RecordableBase.h"
16+
#include "Simulator.h"
17+
#include "Util.h"
18+
19+
/// Constructor
20+
Layout::Layout() : numEndogenouslyActiveNeurons_(0)
21+
{
22+
// Get a copy of the console logger to use in the case of errors
23+
log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console"));
24+
25+
// Create Vertices/Neurons class using type definition in configuration file
26+
string type;
27+
ParameterManager::getInstance().getStringByXpath("//VerticesParams/@class", type);
28+
vertices_ = Factory<AllVertices>::getInstance().createType(type);
29+
30+
// If the factory returns an error (nullptr), exit
31+
if (vertices_ == nullptr) {
32+
LOG4CPLUS_INFO(consoleLogger, "INVALID CLASS: " + type);
33+
exit(EXIT_FAILURE);
34+
}
35+
36+
// Register loadParameters function as a loadParameters operation in the Operation Manager
37+
function<void()> loadParametersFunc = std::bind(&Layout::loadParameters, this);
38+
OperationManager::getInstance().registerOperation(Operations::loadParameters,
39+
loadParametersFunc);
40+
41+
// Register printParameters function as a printParameters operation in the OperationManager
42+
function<void()> printParametersFunc = bind(&Layout::printParameters, this);
43+
OperationManager::getInstance().registerOperation(Operations::printParameters,
44+
printParametersFunc);
45+
46+
// Register registerGraphProperties method as registerGraphProperties operation
47+
// in the OperationManager
48+
function<void()> registerGraphPropertiesFunc = bind(&Layout::registerGraphProperties, this);
49+
OperationManager::getInstance().registerOperation((Operations::registerGraphProperties),
50+
registerGraphPropertiesFunc);
51+
52+
// Get a copy of the file logger to use log4cplus macros
53+
fileLogger_ = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("file"));
54+
}
55+
56+
AllVertices &Layout::getVertices() const
57+
{
58+
return *vertices_;
59+
}
60+
61+
int Layout::getNumVertices() const
62+
{
63+
return numVertices_;
64+
}
65+
66+
/// Load member variables from configuration file. Registered to OperationManager as Operations::op::loadParameters
67+
void Layout::loadParameters()
68+
{
69+
numVertices_ = GraphManager<NeuralVertexProperties>::getInstance().numVertices();
70+
}
71+
72+
void Layout::registerGraphProperties()
73+
{
74+
GraphManager<NeuralVertexProperties> &gm = GraphManager<NeuralVertexProperties>::getInstance();
75+
gm.registerProperty("y", &VertexProperties::y);
76+
gm.registerProperty("x", &VertexProperties::x);
77+
gm.registerProperty("type", &VertexProperties::type);
78+
}
79+
80+
81+
/// Setup the internal structure of the class.
82+
/// Allocate memories to store all layout state, no sequential dependency in this method
83+
void Layout::setup()
84+
{
85+
// Allocate memory
86+
xloc_ = VectorMatrix(MATRIX_TYPE, MATRIX_INIT, 1, numVertices_);
87+
yloc_ = VectorMatrix(MATRIX_TYPE, MATRIX_INIT, 1, numVertices_);
88+
dist2_ = CompleteMatrix(MATRIX_TYPE, MATRIX_INIT, numVertices_, numVertices_);
89+
dist_ = CompleteMatrix(MATRIX_TYPE, MATRIX_INIT, numVertices_, numVertices_);
90+
91+
// more allocation of internal memory
92+
starterMap_.assign(numVertices_, false);
93+
vertexTypeMap_.assign(numVertices_, vertexType::VTYPE_UNDEF);
94+
95+
// Loop over all vertices and set their x and y locations
96+
GraphManager<NeuralVertexProperties>::VertexIterator vi, vi_end;
97+
GraphManager<NeuralVertexProperties> &gm = GraphManager<NeuralVertexProperties>::getInstance();
98+
for (boost::tie(vi, vi_end) = gm.vertices(); vi != vi_end; ++vi) {
99+
assert(*vi < numVertices_);
100+
xloc_[*vi] = gm[*vi].x;
101+
yloc_[*vi] = gm[*vi].y;
102+
}
103+
104+
// Now we calculate the distance and distance^2
105+
// between each pair of vertices
106+
for (int n = 0; n < numVertices_ - 1; n++) {
107+
for (int n2 = n + 1; n2 < numVertices_; n2++) {
108+
// distance^2 between two points in point-slope form
109+
dist2_(n, n2) = (xloc_[n] - xloc_[n2]) * (xloc_[n] - xloc_[n2])
110+
+ (yloc_[n] - yloc_[n2]) * (yloc_[n] - yloc_[n2]);
111+
112+
// both points are equidistant from each other
113+
dist2_(n2, n) = dist2_(n, n2);
114+
}
115+
}
116+
117+
// Finally take the square root to get the distances
118+
dist_ = sqrt(dist2_);
119+
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);
127+
128+
// test purpose
129+
// cout << "xloc_: " << &xloc_ << endl;
130+
// RecordableBase& location = xloc_;
131+
// cout << "location: " << &location << endl;
132+
}
133+
134+
135+
/// Prints out all parameters to logging file. Registered to OperationManager as Operation::printParameters
136+
void Layout::printParameters() const
137+
{
138+
GraphManager<NeuralVertexProperties>::VertexIterator vi, vi_end;
139+
GraphManager<NeuralVertexProperties> &gm = GraphManager<NeuralVertexProperties>::getInstance();
140+
stringstream output;
141+
output << "\nLAYOUT PARAMETERS" << endl;
142+
output << "\tEndogenously active neuron positions: ";
143+
144+
for (boost::tie(vi, vi_end) = gm.vertices(); vi != vi_end; ++vi) {
145+
assert(*vi < numVertices_);
146+
if (gm[*vi].active) {
147+
output << *vi << " ";
148+
}
149+
}
150+
output << endl;
151+
152+
output << "\tInhibitory neuron positions: ";
153+
154+
for (boost::tie(vi, vi_end) = gm.vertices(); vi != vi_end; ++vi) {
155+
assert(*vi < numVertices_);
156+
if (gm[*vi].type == "INH") {
157+
output << *vi << " ";
158+
}
159+
}
160+
output << endl;
161+
162+
LOG4CPLUS_DEBUG(fileLogger_, output.str());
163+
}
164+
165+
/// Creates a vertex type map.
166+
/// @param numVertices number of the vertices to have in the type map.
167+
void Layout::generateVertexTypeMap()
168+
{
169+
DEBUG(cout << "\nInitializing vertex type map: VTYPE_UNDEF" << endl;);
170+
vertexTypeMap_.assign(numVertices_, vertexType::VTYPE_UNDEF);
171+
}
172+
173+
/// Populates the starter map.
174+
/// Selects num_endogenously_active_neurons excitory neurons and converts them into starter neurons.
175+
/// @param numVertices number of vertices to have in the map.
176+
void Layout::initStarterMap()
177+
{
178+
starterMap_.assign(numVertices_, false);
179+
}

0 commit comments

Comments
 (0)