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::PatternMonitor Class Reference

Monitor class to record population firing rates. More...

#include <PatternMonitor.h>

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

Public Member Functions

 PatternMonitor (SpikingGroup *source, string filename, string patfile, NeuronID maximum_patterns=10, AurynFloat binsize=1e-1)
 
 PatternMonitor (SpikingGroup *source, string filename, StimulusGroup *stimgroup, NeuronID maximum_patterns=10, AurynFloat binsize=1e-1)
 
virtual ~PatternMonitor ()
 
void execute ()
 
void load_patterns (string filename)
 

Protected Member Functions

void init (SpikingGroup *source, string filename, NeuronID maximum_patterns, AurynFloat binsize)
 
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)
 
- Protected Member Functions inherited from auryn::Monitor
virtual void open_output_file (std::string filename)
 
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

SpikingGroupsrc
 
- 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

Monitor class to record population firing rates.

Instances of this class record the population firing rate of the src SpikingGroup assigned. Binning is done discretely in bins of size bsize that is directly transformed in discrete AurynTime steps.

Constructor & Destructor Documentation

◆ PatternMonitor() [1/2]

PatternMonitor::PatternMonitor ( SpikingGroup source,
std::string  filename,
std::string  patfile,
NeuronID  maximum_patterns = 10,
AurynFloat  binsize = 1e-1 
)

Default Constructor

Parameters
30  : Monitor(filename)
31 {
32  init(source,filename,maximum_patterns,binsize);
33  load_patterns(patfile);
34 }
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
void load_patterns(string filename)
Definition: PatternMonitor.cpp:112
Here is the call graph for this function:

◆ PatternMonitor() [2/2]

PatternMonitor::PatternMonitor ( SpikingGroup source,
std::string  filename,
StimulusGroup stimgroup,
NeuronID  maximum_patterns = 10,
AurynFloat  binsize = 1e-1 
)

Constructor that loads patterns from a StimulusGroup

Parameters
36  : Monitor(filename)
37 {
38  init(source,filename,maximum_patterns,binsize);
39  delete patterns;
40  linked_to_stimgroup = true;
41  patterns = stimgroup->get_patterns();
42 
43  std::stringstream oss;
44  oss << "PatternMonitor:: Linked to StimulusGroup";
45  auryn::logger->msg(oss.str(),NOTIFICATION);
46 }
Definition: Logger.h:41
std::vector< type_pattern > * get_patterns()
Definition: StimulusGroup.cpp:554
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
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
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:

◆ ~PatternMonitor()

PatternMonitor::~PatternMonitor ( )
virtual

Default Destructor

49 {
50  delete [] counter;
51  if ( !linked_to_stimgroup )
52  delete patterns;
53 }

Member Function Documentation

◆ execute()

void PatternMonitor::execute ( )
virtual

Implementation of necessary execute() function.

Reimplemented from auryn::Device.

82 {
83  if ( src->evolve_locally() ) {
84  for ( SpikeContainer::const_iterator iter = src->get_spikes_immediate()->begin() ;
85  iter != src->get_spikes_immediate()->end() ; ++iter ) {
86  counter[src->global2rank(*iter)] += 1; // might be more memory efficent to count here in rankIDs (local)
87  }
88 
89  if (auryn::sys->get_clock()%ssize==0) {
91  for ( std::vector<type_pattern>::iterator pattern = patterns->begin() ;
92  pattern != patterns->end() ; ++pattern ) {
93  double sum = 0.;
94  for ( type_pattern::iterator piter = pattern->begin() ; piter != pattern->end() ; ++piter ) {
95  if ( counter[piter->i] > 0 ) {
96  sum += counter[piter->i];
97  }
98  }
99  double mean = sum/pattern->size();
100  outfile << " " << mean/bsize;
101  }
102 
103  outfile << "\n"; //newline
104 
105  // reset counter
106  for ( NeuronID i = 0 ; i < src->get_rank_size() ; ++i )
107  counter[i] = 0;
108  }
109  }
110 }
NeuronID get_rank_size()
Returns the size on this rank.
Definition: SpikingGroup.h:450
NeuronID global2rank(NeuronID i)
Converts global NeuronID within the SpikingGroup to the local NeuronID on this rank.
Definition: SpikingGroup.h:446
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
SpikeContainer * get_spikes_immediate()
Returns pointer to SpikeContainer of spikes generated during the last evolve() step.
Definition: SpikingGroup.cpp:250
AurynTime get_clock()
Gets the current clock value in AurynTime.
Definition: System.cpp:231
SpikingGroup * src
Definition: PatternMonitor.h:65
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:

◆ init()

void PatternMonitor::init ( SpikingGroup source,
std::string  filename,
NeuronID  maximum_patterns,
AurynFloat  binsize 
)
protected

