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

Reads spikes from a ras file and emits them as SpikingGroup in a simulation. More...

#include <FileInputGroup.h>

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

Public Member Functions

 FileInputGroup (NeuronID n, string filename, bool loop=false, AurynFloat delay=0.0)
 Default constructor. More...
 
 FileInputGroup (NeuronID n)
 Constructor which does not load spikes. More...
 
virtual ~FileInputGroup ()
 
virtual void evolve ()
 Virtual pure evolve function which needs to be implemented by derived classes. More...
 
void set_loop_grid (AurynDouble grid_size)
 Aligned loop blocks to a temporal grid of this size. More...
 
void load_spikes (std::string filename)
 Load spikes from file. More...
 
void add_spike (double spiketime, NeuronID neuron_id=0)
 Adds a spike to the buffer manually and then temporally sorts the buffer. More...
 
void sort_spikes ()
 Sorts spikes by time. More...
 
- Public Member Functions inherited from auryn::SpikingGroup
void add_state_vector (std::string key, AurynStateVector *state_vector)
 Adds a state vector passed as an argument to the dictinary. More...
 
void remove_state_vector (std::string key)
 Removes a state vector passed as an argument to the dictinary. More...
 
AurynStateVectorfind_state_vector (std::string key)
 Returns existing state vector by name or NULL if it does not exist. More...
 
AurynStateVectorget_state_vector (std::string key)
 Creates a new or returns an existing state vector by name. More...
 
AurynStateVectorget_existing_state_vector (std::string key)
 Returns an existing state with the supplied name. More...
 
AurynStateVectorcreate_state_vector (std::string key)
 Creates a new state vector and throws an exception if a vector with the same name exists. More...
 
AurynStateget_state_variable (std::string key)
 Creates a new group-wide state variable or returns an existing group-wide variable by name then returns a pointer to it. More...
 
void randomize_state_vector_gauss (std::string state_vector_name, AurynState mean, AurynState sigma, int seed=12239)
 Randomizes the content of a state vector with Gaussian random numbers. Seeding is MPI save. More...
 
 SpikingGroup (NeuronID size, NodeDistributionMode mode=AUTO)
 Default constructor. More...
 
virtual ~SpikingGroup ()
 Default destructor. More...
 
virtual void evolve_traces ()
 Evolves traces. More...
 
void set_name (std::string s)
 Set connection name. More...
 
std::string get_name ()
 Retrieves the groups name. More...
 
std::string get_file_name ()
 Extracts the class name of the connection from the file name. More...
 
std::string get_log_name ()
 Returns a string which is the combination of file and connection name for logging. More...
 
void inc_num_spike_attributes (int x)
 Instructs SpikingGroup to increase the number of spike attributes by x. More...
 
int get_num_spike_attributes ()
 
void conditional_evolve ()
 Conditional evolve functino which is called by System. More...
 
unsigned int get_locked_rank ()
 Returns locked rank for SpikingGroups which are not distributed across all ranks. More...
 
unsigned int get_locked_range ()
 Returns locked range of ranks for SpikingGroups which are not distributed across all ranks. More...
 
SpikeContainerget_spikes ()
 Returns pointer to a spike container that contains spikes which arrive in this timestep from all neurons in this group. More...
 
SpikeContainerget_spikes_immediate ()
 Returns pointer to SpikeContainer of spikes generated during the last evolve() step. More...
 
AttributeContainerget_attributes ()
 Returns pointer to Attributecontainer for usage in propagating Connection objects. Same as get_spikes_immediate(), however might be overwritten to contain Spikes that have been delayed. More...
 
AttributeContainerget_attributes_immediate ()
 Returns pointer to Attributecontainer of spikes generated during the last evolve() step. More...
 
NeuronID get_size ()
 Returns the size of the group. More...
 
NeuronID get_pre_size ()
 Returns the size of the group. More...
 
NeuronID calculate_rank_size (int rank=-1)
 Determines rank size and stores it in local variable. More...
 
NeuronID get_rank_size ()
 Returns the size on this rank. More...
 
NeuronID get_post_size ()
 Returns the size on this rank. More...
 
void set_clock_ptr (AurynTime *clock)
 
bool evolve_locally ()
 Returns true if the calling instance has units which are integrated on the current rank. More...
 
NeuronID get_uid ()
 Get the unique ID of the class. More...
 
