Auryn simulator  v0.8.1-206-gb56e451
Plastic Spiking Neural Network Simulator
Connection.h
Go to the documentation of this file.
1 /*
2 * Copyright 2014-2018 Friedemann Zenke
3 *
4 * This file is part of Auryn, a simulation package for plastic
5 * spiking neural networks.
6 *
7 * Auryn is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * Auryn is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Auryn. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * If you are using Auryn or parts of it for your work please cite:
21 * Zenke, F. and Gerstner, W., 2014. Limits to high-speed simulations
22 * of spiking neural networks using general-purpose computers.
23 * Front Neuroinform 8, 76. doi: 10.3389/fninf.2014.00076
24 */
25 
26 #ifndef CONNECTION_H_
27 #define CONNECTION_H_
28 
29 
30 #include <string>
31 
32 #include "auryn_definitions.h"
33 #include "AurynVector.h"
34 #include "SpikingGroup.h"
35 #include "NeuronGroup.h"
36 #include "Trace.h"
37 
38 namespace auryn {
39 
40 class System;
41 
53 class Connection
54 {
55 private:
57  template<class Archive>
58  void serialize(Archive & ar, const unsigned int version)
59  {
60  virtual_serialize(ar, version);
61  }
62 
63 
64  NeuronID m_rows,n_cols;
65  std::string connection_name;
66 
67 protected:
71  virtual void virtual_serialize(boost::archive::binary_oarchive & ar, const unsigned int version )
72  {
73  ar & m_rows & n_cols & connection_name;
74  }
75 
79  virtual void virtual_serialize(boost::archive::binary_iarchive & ar, const unsigned int version )
80  {
81  ar & m_rows & n_cols & connection_name;
82  }
83 
85 
87 
94 
100 
103 
104  void init(TransmitterType transmitter=GLUT);
105 
106 public:
109 
112 
113  Connection();
114  Connection(NeuronID rows, NeuronID cols);
115  Connection(SpikingGroup * source, NeuronGroup * destination, TransmitterType transmitter=GLUT, std::string name="Connection");
116  virtual ~Connection();
117 
118  void set_size(NeuronID i, NeuronID j);
119 
123  void set_name(std::string name);
124 
127 
130 
133 
136 
142 
148 
154 
156  void set_target(AurynWeight * ptr);
157 
159  void set_target(AurynStateVector * ptr);
160 
162  void set_receptor(AurynStateVector * ptr);
163 
165  void set_transmitter(AurynStateVector * ptr);
166 
171  void set_transmitter(TransmitterType transmitter);
172 
174  void set_receptor(string state_name);
175 
177  void set_target(string state_name);
178 
180  void set_transmitter(string state_name);
181 
183  void set_source(SpikingGroup * source);
184 
187 
189  void set_destination(NeuronGroup * source);
190 
193 
194  /* Purely virtual functions */
196  virtual AurynWeight get(NeuronID i, NeuronID j) = 0;
197 
199  virtual AurynWeight * get_ptr(NeuronID i, NeuronID j) = 0;
200 
202  virtual AurynWeight get_data(NeuronID i) = 0;
203 
205  virtual void set(NeuronID i, NeuronID j, AurynWeight value) = 0;
206 
208  virtual AurynLong get_nonzero() = 0;
209 
211  virtual void finalize() = 0;
212 
214  virtual void propagate() = 0;
215 
217  virtual void evolve();
218 
221  void conditional_propagate();
222 
223 
225  Trace * get_pre_trace(const AurynDouble tau);
226 
228  Trace * get_post_trace(const AurynDouble tau);
229 
231  Trace * get_post_state_trace(const string state_name, const AurynDouble tau, const AurynDouble jump_size=0.0);
232 
234  virtual void stats(AurynDouble &mean, AurynDouble &std, StateID zid = 0) = 0;
235 
237  virtual bool write_to_file(std::string filename) = 0;
238 
240  virtual bool load_from_file(std::string filename) = 0;
241 
249  void transmit(const NeuronID id, const AurynWeight amount);
250 
254  void targeted_transmit(SpikingGroup * target_group, AurynStateVector * target_state, const NeuronID id, const AurynWeight amount);
255 
257  void safe_transmit(NeuronID id, AurynWeight amount);
258 
265 
273 
279  void add_number_of_spike_attributes(int x);
280 
282  AurynFloat get_spike_attribute(const NeuronID i, const int attribute_id=0);
283 };
284 
285 BOOST_SERIALIZATION_ASSUME_ABSTRACT(Connection)
286 
287 
288 inline void Connection::targeted_transmit(SpikingGroup * target_group, AurynStateVector * target_state, const NeuronID id, const AurynWeight amount)
289 {
290  const NeuronID localid = target_group->global2rank(id);
291  target_state->data[localid]+=amount;
292 }
293 
294 inline void Connection::transmit(const NeuronID id, const AurynWeight amount)
295 {
297 }
298 
299 }
300 
301 #endif /*CONNECTION_H_*/
virtual void propagate()=0
Propagate method to propagate spikes. Called by System run method.
void set_receptor(AurynStateVector *ptr)
Same as set_target.
Definition: Connection.cpp:152
TransmitterType get_transmitter()
Returns transmitter type.
Definition: Connection.cpp:106
Standard Glutamatergic (excitatory) transmission.
Definition: auryn_definitions.h:139
NeuronID number_of_spike_attributes
Number of spike attributes to expect with each spike transmitted through this connection.
Definition: Connection.h:99
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: Connection.cpp:98
Connection()
Definition: Connection.cpp:30
Trace * get_post_trace(const AurynDouble tau)
Returns a pointer to a postsynaptic trace object.
Definition: Connection.cpp:265
The abstract base class for all Connection objects in Auryn.
Definition: Connection.h:53
void transmit(const NeuronID id, const AurynWeight amount)
Default way to transmit a spike to a postsynaptic partner.
Definition: Connection.h:294
TransmitterType trans
Definition: Connection.h:84
std::vector< NeuronID > SpikeContainer
Spike container type. Used for storing spikes.
Definition: auryn_definitions.h:161
NeuronGroup * get_destination()
Returns pointer to the postsynaptic group.
Definition: Connection.cpp:203
virtual void evolve()
Evolve method to update internal connection state. Called by System run method.
Definition: Connection.cpp:276
void targeted_transmit(SpikingGroup *target_group, AurynStateVector *target_state, const NeuronID id, const AurynWeight amount)
Transmits a spike to a given target group and state.
Definition: Connection.h:288
virtual bool write_to_file(std::string filename)=0
Implements save to file functionality. Also called in save_network_state from System class...
STL namespace.
Abstract base class of all objects producing spikes.
Definition: SpikingGroup.h:67
SpikingGroup * get_source()
Returns pointer to the presynaptic group.
Definition: Connection.cpp:193
void add_number_of_spike_attributes(int x)
Set up spike delay to accomodate x additional spike attributes.
Definition: Connection.cpp:221
double AurynDouble
Higher precision floating point datatype.
Definition: auryn_definitions.h:158
AurynFloat AurynWeight
Unit of synaptic weights.
Definition: auryn_definitions.h:159
SpikingGroup * src
Pointer to the source group of this connection.
Definition: Connection.h:108
Abstract base class of synaptic traces.
Definition: Trace.h:36
virtual bool load_from_file(std::string filename)=0
Implements load from file functionality. Also called in save_network_state from System class...
void set_destination(NeuronGroup *source)
Sets destination SpikingGroup of this connection.
Definition: Connection.cpp:198
NeuronGroup * dst
Pointer to the destination group of this connection.
Definition: Connection.h:111
virtual void stats(AurynDouble &mean, AurynDouble &std, StateID zid=0)=0
Computes mean synaptic weight and std dev of all weights in this connection.
Trace * get_post_state_trace(const string state_name, const AurynDouble tau, const AurynDouble jump_size=0.0)
Returns a pointer to a postsynaptic state trace object.
Definition: Connection.cpp:270
virtual AurynWeight * get_ptr(NeuronID i, NeuronID j)=0
Return pointer to weight element i,j if it exists, otherwise return NULL.
NeuronID get_n_cols()
Get number of columns (postsynaptic) in connection.
Definition: Connection.cpp:183
Definition: ABSConnection.h:38
friend class boost::serialization::access
Definition: Connection.h:56
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
virtual void virtual_serialize(boost::archive::binary_oarchive &ar, const unsigned int version)
Definition: Connection.h:71
virtual AurynWeight get_data(NeuronID i)=0
Return weight element as index in data array.
void safe_transmit(NeuronID id, AurynWeight amount)
Same as transmit but first checks if the target neuron exists and avoids segfaults that way (but it&#39;s...
Definition: Connection.cpp:215
std::string get_file_name()
Extracts the class name of the connection from the file name.
Definition: Connection.cpp:92
void conditional_propagate()
DEPRECATED. (Such connections should not be registered in the first place) Calls propagate only if th...
Definition: Connection.cpp:208
TransmitterType
Specifies the different transmitter types that Auryn knows.
Definition: auryn_definitions.h:138
float AurynFloat
Low precision floating point datatype.
Definition: auryn_definitions.h:157
void init(TransmitterType transmitter=GLUT)
Definition: Connection.cpp:51
virtual void virtual_serialize(boost::archive::binary_iarchive &ar, const unsigned int version)
Definition: Connection.h:79
SpikeContainer * get_post_spikes()
Returns pointer to SpikeContainer for postsynaptic spikes on this node.
Definition: Connection.cpp:236
SpikeContainer * get_pre_spikes()
Supplies pointer to SpikeContainer of all presynaptic spikes.
Definition: Connection.cpp:231
Trace * get_pre_trace(const AurynDouble tau)
Returns a pointer to a presynaptic trace object.
Definition: Connection.cpp:260
virtual void finalize()=0
Finalize Connection after initialization to prepare for use in simulation.
AurynStateVector * target_state_vector
Definition: Connection.h:86
Abstract base class for all neuron groups.
Definition: NeuronGroup.h:45
AurynFloat get_spike_attribute(const NeuronID i, const int attribute_id=0)
Returns spike attribute belonging to the spike at position i in the get_spikes() SpikeContainer.
Definition: Connection.cpp:242
AurynStateVector * get_target_vector()
Returns target state vector if one is defined.
Definition: Connection.cpp:173
NeuronID get_m_rows()
Get number of rows (presynaptic) in connection.
Definition: Connection.cpp:178
Default AurynVectorFloat class for performance computation.
Definition: AurynVector.h:796
NeuronID spike_attribute_offset
Stores spike attribute offset in attribute array.
Definition: Connection.h:102
AurynFloat * target
A more direct reference on the first element of the target_state_vector.
Definition: Connection.h:93
virtual AurynLong get_nonzero()=0
Return number of nonzero elements in this Connection.
void set_transmitter(AurynStateVector *ptr)
Same as set_target.
unsigned int StateID
StateID is an unsigned integeger type used to index synaptic states in Auryn.
Definition: auryn_definitions.h:153
virtual ~Connection()
Definition: Connection.cpp:78
std::string get_name()
Returns name of connection.
Definition: Connection.cpp:87
void set_target(AurynWeight *ptr)
Sets target state of this connection directly via a pointer.
Definition: Connection.cpp:137
void set_size(NeuronID i, NeuronID j)
Definition: Connection.cpp:71
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
void set_source(SpikingGroup *source)
Sets source SpikingGroup of this connection.
Definition: Connection.cpp:188
void set_name(std::string name)
Set name of connection.
Definition: Connection.cpp:82