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

Records mean weights from a connection specified by one or two pattern files. Can be used to easily monitor the mean synaptic weight in assemblies or feed-forward connections of populations of neurons. More...

#include <WeightPatternMonitor.h>

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

Public Member Functions

 WeightPatternMonitor (Connection *source, string filename, AurynDouble binsize=10.0)
 
void load_pre_patterns (string filename)
 
void load_post_patterns (string filename)
 
void load_patterns (string filename)
 
virtual ~WeightPatternMonitor ()
 
void execute ()
 

Public Attributes

size_t max_patterns
 

Protected Member Functions

void init (Connection *source, string filename, AurynTime stepsize)
 
AurynWeight compute_pattern_mean (const NeuronID i, const NeuronID j)
 
void load_patterns (std::string filename, std::vector< type_pattern > &patterns)
 
- 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

Connectionsrc
 
AurynTime ssize
 
std::vector< type_patternpre_patterns
 
std::vector< type_patternpost_patterns
 
- 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

Records mean weights from a connection specified by one or two pattern files. Can be used to easily monitor the mean synaptic weight in assemblies or feed-forward connections of populations of neurons.

Constructor & Destructor Documentation

◆ WeightPatternMonitor()

WeightPatternMonitor::WeightPatternMonitor ( Connection source,
std::string  filename,
AurynDouble  binsize = 10.0 
)
30  : Monitor(filename)
31 {
32  init(source,filename,binsize/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:

◆ ~WeightPatternMonitor()

WeightPatternMonitor::~WeightPatternMonitor ( )
virtual
36 {
37 }

Member Function Documentation

◆ compute_pattern_mean()

AurynWeight WeightPatternMonitor::compute_pattern_mean ( const NeuronID  i,
const NeuronID  j 
)
protected
56 {
57  AurynWeight sum = 0;
58  // AurynFloat sum2 = 0;
59  NeuronID n = 0;
60  for ( NeuronID k = 0 ; k < pre_patterns[i].size() ; ++k ) {
61  for ( NeuronID l = 0 ; l < post_patterns[j].size() ; ++l ) {
62  pattern_member p = pre_patterns[i][k];
63  pattern_member q = post_patterns[j][l];
64  AurynWeight * val = src->get_ptr(p.i,q.i);
65  if ( val ) {
66  sum += *val;
67  // sum2 += *val* *val;
68  n++;
69  }
70  }
71  }
72  AurynFloat mean = sum/n;
73  return mean;
74 }
NeuronID i
Definition: auryn_definitions.h:173
AurynFloat AurynWeight
Unit of synaptic weights.
Definition: auryn_definitions.h:159
int n
Definition: mkpat.py:5
virtual AurynWeight * get_ptr(NeuronID i, NeuronID j)=0
Return pointer to weight element i,j if it exists, otherwise return NULL.
float AurynFloat
Low precision floating point datatype.
Definition: auryn_definitions.h:157
std::vector< type_pattern > pre_patterns
Definition: WeightPatternMonitor.h:51
Connection * src
Definition: WeightPatternMonitor.h:46
Struct used to define neuronal assembly patterns in SparseConnection.
Definition: auryn_definitions.h:172
std::vector< type_pattern > post_patterns
Definition: WeightPatternMonitor.h:52
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:

◆ execute()

void WeightPatternMonitor::execute ( )
virtual

Virtual execute function to be called at the end of central simulation loop in System

Reimplemented from auryn::Device.

77 {
78  if (auryn::sys->get_clock()%ssize==0) {
79  outfile << std::fixed << (auryn::sys->get_time()) << " ";
80 
81  int p = std::min(std::min(pre_patterns.size(),post_patterns.size()),max_patterns);
82 
83  for ( int i = 0 ; i < p ; ++i ) {
84  for ( int j = 0 ; j < p ; ++j ) {
85  outfile << std::scientific
86  << compute_pattern_mean(i,j)
87  << " ";
88  }
89  }
90  outfile << std::endl;
91  }
92 }
AurynWeight compute_pattern_mean(const NeuronID i, const NeuronID j)
Definition: WeightPatternMonitor.cpp:55
AurynTime ssize
Definition: WeightPatternMonitor.h:47
std::ofstream outfile
Definition: Monitor.h:58
size_t max_patterns
Definition: WeightPatternMonitor.h:63
System * sys
Global pointer to instance of System which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:37
AurynDouble get_time()
Gets the current system time in [s].
Definition: System.cpp:226
std::vector< type_pattern > pre_patterns
Definition: WeightPatternMonitor.h:51
std::vector< type_pattern > post_patterns
Definition: WeightPatternMonitor.h:52
Here is the call graph for this function:

◆ init()

void WeightPatternMonitor::init ( Connection source,
std::string  filename,
AurynTime  stepsize 
)
protected
40 {
41  if ( !source->get_destination()->evolve_locally() ) return;
42 
44 
45  src = source;
46  ssize = stepsize;
47  if ( ssize < 1 ) ssize = 1;
48 
49  outfile << std::setiosflags(std::ios::fixed) << std::setprecision(6);
50 
51  max_patterns = 5;
52 }
NeuronGroup * get_destination()
Returns pointer to the postsynaptic group.
Definition: Connection.cpp:203
AurynTime ssize
Definition: WeightPatternMonitor.h:47
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
void register_device(Device *device)
Registers an instance of Device to the devices vector.
Definition: System.cpp:272
size_t max_patterns
Definition: WeightPatternMonitor.h:63
System * sys
Global pointer to instance of System which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:37
Connection * src
Definition: WeightPatternMonitor.h:46
Here is the call graph for this function:

◆ load_patterns() [1/2]

void WeightPatternMonitor::load_patterns ( std::string  filename,
std::vector< type_pattern > &  patterns 
)
protected

Mother function for loading patterns

96 {
97  std::ifstream fin (filename.c_str());
98  if (!fin) {
99  std::stringstream oss;
100  oss << "WeightPatternMonitor:: "
101  << "There was a problem opening file "
102  << filename
103  << " for reading."
104  << std::endl;
105  auryn::logger->msg(oss.str(),ERROR);
106  throw AurynOpenFileException();
107  }
108 
109  char buffer[256];
110  std::string line;
111 
112  patterns.clear();
113 
114  type_pattern pattern;
115  int total_pattern_size = 0;
116  while(!fin.eof()) {
117 
118  line.clear();
119  fin.getline (buffer,255);
120  line = buffer;
121 
122  if (line[0] == '#') continue;
123  if (line == "") {
124  if ( total_pattern_size > 0 ) {
125  std::stringstream oss;
126  oss << "WeightPatternMonitor:: Read pattern "
127  << patterns.size()
128  << " with pattern size "
129  << total_pattern_size
130  << " ( "
131  << pattern.size()
132  << " on rank )";
133  auryn::logger->msg(oss.str(),VERBOSE);
134 
135  patterns.push_back(pattern);
136  pattern.clear();
137  total_pattern_size = 0;
138  }
139  continue;
140  }
141 
142  std::stringstream iss (line);
143  NeuronID i ;
144  iss >> i ;
145  pattern_member pm;
146  pm.gamma = 1.0 ;
147  iss >> pm.gamma ;
148  pm.i = i ;
149  pattern.push_back( pm ) ;
150  total_pattern_size++;
151  }
152 
153  fin.close();
154 
155  std::stringstream oss;
156  oss << "WeightPatternMonitor:: Finished loading " << patterns.size() << " patterns";
157  auryn::logger->msg(oss.str(),NOTIFICATION);
158 }
NeuronID i
Definition: auryn_definitions.h:173
Definition: Logger.h:41
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_patterns() [2/2]

void WeightPatternMonitor::load_patterns ( std::string  filename)

Loads patterns for symmetric assembly monitoring

171 {
172  load_pre_patterns(filename);
173  load_post_patterns(filename);
174 }
void load_post_patterns(string filename)
Definition: WeightPatternMonitor.cpp:165
void load_pre_patterns(string filename)
Definition: WeightPatternMonitor.cpp:160
Here is the call graph for this function:

◆ load_post_patterns()

void WeightPatternMonitor::load_post_patterns ( std::string  filename)

Loads post patterns for asymmetric monitoring. Each post pattern needs to be matched by a corresponding pre pattern otherwise there will be a crash.

166 {
167  load_patterns(filename,post_patterns);
168 }
void load_patterns(std::string filename, std::vector< type_pattern > &patterns)
Definition: WeightPatternMonitor.cpp:95
std::vector< type_pattern > post_patterns
Definition: WeightPatternMonitor.h:52
Here is the call graph for this function:

◆ load_pre_patterns()

void WeightPatternMonitor::load_pre_patterns ( std::string  filename)

Loads pre patterns for asymmetric monitoring. Each pre pattern needs to be matched by a corresponding post pattern otherwise there will be a crash.

161 {
162  load_patterns(filename,pre_patterns);
163 }
void load_patterns(std::string filename, std::vector< type_pattern > &patterns)
Definition: WeightPatternMonitor.cpp:95
std::vector< type_pattern > pre_patterns
Definition: WeightPatternMonitor.h:51
Here is the call graph for this function:

Member Data Documentation

◆ max_patterns

size_t auryn::WeightPatternMonitor::max_patterns

Maximum number of patterns to record from

◆ post_patterns

std::vector<type_pattern> auryn::WeightPatternMonitor::post_patterns
protected

◆ pre_patterns

std::vector<type_pattern> auryn::WeightPatternMonitor::pre_patterns
protected

◆ src

Connection* auryn::WeightPatternMonitor::src
protected

◆ ssize

AurynTime auryn::WeightPatternMonitor::ssize
protected

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