Traceget_pre_trace (AurynFloat x)
 Returns a pre trace with time constant x. More...
 
void add_pre_trace (Trace *tr)
 Adds trace to pretrace stack of a connection. More...
 
Traceget_post_trace (AurynFloat x)
 Returns a post trace with time constant x. More...
 
void add_post_trace (Trace *tr)
 Adds trace to posttrace stack of a connection. More...
 
void push_spike (NeuronID spike)
 Pushes a local NeuronID as spike into the axonal SpikeDelay buffer. More...
 
void push_attribute (AurynFloat attrib)
 Pushes a spike attribute into the axonal SpikeDelay buffer. More...
 
void clear_spikes ()
 Clears all spikes stored in the delays which is useful to reset a network during runtime. More...
 
Traceget_post_state_trace (std::string state_name="mem", AurynFloat tau=10e-3, AurynFloat b=0.0)
 Returns a post trace of a neuronal state variable e.g. the membrane potential with time constant tau. More...
 
Traceget_post_state_trace (AurynStateVector *state, AurynFloat tau=10e-3, AurynFloat b=0.0)
 Returns a post trace of a neuronal state variable specified by pointer. More...
 
void set_delay (int d)
 Sets axonal delay for this SpikingGroup. More...
 
virtual bool write_to_file (const char *filename)
 Writes current states of SpikingGroup to human-readible textfile if implemented in derived class. More...
 
virtual bool load_from_file (const char *filename)
 Reads current states of SpikingGroup to human-readible textfile if implemented in derived class. More...
 
NeuronID ranksize ()
 Returns size (num of neurons) on the current rank. More...
 
NeuronID global2rank (NeuronID i)
 Converts global NeuronID within the SpikingGroup to the local NeuronID on this rank. More...
 
NeuronID rank2global (NeuronID i)
 Converts local NeuronID from the local rank to a global NeuronID. More...
 
bool localrank (NeuronID i)
 Checks if the global NeuronID i is integrated on this MPI rank. More...
 
NeuronID get_vector_size ()
 Rank size but rounded up to multiples of 4 (or potentially some other and larger number in future versions) for SSE compatibility. More...
 

Public Attributes

bool playinloop
 Switch that activates the loop mode of FileInputGroup when set to true. More...
 
AurynTime time_delay
 Time delay after each replay of the input pattern in loop mode (default 0s) More...
 
- Public Attributes inherited from auryn::SpikingGroup
SpikeDelaydelay
 
bool active
 Toggles group active. More...
 
std::map< std::string, AurynStateVector * > state_vectors
 
std::map< std::string, AurynStatestate_variables
 

Additional Inherited Members

- Protected Member Functions inherited from auryn::SpikingGroup
virtual void load_input_line (NeuronID i, const char *buf)
 
virtual std::string get_output_line (NeuronID i)
 
virtual void virtual_serialize (boost::archive::binary_oarchive &ar, const unsigned int version)
 Implementatinon of serialize function for writing. More...
 
virtual void virtual_serialize (boost::archive::binary_iarchive &ar, const unsigned int version)
 Implementatinon of serialize function for reading. More...
 
void free ()
 Frees potentially allocated memory. More...
 
- Protected Attributes inherited from auryn::SpikingGroup
std::vector< Trace * > pretraces
 Pretraces. More...
 
std::vector< Trace * > posttraces
 Posttraces. More...
 
std::vector< Trace * > post_state_traces
 Post state traces. More...
 
std::vector< AurynFloatpost_state_traces_spike_biases
 
std::vector< AurynStateVector * > post_state_traces_states
 
std::string group_name
 Identifying name for object. More...
 
NeuronID size
 Stores the size of the group. More...
 
NeuronID rank_size
 Stores the size of the group on this rank. More...
 
SpikeContainerspikes
 SpikeContainers to store spikes produced during one step of evolve. More...
 
AttributeContainerattribs
 
- Static Protected Attributes inherited from auryn::SpikingGroup
static AurynTimeclock_ptr = NULL
 

Detailed Description

Reads spikes from a ras file and emits them as SpikingGroup in a simulation.

FileInputGroup first reads the entire ras file into memory and emits the spikes then during the simulation without file access. It supports looping over the input spikes by setting the loop argument with the constructor to true.

Constructor & Destructor Documentation

◆ FileInputGroup() [1/2]