Default init method

56 {
58 
59  linked_to_stimgroup = false;
60 
61  src = source;
62  bsize = binsize;
63  ssize = bsize/auryn_timestep;
64  if ( ssize < 1 ) ssize = 1;
65 
66  maxpat = maximum_patterns;
67 
68  counter = new NeuronID [src->get_rank_size()];
69  patterns = new std::vector<type_pattern>;
70 
71  for ( NeuronID i = 0 ; i < src->get_rank_size() ; ++i )
72  counter[i] = 0;
73 
74  std::stringstream oss;
75  oss << "PatternMonitor:: Setting binsize " << bsize << "s";
76  auryn::logger->msg(oss.str(),NOTIFICATION);
77 
78  outfile << std::setiosflags(std::ios::fixed) << std::setprecision(6);
79 }
NeuronID get_rank_size()
Returns the size on this rank.
Definition: SpikingGroup.h:450
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
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
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 msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
SpikingGroup * src
Definition: PatternMonitor.h:65
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()

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

Load patterns from file

113 {
114 
115  // if ( not src->evolve_locally() ) return ;
116 
117  std::ifstream fin (filename.c_str());
118  if (!fin) {
119  std::stringstream oss;
120  oss << "PatternMonitor:: "
121  << "There was a problem opening file "
122  << filename
123  << " for reading."
124  << std::endl;
125  auryn::logger->msg(oss.str(),ERROR);
126  return;
127  }
128 
129  char buffer[256];
130  std::string line;
131 
132  type_pattern pattern;
133  int total_pattern_size = 0;
134  while( !fin.eof() && patterns->size() < maxpat ) {
135 
136  line.clear();
137  fin.getline (buffer,255);
138  line = buffer;
139 
140  if (line[0] == '#') continue;
141  if (line == "") {
142  if ( total_pattern_size > 0 ) {
143  std::stringstream oss;
144  oss << "PatternMonitor:: Read pattern "
145  << patterns->size()
146  << " with pattern size "
147  << total_pattern_size
148  << " ( "
149  << pattern.size()
150  << " on rank )";
151  auryn::logger->msg(oss.str(),VERBOSE);
152 
153  patterns->push_back(pattern);
154  pattern.clear();
155  total_pattern_size = 0;
156  }
157  continue;
158  }
159 
160  std::stringstream iss (line);
161  NeuronID i ;
162  iss >> i ;
163  if ( src->localrank( i ) ) {
164  pattern_member pm;
165  pm.gamma = 1 ;
166  iss >> pm.gamma ;
167  pm.i = src->global2rank( i ) ;
168  pattern.push_back( pm ) ;
169  }
170  total_pattern_size++;
171  }
172 
173  fin.close();
174 
175  std::stringstream oss;
176  oss << "PatternMonitor:: Finished loading " << patterns->size() << " patterns";
177  auryn::logger->msg(oss.str(),NOTIFICATION);
178 }
NeuronID i
Definition: auryn_definitions.h:173
bool localrank(NeuronID i)
Checks if the global NeuronID i is integrated on this MPI rank.
Definition: SpikingGroup.cpp:531
NeuronID global2rank(NeuronID i)
Converts global NeuronID within the SpikingGroup to the local NeuronID on this rank.
Definition: SpikingGroup.h:446
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
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
SpikingGroup * src
Definition: PatternMonitor.h:65
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:

◆ virtual_serialize() [1/2]

void PatternMonitor::virtual_serialize ( boost::archive::binary_oarchive &  ar,
const unsigned int  version 
)
protectedvirtual

Functions necesssary for serialization and loading saving to netstate files.

Reimplemented from auryn::Monitor.

181 {
182  for ( NeuronID i = 0 ; i < src->get_rank_size() ; ++i )
183  ar & counter[i] ;
184 }
NeuronID get_rank_size()
Returns the size on this rank.
Definition: SpikingGroup.h:450
SpikingGroup * src
Definition: PatternMonitor.h:65
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:

◆ virtual_serialize() [2/2]

void PatternMonitor::virtual_serialize ( boost::archive::binary_iarchive &  ar,
const unsigned int  version 
)
protectedvirtual

Reimplemented from auryn::Monitor.

187 {
188  for ( NeuronID i = 0 ; i < src->get_rank_size() ; ++i )
189  ar & counter[i] ;
190 }
NeuronID get_rank_size()
Returns the size on this rank.
Definition: SpikingGroup.h:450
SpikingGroup * src
Definition: PatternMonitor.h:65
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:

Member Data Documentation

◆ src

SpikingGroup* auryn::PatternMonitor::src
protected

The source SpikingGroup


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