Auryn simulator  v0.8.1-206-gb56e451
Plastic Spiking Neural Network Simulator
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
auryn::WeightMonitor Class Reference

Monitors the evolution of a single or a set of weights. More...

#include <WeightMonitor.h>

Inheritance diagram for auryn::WeightMonitor:
Inheritance graph
[legend]
Collaboration diagram for auryn::WeightMonitor:
Collaboration graph
[legend]

Public Member Functions

 WeightMonitor (SparseConnection *source, string filename, AurynDouble interval=10.0)
 Default constructor. More...
 
 WeightMonitor (SparseConnection *source, ForwardMatrix *m, string filename, AurynDouble interval=10.0)
 Specific weight matrix constructor. More...
 
 WeightMonitor (SparseConnection *source, NeuronID i, NeuronID j, string filename, AurynDouble interval=10.0, RecordingMode mode=SINGLE, StateID z=0)
 Single weight constructor. More...
 
virtual ~WeightMonitor ()
 
void execute ()
 propagate function used by System class internally More...
 
void set_mat (ForwardMatrix *m)
 Sets target matrix to read from. More...
 
void add_to_list_by_data_index (AurynLong index, StateID z=0)
 Adds a single element to the recording list which is identified by its data index and z-state. More...
 
void add_to_list (AurynWeight *ptr)
 Adds a single element to the recording list which is identified by a pointer. More...
 
void add_to_list (NeuronID i, NeuronID j, StateID z=0)
 Adds a single element identified matrix coordinates (row,col,z) to the recording list. More...
 
void add_to_list (std::vector< neuron_pair > vec, string label="")
 Adds a list vector<neuron_pair> vec the the recording list. More...
 
void add_equally_spaced (NeuronID number, NeuronID z=0)
 Adds number of elements to the recording list that are equally spaced in the data vector of the connection matrix. More...
 
void load_pattern_connections (string filename, unsigned int maxcon=5, unsigned int maxpat=10, PatternMode patmod=ALLTOALL)
 Adds connections inside a pattern and between patterns. Since such lists can become large quickly the amount of patterns and connections for each pattern to be monitored can be limited by maxcon and maxpat. More...
 
void load_pattern_connections (string filename_pre, string filename_post, unsigned int maxcon=5, unsigned int maxpat=10, PatternMode patmod=ALLTOALL)
 
void load_data_range (AurynLong i, AurynLong j)
 Adds connections from a given range in the sparse matrix data array. More...
 

Protected Member Functions

void init (SparseConnection *source, NeuronID i, NeuronID j, string filename, AurynTime interval)
 
void record_single_synapses ()
 
void record_synapse_groups ()
 
std::vector< type_pattern > * load_patfile (string filename, unsigned int maxpat)
 
- Protected Member Functions inherited from auryn::Monitor
virtual void open_output_file (std::string filename)
 
virtual void virtual_serialize (boost::archive::binary_oarchive &ar, const unsigned int version)
 
virtual void virtual_serialize (boost::archive::binary_iarchive &ar, const unsigned int version)
 
virtual void flush ()
 Flush to file. More...
 
 Monitor (std::string filename, std::string default_extension="dat")
 Standard constructor with file name. More...
 
 Monitor ()
 Constructor which does not open a text file for output. More...
 
std::string generate_filename (std::string name_hint="")
 Generates a default filename from the device ID. More...
 
virtual ~Monitor ()
 Standard destructor. More...
 
- Protected Member Functions inherited from auryn::Device
void init ()
 Standard initializer to be called by the constructor. More...
 
 Device ()
 Standard constructor. More...
 
void set_name (std::string s)
 Set device name. More...
 
std::string get_name ()
 Get device name. More...
 
int get_id ()
 Get numeric device id. More...
 
virtual ~Device ()
 Standard destructor. More...
 
virtual void evolve ()
 

Protected Attributes

SparseConnectionsrc
 
ForwardMatrixmat
 
