NEST main@caf0ae8
 
Loading...
Searching...
No Matches
stdp_facetshw_synapse_hom.h
Go to the documentation of this file.
1/*
2 * stdp_facetshw_synapse_hom.h
3 *
4 * This file is part of NEST.
5 *
6 * Copyright (C) 2004 The NEST Initiative
7 *
8 * NEST is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * NEST is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#ifndef STDP_SYNAPSE_FACETSHW_HOM_H
24#define STDP_SYNAPSE_FACETSHW_HOM_H
25
26// C++ includes:
27#include <cmath>
28
29// Includes from nestkernel:
31#include "connection.h"
32
33namespace nest
34{
35
36/* BeginUserDocs: synapse, chemical, functional, stdp
37
38Short description
39+++++++++++++++++
40
41Synapse type for spike-timing dependent plasticity using homogeneous parameters
42
43Description
44+++++++++++
45
46``stdp_facetshw_synapse`` is a connector to create synapses with spike-timing
47dependent plasticity (as defined in :footcite:p:`Morrison2008`).
48This connector is a modified version of ``stdp_synapse``.
49It includes constraints of the hardware developed in the FACETS (BrainScaleS)
50project :footcite:p:`Schemmel2006`, :footcite:p:`Pfeil2012`, as for example, 4-bit weight resolution, sequential updates
51of groups of synapses and reduced symmetric nearest-neighbor spike pairing scheme. For details see
52:footcite:p:`Pfeil2012`. The modified spike pairing scheme requires the calculation of ``tau_minus_`` within this
53synapse and not at the neuron site via ``Kplus_`` like in
54``stdp_synapse_hom``.
55
56.. warning::
57
58 This synaptic plasticity rule does not take
59 :ref:`precise spike timing <sim_precise_spike_times>` into
60 account. When calculating the weight update, the precise spike time part
61 of the timestamp is ignored.
62
63The synapse IDs are assigned to each synapse in an ascending order (0,1,2,
64...) according their first presynaptic activity and is used to group synapses
65that are updated at once. It is possible to avoid activity dependent synapse
66ID assignments by manually setting the no_synapses and the synapse_id(s)
67before running the simulation. The weights will be discretized after the
68first presynaptic activity at a synapse.
69
70Parameters
71++++++++++
72
73======================= =========== ===========================================
74**Common properties**
75-------------------------------------------------------------------------------
76 tau_plus ms Time constant of STDP window, causal branch
77 tau_minus_stdp ms Time constant of STDP window, anti-causal
78 branch
79 Wmax real Maximum allowed weight
80 no_synapses integer Total number of synapses
81 synapses_per_driver integer Number of synapses updated at once
82 driver_readout_time real Time for processing of one synapse row
83 (synapse line driver)
84 readout_cycle_duration real Duration between two subsequent
85 updates of same synapse (synapse line
86 driver)
87 lookuptable_0 list of Three look-up tables (LUT)
88 integers
89 lookuptable_1 list of
90 integers
91 lookuptable_2 list of
92 integers
93 configbit_0 list of Configuration bits for evaluation
94 integers function. For details see code in
95 function ``eval_function_`` and
96 :footcite:p:`Friedmann2013`
97 (configbit[0]=e_cc, :footcite:p:`Morrison2008` =e_ca,
98 :footcite:p:`Schemmel2006` =e_ac, :footcite:p:`Pfeil2012` =e_aa).
99 Depending on these two sets of
100 configuration bits weights are updated
101 according LUTs (out of three: (1,0),
102 (0,1), (1,1)). For (0,0) continue
103 without reset.
104 configbit_1 list of
105 integers
106 reset_pattern list of Configuration bits for reset behavior.
107 integers Two bits for each LUT (reset causal
108 and acausal). In hardware only (all
109 false; never reset) or (all true;
110 always reset) is allowed.
111======================= =========== ===========================================
112
113Common properties can only be set on the synapse model using
114:py:func:`.SetDefaults`.
115
116============ ======= =====================================================
117**Individual properties**
118---------------------------------------------------------------------------
119 a_causal real Causal and anti-causal spike pair accumulations
120 a_acausal real
121 a_thresh_th real Two thresholds used in evaluation function
122 No common property, because variation of analog
123 synapse circuitry can be applied here
124 a_thresh_tl real
125 synapse_id integer Synapse ID, used to assign synapses to groups (synapse
126 drivers)
127============ ======= =====================================================
128
129Transmits
130+++++++++
131
132SpikeEvent
133
134References
135++++++++++
136
137.. footbibliography::
138
139See also
140++++++++
141
142stdp_synapse, tsodyks_synapse, static_synapse
143
144Examples using this model
145+++++++++++++++++++++++++
146
147.. listexamples:: stdp_facetshw_synapse_hom
148
149EndUserDocs */
150
151// template class forward declaration required by common properties friend
152// definition
153
154void register_stdp_facetshw_synapse_hom( const std::string& name );
155
156template < typename targetidentifierT >
157class stdp_facetshw_synapse_hom;
158
163template < typename targetidentifierT >
165{
166 friend class stdp_facetshw_synapse_hom< targetidentifierT >;
167
168public:
174
178 void get_status( Dictionary& d ) const;
179
183 void set_status( const Dictionary& d, ConnectorModel& cm );
184
185 // overloaded for all supported event types
186 void
188 {
189 }
190
191private:
196
197
198 // data members common to all connections
199 double tau_plus_;
201 double Wmax_;
203
204 // STDP controller parameters
209 // TODO: TP: size in memory could be reduced
210 std::vector< long > lookuptable_0_;
211 std::vector< long > lookuptable_1_;
212 std::vector< long > lookuptable_2_;
213 std::vector< long > configbit_0_;
214 std::vector< long > configbit_1_;
215 std::vector< long > reset_pattern_;
216};
217
218
223template < typename targetidentifierT >
224class stdp_facetshw_synapse_hom : public Connection< targetidentifierT >
225{
226
227public:
230
234
240
247
248 // Explicitly declare all methods inherited from the dependent base
249 // ConnectionBase. This avoids explicit name prefixes in all places these
250 // functions are used. Since ConnectionBase depends on the template parameter,
251 // they are not automatically found in the base class.
256
260 void get_status( Dictionary& d ) const;
261
265 void set_status( const Dictionary& d, ConnectorModel& cm );
266
272
274 {
275 public:
276 // Ensure proper overriding of overloaded virtual functions.
277 // Return values from functions are ignored.
279 size_t
280 handles_test_event( SpikeEvent&, size_t ) override
281 {
282 return invalid_port;
283 }
284 };
285
286
287 /*
288 * This function calls check_connection on the sender and checks if the
289 * receiver accepts the event type and receptor type requested by the sender.
290 * Node::check_connection() will either confirm the receiver port by returning
291 * true or false if the connection should be ignored.
292 * We have to override the base class' implementation, since for STDP
293 * connections we have to call register_stdp_connection on the target neuron
294 * to inform the Archiver to collect spikes for this connection.
295 *
296 * \param s The source node
297 * \param r The target node
298 * \param receptor_type The ID of the requested receptor type
299 */
300 void
301 check_connection( Node& s, Node& t, size_t receptor_type, const CommonPropertiesType& )
302 {
303 ConnTestDummyNode dummy_target;
304
305 ConnectionBase::check_connection_( dummy_target, s, t, receptor_type );
306
308 }
309
310 void
311 set_weight( double w )
312 {
313 weight_ = w;
314 }
315
316private:
317 bool eval_function_( double a_causal,
318 double a_acausal,
319 double a_thresh_th,
320 double a_thresh_tl,
321 std::vector< long > configbit );
322
323 // transformation biological weight <-> discrete weight (represented in index
324 // of look-up table)
325 unsigned int weight_to_entry_( double weight, double weight_per_lut_entry );
326 double entry_to_weight_( unsigned int discrete_weight, double weight_per_lut_entry );
327
328 unsigned int lookup_( unsigned int discrete_weight_, std::vector< long > table );
329
330 // data members of each connection
331 double weight_;
332 double a_causal_;
336
340 unsigned int discrete_weight_; // TODO: TP: only needed in send, move to common
341 // properties or "static"?
343};
344
345template < typename targetidentifierT >
347
348template < typename targetidentifierT >
349inline bool
351 double a_acausal,
352 double a_thresh_th,
353 double a_thresh_tl,
354 std::vector< long > configbit )
355{
356 // compare charge on capacitors with thresholds and return evaluation bit
357 return ( a_thresh_tl + configbit[ 2 ] * a_causal + configbit[ 1 ] * a_acausal )
358 / ( 1 + configbit[ 2 ] + configbit[ 1 ] )
359 > ( a_thresh_th + configbit[ 0 ] * a_causal + configbit[ 3 ] * a_acausal )
360 / ( 1 + configbit[ 0 ] + configbit[ 3 ] );
361}
362
363template < typename targetidentifierT >
364inline unsigned int
365stdp_facetshw_synapse_hom< targetidentifierT >::weight_to_entry_( double weight, double weight_per_lut_entry )
366{
367 // returns the discrete weight in terms of the look-up table index
368 return round( weight / weight_per_lut_entry );
369}
370
371template < typename targetidentifierT >
372inline double
374 double weight_per_lut_entry )
375{
376 // returns the continuous weight
377 return discrete_weight * weight_per_lut_entry;
378}
379
380template < typename targetidentifierT >
381inline unsigned int
382stdp_facetshw_synapse_hom< targetidentifierT >::lookup_( unsigned int discrete_weight_, std::vector< long > table )
383{
384 // look-up in table
385 return table[ discrete_weight_ ];
386}
387
388
394template < typename targetidentifierT >
395inline bool
397 size_t t,
399{
400 // synapse STDP dynamics
401
402 double t_spike = e.get_stamp().get_ms();
403
404 // remove const-ness of common properties
405 // this is not a nice solution, but only a workaround
406 // anyway the current implementation will presumably
407 // generate wring results on distributed systems,
408 // because the number of synapses counted is only
409 // the number of synapses local to the current machine
412
413 // init the readout time
414 if ( not init_flag_ )
415 {
416 synapse_id_ = cp.no_synapses_;
417 ++cp_nonconst.no_synapses_;
418 cp_nonconst.calc_readout_cycle_duration_();
419 next_readout_time_ = int( synapse_id_ / cp_nonconst.synapses_per_driver_ ) * cp_nonconst.driver_readout_time_;
420 std::cout << "init synapse " << synapse_id_ << " - first readout time: " << next_readout_time_ << std::endl;
421 init_flag_ = true;
422 }
423
424 // STDP controller is processing this synapse (synapse driver)?
425 if ( t_spike > next_readout_time_ )
426 {
427 // transform weight to discrete representation
428 discrete_weight_ = weight_to_entry_( weight_, cp_nonconst.weight_per_lut_entry_ );
429
430 // obtain evaluation bits
431 bool eval_0 = eval_function_( a_causal_, a_acausal_, a_thresh_th_, a_thresh_tl_, cp.configbit_0_ );
432 bool eval_1 = eval_function_( a_causal_, a_acausal_, a_thresh_th_, a_thresh_tl_, cp.configbit_1_ );
433
434 // select LUT, update weight and reset capacitors
435 if ( eval_0 == true and eval_1 == false )
436 {
437 discrete_weight_ = lookup_( discrete_weight_, cp.lookuptable_0_ );
438 if ( cp.reset_pattern_[ 0 ] )
439 {
440 a_causal_ = 0;
441 }
442 if ( cp.reset_pattern_[ 1 ] )
443 {
444 a_acausal_ = 0;
445 }
446 }
447 else if ( eval_0 == false and eval_1 == true )
448 {
449 discrete_weight_ = lookup_( discrete_weight_, cp.lookuptable_1_ );
450 if ( cp.reset_pattern_[ 2 ] )
451 {
452 a_causal_ = 0;
453 }
454 if ( cp.reset_pattern_[ 3 ] )
455 {
456 a_acausal_ = 0;
457 }
458 }
459 else if ( eval_0 == true and eval_1 == true )
460 {
461 discrete_weight_ = lookup_( discrete_weight_, cp.lookuptable_2_ );
462 if ( cp.reset_pattern_[ 4 ] )
463 {
464 a_causal_ = 0;
465 }
466 if ( cp.reset_pattern_[ 5 ] )
467 {
468 a_acausal_ = 0;
469 }
470 }
471 // do nothing, if eval_0 == false and eval_1 == false
472
473 while ( t_spike > next_readout_time_ )
474 {
475 next_readout_time_ += cp_nonconst.readout_cycle_duration_;
476 }
477 // std::cout << "synapse " << synapse_id_ << " updated at " << t_spike << ",
478 // next readout time:
479 // " << next_readout_time_ << std::endl;
480
481 // back-transformation to continuous weight space
482 weight_ = entry_to_weight_( discrete_weight_, cp.weight_per_lut_entry_ );
483 }
484
485 // t_lastspike_ = 0 initially
486
487 double dendritic_delay = Time( Time::step( get_delay_steps() ) ).get_ms();
488
489 // get spike history in relevant range (t1, t2] from postsynaptic neuron
490 std::deque< histentry >::iterator start;
491 std::deque< histentry >::iterator finish;
492 get_target( t )->get_history( t_lastspike_ - dendritic_delay, t_spike - dendritic_delay, &start, &finish );
493
494 // facilitation due to the first postsynaptic spike since the last
495 // pre-synaptic spike
496 if ( start != finish )
497 {
498 double minus_dt_causal = t_lastspike_ - ( start->t_ + dendritic_delay );
499
500 // get_history() should make sure that
501 // start->t_ > t_lastspike_ - dendritic_delay, i.e. minus_dt < 0
502 assert( minus_dt_causal < -1.0 * kernel().connection_manager.get_stdp_eps() );
503
504 a_causal_ += std::exp( minus_dt_causal / cp.tau_plus_ );
505
506 // take only last postspike before current spike
507 double minus_dt_acausal;
508
509 --finish;
510 minus_dt_acausal = ( finish->t_ + dendritic_delay ) - t_spike;
511
512 a_acausal_ += std::exp( minus_dt_acausal / cp.tau_minus_ );
513 }
514
515 e.set_receiver( *get_target( t ) );
516 e.set_weight( weight_ );
517 e.set_delay_steps( get_delay_steps() );
518 e.set_rport( get_rport() );
519 e();
520
521 t_lastspike_ = t_spike;
522
523 return true;
524}
525} // of namespace nest
526
527#endif // of #ifndef STDP_SYNAPSE_FACETSHW_HOM_H
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
Class containing the common properties for all connections of a certain type.
Definition common_synapse_properties.h:50
Base class for dummy nodes used in connection testing.
Definition connection.h:67
Base class for representing connections.
Definition connection.h:110
void check_connection_(Node &dummy_target, Node &source, Node &target, const size_t receptor_type)
This function calls check_connection() on the sender to check if the receiver accepts the event type ...
Definition connection.h:319
long get_delay_steps() const
Return the delay of the connection in steps.
Definition connection.h:181
Node * get_target(const size_t tid) const
Definition connection.h:239
size_t get_rport() const
Definition connection.h:244
double get_delay() const
Return the delay of the connection in ms.
Definition connection.h:172
Definition connector_model.h:69
Encapsulate information sent between nodes.
Definition event.h:103
Base class for all NEST network objects.
Definition node.h:99
virtual void register_stdp_connection(double, double)
Register a STDP connection.
Definition node.cpp:211
Class containing the common properties for all synapses of type stdp_facetshw_synapse_hom.
Definition stdp_facetshw_synapse_hom.h:165
void calc_readout_cycle_duration_()
Calculate the readout cycle duration.
Definition stdp_facetshw_synapse_hom_impl.h:120
long no_synapses_
Definition stdp_facetshw_synapse_hom.h:205
std::vector< long > configbit_0_
Definition stdp_facetshw_synapse_hom.h:213
std::vector< long > lookuptable_1_
Definition stdp_facetshw_synapse_hom.h:211
std::vector< long > lookuptable_2_
Definition stdp_facetshw_synapse_hom.h:212
double driver_readout_time_
Definition stdp_facetshw_synapse_hom.h:207
double tau_plus_
Definition stdp_facetshw_synapse_hom.h:199
double Wmax_
Definition stdp_facetshw_synapse_hom.h:201
double weight_per_lut_entry_
Definition stdp_facetshw_synapse_hom.h:202
std::vector< long > lookuptable_0_
Definition stdp_facetshw_synapse_hom.h:210
std::vector< long > configbit_1_
Definition stdp_facetshw_synapse_hom.h:214
double readout_cycle_duration_
Definition stdp_facetshw_synapse_hom.h:208
void check_event(SpikeEvent &)
Definition stdp_facetshw_synapse_hom.h:187
STDPFACETSHWHomCommonProperties()
Default constructor.
Definition stdp_facetshw_synapse_hom_impl.h:40
double tau_minus_
Definition stdp_facetshw_synapse_hom.h:200
std::vector< long > reset_pattern_
Definition stdp_facetshw_synapse_hom.h:215
void get_status(Dictionary &d) const
Get all properties and put them into a dictionary.
Definition stdp_facetshw_synapse_hom_impl.h:127
void set_status(const Dictionary &d, ConnectorModel &cm)
Set properties from the values given in dictionary.
Definition stdp_facetshw_synapse_hom_impl.h:151
long synapses_per_driver_
Definition stdp_facetshw_synapse_hom.h:206
Event for spike information.
Definition event.h:418
Definition nest_time.h:135
double get_ms() const
Definition nest_time.h:490
Definition stdp_facetshw_synapse_hom.h:274
size_t handles_test_event(SpikeEvent &, size_t) override
Check if the node can handle a particular event and receptor type.
Definition stdp_facetshw_synapse_hom.h:280
Class representing an STDP connection with homogeneous parameters, i.e.
Definition stdp_facetshw_synapse_hom.h:225
bool send(Event &e, size_t t, const STDPFACETSHWHomCommonProperties< targetidentifierT > &)
Send an event to the receiver of this connection.
Definition stdp_facetshw_synapse_hom.h:396
double t_lastspike_
Definition stdp_facetshw_synapse_hom.h:342
stdp_facetshw_synapse_hom()
Default Constructor.
Definition stdp_facetshw_synapse_hom_impl.h:274
unsigned int lookup_(unsigned int discrete_weight_, std::vector< long > table)
Definition stdp_facetshw_synapse_hom.h:382
void set_weight(double w)
Definition stdp_facetshw_synapse_hom.h:311
unsigned int weight_to_entry_(double weight, double weight_per_lut_entry)
Definition stdp_facetshw_synapse_hom.h:365
STDPFACETSHWHomCommonProperties< targetidentifierT > CommonPropertiesType
Definition stdp_facetshw_synapse_hom.h:228
double entry_to_weight_(unsigned int discrete_weight, double weight_per_lut_entry)
Definition stdp_facetshw_synapse_hom.h:373
void check_connection(Node &s, Node &t, size_t receptor_type, const CommonPropertiesType &)
Definition stdp_facetshw_synapse_hom.h:301
void get_status(Dictionary &d) const
Get all properties of this connection and put them into a dictionary.
Definition stdp_facetshw_synapse_hom_impl.h:290
bool eval_function_(double a_causal, double a_acausal, double a_thresh_th, double a_thresh_tl, std::vector< long > configbit)
Definition stdp_facetshw_synapse_hom.h:350
double next_readout_time_
Definition stdp_facetshw_synapse_hom.h:339
double weight_
Definition stdp_facetshw_synapse_hom.h:331
double a_causal_
Definition stdp_facetshw_synapse_hom.h:332
double get_delay() const
Return the delay of the connection in ms.
Definition connection.h:172
void set_status(const Dictionary &d, ConnectorModel &cm)
Set properties of this connection from the values given in dictionary.
Definition stdp_facetshw_synapse_hom_impl.h:314
long synapse_id_
Definition stdp_facetshw_synapse_hom.h:338
Connection< targetidentifierT > ConnectionBase
Definition stdp_facetshw_synapse_hom.h:229
double a_thresh_tl_
Definition stdp_facetshw_synapse_hom.h:335
bool init_flag_
Definition stdp_facetshw_synapse_hom.h:337
stdp_facetshw_synapse_hom & operator=(const stdp_facetshw_synapse_hom &)=default
double a_acausal_
Definition stdp_facetshw_synapse_hom.h:333
unsigned int discrete_weight_
Definition stdp_facetshw_synapse_hom.h:340
static constexpr ConnectionModelProperties properties
Definition stdp_facetshw_synapse_hom.h:231
stdp_facetshw_synapse_hom(const stdp_facetshw_synapse_hom &)=default
Copy constructor from a property object.
double a_thresh_th_
Definition stdp_facetshw_synapse_hom.h:334
virtual size_t handles_test_event(SpikeEvent &, size_t receptor_type)
Check if the node can handle a particular event and receptor type.
Definition node.cpp:271
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
KernelManager & kernel()
Definition kernel_manager.h:311
void register_stdp_facetshw_synapse_hom(const std::string &name)
Definition stdp_facetshw_synapse_hom.cpp:33
ConnectionModelProperties
Definition connector_model.h:49
constexpr size_t invalid_port
Value for invalid connection port number.
Definition nest_types.h:141
Definition nest_time.h:246