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::getInstance ().numVertices ();
70- }
71-
72- void Layout::registerGraphProperties ()
73- {
74- GraphManager &gm = GraphManager::getInstance ();
75- gm.registerProperty (" y" , &VertexProperty::y);
76- gm.registerProperty (" x" , &VertexProperty::x);
77- gm.registerProperty (" type" , &VertexProperty::type);
78- }
79-
80- // / Setup the internal structure of the class.
81- // / Allocate memories to store all layout state, no sequential dependency in this method
82- void Layout::setup ()
83- {
84- // Allocate memory
85- xloc_ = VectorMatrix (MATRIX_TYPE, MATRIX_INIT, 1 , numVertices_);
86- yloc_ = VectorMatrix (MATRIX_TYPE, MATRIX_INIT, 1 , numVertices_);
87- dist2_ = CompleteMatrix (MATRIX_TYPE, MATRIX_INIT, numVertices_, numVertices_);
88- dist_ = CompleteMatrix (MATRIX_TYPE, MATRIX_INIT, numVertices_, numVertices_);
89-
90- // more allocation of internal memory
91- starterMap_.assign (numVertices_, false );
92- vertexTypeMap_.assign (numVertices_, vertexType::VTYPE_UNDEF);
93-
94- // Loop over all vertices and set their x and y locations
95- GraphManager::VertexIterator vi, vi_end;
96- GraphManager &gm = GraphManager::getInstance ();
97- for (boost::tie (vi, vi_end) = gm.vertices (); vi != vi_end; ++vi) {
98- assert (*vi < numVertices_);
99- xloc_[*vi] = gm[*vi].x ;
100- yloc_[*vi] = gm[*vi].y ;
101- }
102-
103- // Now we calculate the distance and distance^2
104- // between each pair of vertices
105- for (int n = 0 ; n < numVertices_ - 1 ; n++) {
106- for (int n2 = n + 1 ; n2 < numVertices_; n2++) {
107- // distance^2 between two points in point-slope form
108- dist2_ (n, n2) = (xloc_[n] - xloc_[n2]) * (xloc_[n] - xloc_[n2])
109- + (yloc_[n] - yloc_[n2]) * (yloc_[n] - yloc_[n2]);
110-
111- // both points are equidistant from each other
112- dist2_ (n2, n) = dist2_ (n, n2);
113- }
114- }
115-
116- // Finally take the square root to get the distances
117- dist_ = sqrt (dist2_);
118-
119- // Register variable: vertex locations if need
120- // Recorder &recorder = Simulator::getInstance().getModel().getRecorder();
121- // string baseName = "Location";
122- // string xLocation = "x_" + baseName;
123- // string yLocation = "y_" + baseName;
124- // recorder.registerVariable(xLocation, xloc_, Recorder::UpdatedType::CONSTANT);
125- // recorder.registerVariable(yLocation, yloc_, Recorder::UpdatedType::CONSTANT);
126-
127- // test purpose
128- // cout << "xloc_: " << &xloc_ << endl;
129- // RecordableBase& location = xloc_;
130- // cout << "location: " << &location << endl;
131- }
132-
133-
134- // / Prints out all parameters to logging file. Registered to OperationManager as Operation::printParameters
135- void Layout::printParameters () const
136- {
137- GraphManager::VertexIterator vi, vi_end;
138- GraphManager &gm = GraphManager::getInstance ();
139- stringstream output;
140- output << " \n LAYOUT PARAMETERS" << endl;
141- output << " \t Endogenously active neuron positions: " ;
142-
143- for (boost::tie (vi, vi_end) = gm.vertices (); vi != vi_end; ++vi) {
144- assert (*vi < numVertices_);
145- if (gm[*vi].active ) {
146- output << *vi << " " ;
147- }
148- }
149- output << endl;
150-
151- output << " \t Inhibitory neuron positions: " ;
152-
153- for (boost::tie (vi, vi_end) = gm.vertices (); vi != vi_end; ++vi) {
154- assert (*vi < numVertices_);
155- if (gm[*vi].type == " INH" ) {
156- output << *vi << " " ;
157- }
158- }
159- output << endl;
160-
161- LOG4CPLUS_DEBUG (fileLogger_, output.str ());
162- }
163-
164- // / Creates a vertex type map.
165- // / @param numVertices number of the vertices to have in the type map.
166- void Layout::generateVertexTypeMap ()
167- {
168- DEBUG (cout << " \n Initializing vertex type map: VTYPE_UNDEF" << endl;);
169- vertexTypeMap_.assign (numVertices_, vertexType::VTYPE_UNDEF);
170- }
171-
172- // / Populates the starter map.
173- // / Selects num_endogenously_active_neurons excitory neurons and converts them into starter neurons.
174- // / @param numVertices number of vertices to have in the map.
175- void Layout::initStarterMap ()
176- {
177- starterMap_.assign (numVertices_, false );
178- }
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 << " \n LAYOUT PARAMETERS" << endl;
142+ output << " \t Endogenously 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 << " \t Inhibitory 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 << " \n Initializing 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+
0 commit comments