RecordingMode recordingmode
 
NeuronID elem_i
 
NeuronID elem_j
 
AurynTime ssize
 
std::vector< AurynLong > * element_list
 
std::vector< NeuronIDgroup_indices
 
- Protected Attributes inherited from auryn::Monitor
std::ofstream outfile
 
std::string fname
 
std::string default_file_extension
 
bool active
 Standard active switch. More...
 
- Protected Attributes inherited from auryn::Device
std::string device_name
 Identifying name for device. More...
 
bool active
 Standard active switch. More...
 

Detailed Description

Monitors the evolution of a single or a set of weights.

This class perform online monitoring of synaptic weights in a Connection. The class supports different recording modes for single individual weights or multiple weights. Output is written to a human readable text file.

Todo:
Implement a new data_index based element list which can deal with Complex Matrix states in a clean fashion

Constructor & Destructor Documentation

◆ WeightMonitor() [1/3]

WeightMonitor::WeightMonitor ( SparseConnection source,
std::string  filename,
AurynDouble  interval = 10.0 
)

Default constructor.

This initializes the WeightMonitor and specifies and output file and a sampling interval. Per default WeightMonitor is in multi recording mode. That means it maintains a list of pointers to weights which you would like to monitor. This list is initally empty and needs to be populated after initializating with the appropriate add ... functions.

Parameters
sourceThe connection object to record from
filenameThe file to record to
intervalThe sampling interval in simulation interval in seconds
30  : Monitor(filename)
31 {
32  init(source,0,0,filename,interval/auryn_timestep);
33 }
void init()
Standard initializer to be called by the constructor.
Definition: Device.cpp:32
Monitor()
Constructor which does not open a text file for output.
Definition: Monitor.cpp:47
double auryn_timestep
Simulation timestep in seconds.
Definition: auryn_definitions.cpp:31
Here is the call graph for this function:

◆ WeightMonitor() [2/3]

WeightMonitor::WeightMonitor ( SparseConnection source,
ForwardMatrix m,
std::string  filename,
AurynDouble  interval = 10.0 
)

Specific weight matrix constructor.

This initializes the WeightMonitor and specifies and output file and a sampling interval. The constructor does not specify which weights to monitor. interpreted as range i..j in the data array of the source Connection. Note that in DATARANGE mode the Monitor could in principle also monitor zero connections. However in SINGLE it records only non-zero elements.

Parameters
sourceThe connection object to record from
filenameThe file to record to
mA pointer to the weight matrix to record from
intervalThe sampling interval in simulation interval in seconds
35  : Monitor(filename)
36 {
37  init(source,0,0,filename,interval/auryn_timestep);
38  set_mat(m);
39 }
void init()
Standard initializer to be called by the constructor.
Definition: Device.cpp:32
Monitor()
Constructor which does not open a text file for output.
Definition: Monitor.cpp:47
double auryn_timestep
Simulation timestep in seconds.
Definition: auryn_definitions.cpp:31
void set_mat(ForwardMatrix *m)
Sets target matrix to read from.
Definition: WeightMonitor.cpp:360
Here is the call graph for this function:

◆ WeightMonitor() [3/3]

WeightMonitor::WeightMonitor ( SparseConnection source,
NeuronID  i,
NeuronID  j,
std::string  filename,
AurynDouble  interval = 10.0,
RecordingMode  mode = SINGLE,
StateID  z = 0 
)

Single weight constructor.

This initializes the WeightMonitor and specifies and output file and a sampling interval. It moreover puts the WeightMonitor in RecordingMode mode SINGLE in which it records a single synaptic connection specified by i and j. If mode is set to DATARANGE instead, the arguments i and j are instead interpreted as range i..j in the data index array of the source Connection.

