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

Stimulator class to inject timeseries of currents to patterns (subpopulations) of neurons. More...

#include <PatternStimulator.h>

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

Public Member Functions

 PatternStimulator (NeuronGroup *target, string filename, string patfile="", AurynFloat scale=1, NeuronID maximum_patterns=10)
 
virtual ~PatternStimulator ()
 
void set_scale (AurynFloat scale)
 
AurynFloat get_scale ()
 
void propagate ()
 
void load_patterns (string filename)
 
void load_1_pattern ()
 

Protected Member Functions

void init (NeuronGroup *target, string filename, AurynFloat scale, NeuronID maximum_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 ()
 
virtual void execute ()
 

Protected Attributes

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

Stimulator class to inject timeseries of currents to patterns (subpopulations) of neurons.

Instances of this class inject currents that vary over time to subpopulations of the NeuronGroup assigned.

Constructor & Destructor Documentation

◆ PatternStimulator()

PatternStimulator::PatternStimulator ( NeuronGroup target,
std::string  filename,
std::string  patfile = "",
AurynFloat  scale = 1,
NeuronID  maximum_patterns = 10 
)

Default Constructor

Parameters
30  : Monitor( "" )
31 {
32  init(target,filename,scale,maximum_patterns);
33  std::string s = patfile;
34  if ( s.empty() ) {
35  std::stringstream oss;
36  auryn::logger->msg("No patfile given assuming whole population",NOTIFICATION);
38  } else {
39  load_patterns(patfile);
40  }
41 }
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
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_1_pattern()
Definition: PatternStimulator.cpp:115
void load_patterns(string filename)
Definition: PatternStimulator.cpp:131
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
std::string string
Standard library string type which is imported into Auryn namespace.
Definition: auryn_definitions.h:156
Here is the call graph for this function:

◆ ~PatternStimulator()

PatternStimulator::~PatternStimulator ( )
virtual

Default Destructor

45 {
46  timeseriesfile.close();
47  delete patterns;
48  delete currents;
49  delete newcurrents;
50 }

Member Function Documentation

◆ get_scale()

AurynFloat PatternStimulator::get_scale ( )
206  {
207  return scl;
208 }

◆ init()

void PatternStimulator::init ( NeuronGroup target,
std::string  filename,
AurynFloat  scale,
NeuronID  maximum_patterns 
)
protected

Default init method

53 {
55 
56  dst = target;
57  set_scale(scale);
58  maxpat = maximum_patterns;
59 
60  patterns = new std::vector<type_pattern>;
61 
62  mem = dst->mem;
63 
64  filetime = 0;
65  timeseriesfile.open(filename.c_str(),std::ios::in);
66  if (!timeseriesfile) {
67  std::stringstream oss;
68  oss << "Can't open time series file " << filename;
69  auryn::logger->msg(oss.str(),ERROR);
70  exit(1);
71  }
72 
73 }
NeuronGroup * dst
Definition: PatternStimulator.h:69
void set_scale(AurynFloat scale)
Definition: PatternStimulator.cpp:202
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
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
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
AurynStateVector * mem
Definition: NeuronGroup.h:64
Here is the call graph for this function:

◆ load_1_pattern()

void PatternStimulator::load_1_pattern ( )

Loads the 1111 pattern

116 {
117  type_pattern pattern;
118  for ( unsigned int i = 0 ; i < dst->get_rank_size() ; ++i ) {
119  pattern_member pm;
120  pm.i = i;
121  pm.gamma = 1 ;
122  pattern.push_back( pm ) ;
123  }
124  patterns->push_back(pattern);
125  currents = new AurynState[1];
126  newcurrents = new AurynState[1];
127  currents[0] = 0;
128  newcurrents[0] = 0;
129 }
NeuronID get_rank_size()
Returns the size on this rank.
Definition: SpikingGroup.h:450
NeuronID i
Definition: auryn_definitions.h:173
NeuronGroup * dst
Definition: PatternStimulator.h:69
std::vector< pattern_member > type_pattern
Definition: auryn_definitions.h:177
AurynFloat AurynState
Type for Auryn state variables (default single precision since it needs to be compatible with auryn_v...
Definition: auryn_definitions.h:160
AurynDouble gamma
Definition: auryn_definitions.h:174
Struct used to define neuronal assembly patterns in SparseConnection.
Definition: auryn_definitions.h:172
Here is the call graph for this function:

◆ load_patterns()

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

Load patterns from file

132 {
133  std::ifstream fin (filename.c_str());
134  if (!fin) {
135  std::stringstream oss;
136  oss << "PatternStimulator:: "
137  << "There was a problem opening file "
138  << filename
139  << " for reading."
140  << std::endl;
141  auryn::logger->msg(oss.str(),ERROR);
142  return;
143  }
144 
145  char buffer[256];
146  std::string line;
147 
148  type_pattern pattern;
149  int total_pattern_size = 0;
150  while( !fin.eof() && patterns->size() < maxpat ) {
151 
152  line.clear();
153  fin.getline (buffer,255);
154  line = buffer;
155 
156  if (line[0] == '#') continue;
157  if (line == "") {
158  if ( total_pattern_size > 0 ) {
159  std::stringstream oss;
160  oss << "PatternStimulator:: Read pattern "
161  << patterns->size()
162  << " with pattern size "
163  << total_pattern_size
164  << " ( "
165  << pattern.size()
166  << " on rank )";
167  auryn::logger->msg(oss.str(),VERBOSE);
168  patterns->push_back(pattern);
169  pattern.clear();
170  total_pattern_size = 0;
171  }
172  continue;
173  }
174 
175  std::stringstream iss (line);
176  NeuronID i ;
177  iss >> i ;
178  if ( dst->localrank( i ) ) {
179  pattern_member pm;
180  pm.gamma = 1 ;
181  iss >> pm.gamma ;
182  pm.i = dst->global2rank( i ) ;
183  pattern.push_back( pm ) ;
184  }
185  total_pattern_size++;
186  }
187 
188  fin.close();
189 
190  currents = new AurynState[patterns->size()];
191  newcurrents = new AurynState[patterns->size()];
192  for ( unsigned int i = 0 ; i < patterns->size() ; ++i ) {
193  newcurrents[i] = 0;
194  currents[i] = 0;
195  }
196 
197  std::stringstream oss;
198  oss << "PatternStimulator:: Finished loading " << patterns->size() << " patterns";
199  auryn::logger->msg(oss.str(),NOTIFICATION);
200 }
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
NeuronGroup * dst
Definition: PatternStimulator.h:69
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
AurynFloat AurynState
Type for Auryn state variables (default single precision since it needs to be compatible with auryn_v...
Definition: auryn_definitions.h:160
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:

◆ propagate()

void PatternStimulator::propagate ( )

Implementation of necessary propagate() function.

76 {
77  if ( dst->evolve_locally() ) {
78 
79  char buffer[256];
80  std::string line;
81  while( !timeseriesfile.eof() && filetime < auryn::sys->get_clock() ) {
82  line.clear();
83  timeseriesfile.getline (buffer,255);
84  // TODO This buffer can quickly become too small of read lots of columns
85  // Instead this section should be re-written to directly read one token/column
86  // at a time in the loop below. Just making the buffer size large should be avoided
87  // not to risk buffer overflow or unecessarily large memory consumption on cluster
88  // machines with limited resources.
89  line = buffer;
90  if (line[0] == '#') continue;
91  std::stringstream iss (line);
92  double time;
93  iss >> time;
94  filetime = time/auryn_timestep;
95 
96  for ( unsigned int column = 0 ; column < patterns->size() ; ++column ) {
97  float cur;
98  iss >> cur ;
99  currents[column] = newcurrents[column];
100  newcurrents[column] = cur;
101  }
102  }
103 
104  AurynState * cur_iter = currents;
105  for ( std::vector<type_pattern>::const_iterator pattern = patterns->begin() ;
106  pattern != patterns->end() ; ++pattern ) {
107  for ( type_pattern::const_iterator piter = pattern->begin() ; piter != pattern->end() ; ++piter ) {
108  mem->data[piter->i] += *cur_iter * piter->gamma * scl * auryn_timestep;
109  }
110  ++cur_iter;
111  }
112  }
113 }
T * data
Pointer to the array housing the data.
Definition: AurynVector.h:154
NeuronGroup * dst
Definition: PatternStimulator.h:69
bool evolve_locally()
Returns true if the calling instance has units which are integrated on the current rank...
Definition: SpikingGroup.cpp:323
AurynFloat AurynState
Type for Auryn state variables (default single precision since it needs to be compatible with auryn_v...
Definition: auryn_definitions.h:160
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
AurynTime get_clock()
Gets the current clock value in AurynTime.
Definition: System.cpp:231
std::string string
Standard library string type which is imported into Auryn namespace.
Definition: auryn_definitions.h:156
Here is the call graph for this function:

◆ set_scale()

void PatternStimulator::set_scale ( AurynFloat  scale)
202  {
203  scl = scale;
204 }

Member Data Documentation

◆ dst

NeuronGroup* auryn::PatternStimulator::dst
protected

The target NeuronGroup


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