FileInputGroup::FileInputGroup ( NeuronID  n,
std::string  filename,
bool  loop = false,
AurynFloat  delay = 0.0 
)

Default constructor.

49 : SpikingGroup( n , RANKLOCK )
50 {
51  init();
52  playinloop = loop;
55  time_offset = 0;
56  load_spikes(filename);
57 }
Locks to single rank (this is a special case of BLOCKLOCK.
Definition: SpikingGroup.h:54
SpikingGroup(NeuronID size, NodeDistributionMode mode=AUTO)
Default constructor.
Definition: SpikingGroup.cpp:38
int n
Definition: mkpat.py:5
AurynTime time_delay
Time delay after each replay of the input pattern in loop mode (default 0s)
Definition: FileInputGroup.h:73
double auryn_timestep
Simulation timestep in seconds.
Definition: auryn_definitions.cpp:31
void set_loop_grid(AurynDouble grid_size)
Aligned loop blocks to a temporal grid of this size.
Definition: FileInputGroup.cpp:149
bool playinloop
Switch that activates the loop mode of FileInputGroup when set to true.
Definition: FileInputGroup.h:70
SpikeDelay * delay
Definition: SpikingGroup.h:144
NeuronID AurynTime
Defines Auryns discrete time unit of the System clock. Change to AurynLong if 120h of simtime are not...
Definition: auryn_definitions.h:155
void load_spikes(std::string filename)
Load spikes from file.
Definition: FileInputGroup.cpp:65
Here is the call graph for this function:

◆ FileInputGroup() [2/2]

FileInputGroup::FileInputGroup ( NeuronID  n)

Constructor which does not load spikes.

Use this constructor if you want to init the group without a filename containing spikes. Spikes can be added after initialization by calling load_spikes(filename) or by adding spikes one by one using add_spike(spiketime, neuron_id).

39  : SpikingGroup(n, RANKLOCK )
40 {
41  playinloop = false;
42  time_delay = 0;
43  time_offset = 0;
44  init();
45 }
Locks to single rank (this is a special case of BLOCKLOCK.
Definition: SpikingGroup.h:54
SpikingGroup(NeuronID size, NodeDistributionMode mode=AUTO)
Default constructor.
Definition: SpikingGroup.cpp:38
int n
Definition: mkpat.py:5
AurynTime time_delay
Time delay after each replay of the input pattern in loop mode (default 0s)
Definition: FileInputGroup.h:73
bool playinloop
Switch that activates the loop mode of FileInputGroup when set to true.
Definition: FileInputGroup.h:70

◆ ~FileInputGroup()

FileInputGroup::~FileInputGroup ( )
virtual
60 {
61 }

Member Function Documentation

◆ add_spike()

void FileInputGroup::add_spike ( double  spiketime,
NeuronID  neuron_id = 0 
)

Adds a spike to the buffer manually and then temporally sorts the buffer.

Parameters
spiketimethe spike time
neuron_idthe neuron you want to spike with neuron_id < size of the group
159 {
160  SpikeEvent_type event;
161  event.time = spiketime/auryn_timestep;
162  event.neuronID = neuron_id;
163  input_spikes.push_back(event);
164  sort_spikes();
165 }
AurynTime time
Definition: auryn_definitions.h:196
void sort_spikes()
Sorts spikes by time.
Definition: FileInputGroup.cpp:103
double auryn_timestep
Simulation timestep in seconds.
Definition: auryn_definitions.cpp:31
Auryn spike event for binary monitors.
Definition: auryn_definitions.h:194
Here is the call graph for this function:

◆ evolve()

void FileInputGroup::evolve ( )
virtual

Virtual pure evolve function which needs to be implemented by derived classes.

The evolve function is called during simulations in every timestep by the System class. It updates the internal state of the spiking group and pushes spikes which are generated in this timestep to the axonal output delay (SpikeDelay).

Implements auryn::SpikingGroup.

124 {
125  if (active && input_spikes.size()) {
126  // when reset_time is reached reset the spike_iterator to The beginning and update time offset
127  if ( sys->get_clock() == reset_time ) {
128  spike_iter = input_spikes.begin();
129  time_offset = sys->get_clock();
130  // std::cout << "set to" << reset_time*auryn_timestep << " " << time_offset << std::endl;
131  }
132 
133  while ( spike_iter != input_spikes.end() && (*spike_iter).time <= get_offset_clock() ) {
134  spikes->push_back((*spike_iter).neuronID);
135  ++spike_iter;
136  // std::cout << "spike " << sys->get_time() << std::endl;
137  }
138 
139  // TODO Fix the bug which eats the first spike
140  if ( spike_iter==input_spikes.end() && reset_time < sys->get_clock() && playinloop ) { // at last spike on file set new reset time
141  // schedule reset for next grid point after delay
142  reset_time = get_next_grid_point(sys->get_clock());
143  // std::cout << "set rt" << reset_time << std::endl;
144  }
145  }
146 }
bool active
Toggles group active.
Definition: SpikingGroup.h:149
SpikeContainer * spikes
SpikeContainers to store spikes produced during one step of evolve.
Definition: SpikingGroup.h:123
System * sys
Global pointer to instance of System which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:37
bool playinloop
Switch that activates the loop mode of FileInputGroup when set to true.
Definition: FileInputGroup.h:70
AurynTime get_clock()
Gets the current clock value in AurynTime.
Definition: System.cpp:231
Here is the call graph for this function:

◆ load_spikes()

void FileInputGroup::load_spikes ( std::string  filename)

Load spikes from file.

66 {
67  std::ifstream spkfile;
68  input_spikes.clear();
69 
70  if ( evolve_locally() ) {
71  spkfile.open(filename.c_str(),std::ifstream::in);
72  if (!spkfile) {
73  std::cerr << "Can't open input file " << filename << std::endl;
74  std::exit(1);
75  }
76  }
77 
78  char buffer[255];
79  while ( spkfile.getline(buffer, 256) ) {
80  SpikeEvent_type event;
81  std::stringstream line ( buffer ) ;
82  double t_tmp;
83  line >> t_tmp;
84  event.time = t_tmp/auryn_timestep;
85  line >> event.neuronID;
86  if ( localrank(event.neuronID) ) {
87  input_spikes.push_back(event);
88  // std::cout << event.time << std::endl;
89  }
90  }
91  spkfile.close();
92 
93  sort_spikes();
94 
95  std::stringstream oss;
96  oss << get_log_name() << ":: Finished loading " << input_spikes.size()
97  << " spike events";
98  logger->info(oss.str());
99 
100  spike_iter = input_spikes.begin();
101 }
bool localrank(NeuronID i)
Checks if the global NeuronID i is integrated on this MPI rank.
Definition: SpikingGroup.cpp:531
void sort_spikes()
Sorts spikes by time.
Definition: FileInputGroup.cpp:103
NeuronID neuronID
Definition: auryn_definitions.h:197
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
void info(std::string text)
Definition: Logger.cpp:126
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: SpikingGroup.cpp:523
double auryn_timestep
Simulation timestep in seconds.
Definition: auryn_definitions.cpp:31
Auryn spike event for binary monitors.
Definition: auryn_definitions.h:194
Here is the call graph for this function:

◆ set_loop_grid()

void FileInputGroup::set_loop_grid ( AurynDouble  grid_size)

Aligned loop blocks to a temporal grid of this size.

The grid is applied after the delay. It's mostly there to facilitate the synchronization of certain events or readouts. If no grid is defined the last input spike time will define the end of the loop window (which often could be a fractional time).

150 {
151  playinloop = true;
152  if ( grid_size > 0.0 ) {
153  loop_grid_size = 1.0/auryn_timestep*grid_size;
154  if ( loop_grid_size == 0 ) loop_grid_size = 1;
155  }
156 }
double auryn_timestep
Simulation timestep in seconds.
Definition: auryn_definitions.cpp:31
bool playinloop
Switch that activates the loop mode of FileInputGroup when set to true.
Definition: FileInputGroup.h:70

◆ sort_spikes()

void FileInputGroup::sort_spikes ( )

Sorts spikes by time.

Spikes need to be sorted befure a run otherwise the behavior of this SpikingGroup is undefined

104 {
105  std::sort (input_spikes.begin(), input_spikes.end(), time_compare);
106 }
bool time_compare(SpikeEvent_type a, SpikeEvent_type b)
Definition: FileInputGroup.cpp:63
Here is the call graph for this function:

Member Data Documentation

◆ playinloop

bool auryn::FileInputGroup::playinloop

Switch that activates the loop mode of FileInputGroup when set to true.

◆ time_delay

AurynTime auryn::FileInputGroup::time_delay

Time delay after each replay of the input pattern in loop mode (default 0s)


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