Parameters
sourceThe connection object to record from
iParameter i (either row position of synapse in WeightMatrix or start index in data array depending on mode)
jParameter j (either col position of synapse in WeightMatrix or stop index in data array depending on mode)
filenameThe file to record to
intervalThe sampling interval in simulation interval (1s default)
modeThe recording mode (one of RecordingMode datatype)
zThe z state the complex matrix state to record from
41  : Monitor(filename)
42 {
43  init(source,i,j,filename,interval/auryn_timestep);
44 
45  // overwrite the following default values set in init
46  recordingmode = mode;
47  elem_i = i;
48  elem_j = j;
49 
50  switch (recordingmode) {
51  case DATARANGE :
52  for (AurynLong c = elem_i ; c < elem_j ; ++c)
54  break;
55  case SINGLE :
56  add_to_list(i,j,z);
57  break;
58  default:
59  break;
60  }
61 }
RecordingMode recordingmode
Definition: WeightMonitor.h:70
The entire Monitor will record from a single synapse specified at initialization. ...
Definition: WeightMonitor.h:45
void add_to_list(AurynWeight *ptr)
Adds a single element to the recording list which is identified by a pointer.
Definition: WeightMonitor.cpp:98
NeuronID elem_j
Definition: WeightMonitor.h:72
void init()
Standard initializer to be called by the constructor.
Definition: Device.cpp:32
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
Monitor()
Constructor which does not open a text file for output.
Definition: Monitor.cpp:47
double auryn_timestep
Simulation timestep in seconds.
Definition: auryn_definitions.cpp:31
The Monitor will record from a range of synapses specified at initialization.
Definition: WeightMonitor.h:46
void add_to_list_by_data_index(AurynLong index, StateID z=0)
Adds a single element to the recording list which is identified by its data index and z-state...
Definition: WeightMonitor.cpp:93
NeuronID elem_i
Definition: WeightMonitor.h:71
Here is the call graph for this function:

◆ ~WeightMonitor()

WeightMonitor::~WeightMonitor ( )
virtual
64 {
65  delete element_list;
66 
67 }
std::vector< AurynLong > * element_list
Definition: WeightMonitor.h:74

Member Function Documentation

◆ add_equally_spaced()

void WeightMonitor::add_equally_spaced ( NeuronID  number,
NeuronID  z = 0 
)

Adds number of elements to the recording list that are equally spaced in the data vector of the connection matrix.

This effectively corresponds to a number of random connection matrix elements (if a random matrix is used). The second argument can be used to specify which complex synapse state should be used for this operation when complex synapses are used.

146 {
147  if ( z >= mat->get_num_z_values() ) {
148  auryn::logger->msg("WeightMonitor:: z too large. Trying to monitor complex "
149  "synaptic values which do not exist."
150  ,ERROR);
151  return;
152  }
153 
154  if ( number > src->get_nonzero() ) {
155  auryn::logger->msg("WeightMonitor:: add_equally_spaced: "
156  "Not enough elements in this Connection object",WARNING);
157  number = src->get_nonzero();
158  }
159 
160  for ( NeuronID i = 0 ; i < number ; ++i )
161  add_to_list(mat->get_data_begin(z)+i*mat->get_nonzero()/number);
162 
163  std::stringstream oss;
164  oss << "WeightMonitor:: "
165  << "Added "
166  << number
167  << " equally spaced values.";
168  auryn::logger->msg(oss.str(),VERBOSE);
169 }
SparseConnection * src
Definition: WeightMonitor.h:68
void add_to_list(AurynWeight *ptr)
Adds a single element to the recording list which is identified by a pointer.
Definition: WeightMonitor.cpp:98
Definition: Logger.h:41
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
StateID get_num_z_values()
Returns number of synaptic states (z-value)
Definition: ComplexMatrix.h:721
T * get_data_begin(const StateID z=0)
Returns pointer to data value corresponding to the first element.
Definition: ComplexMatrix.h:971
ForwardMatrix * mat
Definition: WeightMonitor.h:69
Definition: Logger.h:41
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
AurynLong get_nonzero()
Returns number of nonzero elements in this SparseConnection.
Definition: SparseConnection.cpp:949
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Here is the call graph for this function:

◆ add_to_list() [1/3]

void WeightMonitor::add_to_list ( AurynWeight ptr)

Adds a single element to the recording list which is identified by a pointer.

99 {
100  if ( ptr != NULL ) {
101  element_list->push_back( mat->get_data_index(ptr) );
102  }
103 }
std::vector< AurynLong > * element_list
Definition: WeightMonitor.h:74
ForwardMatrix * mat
Definition: WeightMonitor.h:69
AurynLong get_data_index(const NeuronID *ind_ptr)
Returns data index to a particular element specifed by an index pointer.
Definition: ComplexMatrix.h:802
Here is the call graph for this function:

◆ add_to_list() [2/3]

void WeightMonitor::add_to_list ( NeuronID  i,
NeuronID  j,
StateID  z = 0 
)

Adds a single element identified matrix coordinates (row,col,z) to the recording list.

106 {
107  if ( mat->exists(i, j, z) ) {
109  } else {
110  std::stringstream oss;
111  oss << "WeightMonitor:: Tried adding element "
112  << i << ", "
113  << j << " "
114  "z=" << z << " "
115  << " but element does not exist";
116  logger->msg(oss.str());
117  }
118 }
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
ForwardMatrix * mat
Definition: WeightMonitor.h:69
bool exists(const NeuronID i, const NeuronID j, const StateID z=0)
Returns true if the matrix element exists.
Definition: ComplexMatrix.h:692
void add_to_list_by_data_index(AurynLong index, StateID z=0)
Adds a single element to the recording list which is identified by its data index and z-state...
Definition: WeightMonitor.cpp:93
AurynLong get_data_index(const NeuronID *ind_ptr)
Returns data index to a particular element specifed by an index pointer.
Definition: ComplexMatrix.h:802
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
Here is the call graph for this function:

◆ add_to_list() [3/3]

void WeightMonitor::add_to_list ( std::vector< neuron_pair vec,
std::string  label = "" 
)

Adds a list vector<neuron_pair> vec the the recording list.

Such a list can for instance be generated by a SparseConnection with the get_block function.

121 {
123  std::stringstream oss;
124  oss << "WeightMonitor:: Adding " << vec.size() << " elements to index list " << label;
125  auryn::logger->msg(oss.str(),VERBOSE);
126 
127  if ( label.empty() )
128  outfile << "# Added list with " << vec.size() << " elements." << std::endl;
129  else
130  outfile << "# Added list " << label << " with " << vec.size() << " elements." << std::endl;
131 
132  for (std::vector<neuron_pair>::iterator iter = vec.begin() ; iter != vec.end() ; ++iter)
133  {
134  add_to_list( (*iter).i, (*iter).j );
135  }
136  } else {
137  std::stringstream oss;
138  oss << "WeightMonitor:: "
139  << "Cannot add weight list. Not in ELEMENTLIST or GROUP mode."
140  << std::endl;
141  auryn::logger->msg(oss.str(),ERROR);
142  }
143 }
RecordingMode recordingmode
Definition: WeightMonitor.h:70
void add_to_list(AurynWeight *ptr)
Adds a single element to the recording list which is identified by a pointer.
Definition: WeightMonitor.cpp:98
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
std::ofstream outfile
Definition: Monitor.h:58
The Monitor records from selected synapses stored in a list. This is the default behavior.
Definition: WeightMonitor.h:47
Definition: Logger.h:41
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
Definition: WeightMonitor.h:48
Here is the call graph for this function:

◆ add_to_list_by_data_index()

void WeightMonitor::add_to_list_by_data_index ( AurynLong  index,
StateID  z = 0 
)

Adds a single element to the recording list which is identified by its data index and z-state.

Parameters
indexThe index in the data array of this sparse matrix.
zThe id of the complex matrix state to record from.
94 {
95  element_list->push_back( data_index + z*mat->get_statesize() );
96 }
std::vector< AurynLong > * element_list
Definition: WeightMonitor.h:74
ForwardMatrix * mat
Definition: WeightMonitor.h:69
AurynLong get_statesize()
Same as datasize : number of possible entries.
Definition: ComplexMatrix.h:657
Here is the call graph for this function:

◆ execute()

void WeightMonitor::execute ( )
virtual

propagate function used by System class internally

Reimplemented from auryn::Device.

349 {
350  if ( src->get_destination()->evolve_locally() ) {
351  if (auryn::sys->get_clock()%ssize==0) {
352  outfile << std::fixed << auryn_timestep*(auryn::sys->get_clock()) << std::scientific << " ";
354  else record_single_synapses();
355  outfile << "\n";
356  }
357  }
358 }
RecordingMode recordingmode
Definition: WeightMonitor.h:70
SparseConnection * src
Definition: WeightMonitor.h:68
NeuronGroup * get_destination()
Returns pointer to the postsynaptic group.
Definition: Connection.cpp:203
AurynTime ssize
Definition: WeightMonitor.h:73
bool evolve_locally()
Returns true if the calling instance has units which are integrated on the current rank...
Definition: SpikingGroup.cpp:323
std::ofstream outfile
Definition: Monitor.h:58
double auryn_timestep
Simulation timestep in seconds.
Definition: auryn_definitions.cpp:31
System * sys
Global pointer to instance of System which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:37
void record_synapse_groups()
Definition: WeightMonitor.cpp:330
void record_single_synapses()
Definition: WeightMonitor.cpp:318
AurynTime get_clock()
Gets the current clock value in AurynTime.
Definition: System.cpp:231
Definition: WeightMonitor.h:48
Here is the call graph for this function:

◆ init()

void WeightMonitor::init ( SparseConnection source,
NeuronID  i,
NeuronID  j,
std::string  filename,
AurynTime  interval 
)
protected
70 {
72  src = source;
73  set_mat(src->w);
74  ssize = stepsize;
75  if ( ssize < 1 ) ssize = 1;
76 
77  outfile << std::setiosflags(std::ios::fixed) << std::setprecision(6);
78 
79  std::stringstream oss;
80  oss << "WeightMonitor:: "
81  << "Initialized. Writing to file "
82  << fname;
83  auryn::logger->msg(oss.str(),VERBOSE);
84 
85  // default behavior
87  element_list = new std::vector<AurynLong>;
88  group_indices.push_back(0); // important for group mode
89  elem_i = 0;
90  elem_j = 0;
91 }
std::vector< NeuronID > group_indices
Definition: WeightMonitor.h:75
RecordingMode recordingmode
Definition: WeightMonitor.h:70
SparseConnection * src
Definition: WeightMonitor.h:68
std::vector< AurynLong > * element_list
Definition: WeightMonitor.h:74
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
AurynTime ssize
Definition: WeightMonitor.h:73
NeuronID elem_j
Definition: WeightMonitor.h:72
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
std::ofstream outfile
Definition: Monitor.h:58
void register_device(Device *device)
Registers an instance of Device to the devices vector.
Definition: System.cpp:272
System * sys
Global pointer to instance of System which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:37
The Monitor records from selected synapses stored in a list. This is the default behavior.
Definition: WeightMonitor.h:47
std::string fname
Definition: Monitor.h:61
void set_mat(ForwardMatrix *m)
Sets target matrix to read from.
Definition: WeightMonitor.cpp:360
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
NeuronID elem_i
Definition: WeightMonitor.h:71
Here is the call graph for this function:

◆ load_data_range()

void WeightMonitor::load_data_range ( AurynLong  i,
AurynLong  j 
)

Adds connections from a given range in the sparse matrix data array.

172 {
173  if ( !src->get_destination()->evolve_locally() ) return;
174 
175  if ( j > mat->get_nonzero() )
176  j = mat->get_nonzero();
177  std::stringstream oss;
178  oss << "WeightMonitor:: "
179  << "Adding data range i="
180  << i
181  << " j="
182  << j;
183  auryn::logger->msg(oss.str(),VERBOSE);
184  for ( NeuronID a = i ; a < j ; ++a )
185  element_list->push_back( a );
186  outfile << "# Added data range " << i << "-" << j << "." << std::endl;
187 }
SparseConnection * src
Definition: WeightMonitor.h:68
std::vector< AurynLong > * element_list
Definition: WeightMonitor.h:74
NeuronGroup * get_destination()
Returns pointer to the postsynaptic group.
Definition: Connection.cpp:203
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
bool evolve_locally()
Returns true if the calling instance has units which are integrated on the current rank...
Definition: SpikingGroup.cpp:323
std::ofstream outfile
Definition: Monitor.h:58
ForwardMatrix * mat
Definition: WeightMonitor.h:69
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Here is the call graph for this function:

◆ load_patfile()

std::vector< type_pattern > * WeightMonitor::load_patfile ( std::string  filename,
unsigned int  maxpat 
)
protected
190 {
191 
192  std::vector<type_pattern> * patterns = new std::vector<type_pattern>;
193 
194 
195  std::ifstream fin (filename.c_str());
196  if (!fin) {
197  std::stringstream oss;
198  oss << "WeightMonitor:: "
199  << "There was a problem opening file "
200  << filename
201  << " for reading."
202  << std::endl;
203  auryn::logger->msg(oss.str(),ERROR);
204  throw AurynOpenFileException();
205  }
206 
207  char buffer[256];
208  std::string line;
209 
210 
211  type_pattern pattern;
212  int total_pattern_size = 0;
213  while( !fin.eof() && patterns->size() < maxpat ) {
214 
215  line.clear();
216  fin.getline (buffer,255);
217  line = buffer;
218 
219  if (line[0] == '#') continue;
220  if (line == "") {
221  if ( total_pattern_size > 0 ) {
222  std::stringstream oss;
223  oss << "WeightMonitor:: Read pattern "
224  << patterns->size()
225  << " with pattern size "
226  << total_pattern_size
227  << " ( "
228  << pattern.size()
229  << " on rank )";
230  auryn::logger->msg(oss.str(),VERBOSE);
231 
232  patterns->push_back(pattern);
233  pattern.clear();
234  total_pattern_size = 0;
235  }
236  continue;
237  }
238 
239  std::stringstream iss (line);
240  NeuronID i ;
241  iss >> i ;
242  pattern_member pm;
243  pm.gamma = 1 ;
244  iss >> pm.gamma ;
245  pm.i = i ;
246  pattern.push_back( pm ) ;
247  total_pattern_size++;
248  }
249  fin.close();
250 
251 
252 
253  return patterns;
254 }
NeuronID i
Definition: auryn_definitions.h:173
std::vector< pattern_member > type_pattern
Definition: auryn_definitions.h:177
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
Definition: auryn_definitions.h:208
AurynDouble gamma
Definition: auryn_definitions.h:174
Definition: Logger.h:41
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
Struct used to define neuronal assembly patterns in SparseConnection.
Definition: auryn_definitions.h:172
std::string string
Standard library string type which is imported into Auryn namespace.
Definition: auryn_definitions.h:156
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Here is the call graph for this function:

◆ load_pattern_connections() [1/2]

void WeightMonitor::load_pattern_connections ( std::string  filename,
unsigned int  maxcon = 5,
unsigned int  maxpat = 10,
PatternMode  patmod = ALLTOALL 
)

Adds connections inside a pattern and between patterns. Since such lists can become large quickly the amount of patterns and connections for each pattern to be monitored can be limited by maxcon and maxpat.

Parameters
filenameThe filename of the .pat file
maxconmaximum number of connection per pattern or between patterns
maxpatmaximum number of patterns to read from .pat file
patmodALLTOALL means from all patterns to all patterns. ASSEMBLIES_ONLY only adds connections inside single patterns.
257 {
258  load_pattern_connections( filename, filename, maxcon, maxpat, patmod );
259 }
void load_pattern_connections(string filename, unsigned int maxcon=5, unsigned int maxpat=10, PatternMode patmod=ALLTOALL)
Adds connections inside a pattern and between patterns. Since such lists can become large quickly the...
Definition: WeightMonitor.cpp:256

◆ load_pattern_connections() [2/2]

void WeightMonitor::load_pattern_connections ( std::string  filename_pre,
std::string  filename_post,
unsigned int  maxcon = 5,
unsigned int  maxpat = 10,
PatternMode  patmod = ALLTOALL 
)
263 {
264  if ( !src->get_destination()->evolve_locally() ) return ;
265 
266  std::vector<type_pattern> * patterns_pre = load_patfile(filename_pre, maxpat);
267  std::vector<type_pattern> * patterns_post = patterns_pre;
268 
269  if ( filename_pre.compare(filename_post) )
270  patterns_pre = load_patfile(filename_post, maxpat);
271 
272 
273 
274  for ( unsigned int i = 0 ; i < patterns_pre->size() ; ++i ) {
275  for ( unsigned int j = 0 ; j < patterns_post->size() ; ++j ) {
276  if ( patmod==ASSEMBLIES_ONLY && i != j ) continue;
277  std::vector<neuron_pair> list;
278  for ( unsigned int k = 0 ; k < patterns_pre->at(i).size() ; ++k ) {
279  for ( unsigned int l = 0 ; l < patterns_post->at(j).size() ; ++l ) {
280  neuron_pair p;
281  p.i = patterns_pre->at(i)[k].i;
282  p.j = patterns_post->at(j)[l].i;
283  AurynWeight * ptr = mat->get_ptr(p.i,p.j);
284  if ( ptr != NULL ) { // make sure we are counting connections that do exist
285  list.push_back( p );
286  }
287  if ( list.size() >= maxcon ) break;
288  }
289  if ( list.size() >= maxcon ) break;
290  }
291 
292 
293  std::stringstream oss;
294  oss << "(connections " << i << " to " << j << ")";
295  add_to_list(list,oss.str());
296  group_indices.push_back(element_list->size());
297  }
298  }
299 
300 
301 
302  std::stringstream oss;
303  oss << "WeightMonitor:: Finished loading connections from n_pre="
304  << patterns_pre->size()
305  << " and n_post="
306  << patterns_post->size()
307  << " patterns";
308  auryn::logger->msg(oss.str(),NOTIFICATION);
309 
310 
311  if ( patterns_pre != patterns_post )
312  delete patterns_post;
313  delete patterns_pre;
314 
315 }
std::vector< NeuronID > group_indices
Definition: WeightMonitor.h:75
T * get_ptr(const NeuronID i, const NeuronID j, const StateID z=0)
Returns the pointer to a particular element.
Definition: ComplexMatrix.h:814
SparseConnection * src
Definition: WeightMonitor.h:68
std::vector< AurynLong > * element_list
Definition: WeightMonitor.h:74
Struct that defines a pair of neurons in SparseConnection.
Definition: auryn_definitions.h:167
NeuronGroup * get_destination()
Returns pointer to the postsynaptic group.
Definition: Connection.cpp:203
void add_to_list(AurynWeight *ptr)
Adds a single element to the recording list which is identified by a pointer.
Definition: WeightMonitor.cpp:98
std::vector< type_pattern > * load_patfile(string filename, unsigned int maxpat)
Definition: WeightMonitor.cpp:189
AurynFloat AurynWeight
Unit of synaptic weights.
Definition: auryn_definitions.h:159
Definition: Logger.h:41
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
bool evolve_locally()
Returns true if the calling instance has units which are integrated on the current rank...
Definition: SpikingGroup.cpp:323
ForwardMatrix * mat
Definition: WeightMonitor.h:69
NeuronID i
Definition: auryn_definitions.h:168
Definition: WeightMonitor.h:55
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
NeuronID j
Definition: auryn_definitions.h:168
Here is the call graph for this function:

◆ record_single_synapses()

void WeightMonitor::record_single_synapses ( )
protected
319 {
320  for (std::vector<AurynLong>::iterator iter = element_list->begin() ; iter != element_list->end() ; ++iter) {
321  // the following is a workaround for the old WeightMonitor data_index ptr log to work with the new state vector
322  // based ComplexMatrix class
323  // thus we need to translate the data index to a state variable z and the actual new data_index
324  const AurynLong data_index = (*iter)%src->w->get_statesize();
325  const StateID z = (*iter)/src->w->get_statesize();
326  outfile << mat->get_data( data_index, z ) << " ";
327  }
328 }
SparseConnection * src
Definition: WeightMonitor.h:68
std::vector< AurynLong > * element_list
Definition: WeightMonitor.h:74
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
T get_data(AurynLong i, StateID z=0)
Definition: ComplexMatrix.h:408
std::ofstream outfile
Definition: Monitor.h:58
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
ForwardMatrix * mat
Definition: WeightMonitor.h:69
unsigned int StateID
StateID is an unsigned integeger type used to index synaptic states in Auryn.
Definition: auryn_definitions.h:153
AurynLong get_statesize()
Same as datasize : number of possible entries.
Definition: ComplexMatrix.h:657
Here is the call graph for this function:

◆ record_synapse_groups()

void WeightMonitor::record_synapse_groups ( )
protected
331 {
332  for ( unsigned int i = 1 ; i < group_indices.size() ; ++i ) {
333  AurynDouble sum = 0;
334  AurynDouble sum2 = 0;
335 
336  for ( unsigned int k = group_indices[i-1] ; k < group_indices[i] ; ++k ) {
337  sum += mat->get_data( element_list->at(k) );
338  sum2 += pow( mat->get_data( element_list->at(k) ), 2);
339  }
340  NeuronID n = group_indices[i]-group_indices[i-1];
341  AurynDouble mean = sum/n;
342  AurynDouble stdev = sqrt(sum2/n-mean*mean);
343  outfile << mean << " " << stdev << " ";
344  }
345 }
std::vector< NeuronID > group_indices
Definition: WeightMonitor.h:75
std::vector< AurynLong > * element_list
Definition: WeightMonitor.h:74
double AurynDouble
Higher precision floating point datatype.
Definition: auryn_definitions.h:158
int n
Definition: mkpat.py:5
T get_data(AurynLong i, StateID z=0)
Definition: ComplexMatrix.h:408
std::ofstream outfile
Definition: Monitor.h:58
ForwardMatrix * mat
Definition: WeightMonitor.h:69
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Here is the call graph for this function:

◆ set_mat()

void WeightMonitor::set_mat ( ForwardMatrix m)

Sets target matrix to read from.

361 {
362  mat = m;
363 }
ForwardMatrix * mat
Definition: WeightMonitor.h:69

Member Data Documentation

◆ elem_i

NeuronID auryn::WeightMonitor::elem_i
protected

◆ elem_j

NeuronID auryn::WeightMonitor::elem_j
protected

◆ element_list

std::vector<AurynLong>* auryn::WeightMonitor::element_list
protected

◆ group_indices

std::vector<NeuronID> auryn::WeightMonitor::group_indices
protected

◆ mat

ForwardMatrix* auryn::WeightMonitor::mat
protected

◆ recordingmode

RecordingMode auryn::WeightMonitor::recordingmode
protected

◆ src

SparseConnection* auryn::WeightMonitor::src
protected

◆ ssize

AurynTime auryn::WeightMonitor::ssize
protected

The documentation for this class was generated from the following files: