NEST main@f146f75
Loading...
Searching...
No Matches
stdp_pl_synapse_hom_ax_delay.h
Go to the documentation of this file.
1/*
2 * stdp_pl_synapse_hom_ax_delay.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_PL_SYNAPSE_HOM_AX_DELAY_H
24#define STDP_PL_SYNAPSE_HOM_AX_DELAY_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, spike-timing-dependent plasticity
37
38Short description
39+++++++++++++++++
40
41Synapse type for spike-timing dependent plasticity with power law and both dendritic and axonal delays
42
43Description
44+++++++++++
45
46``stdp_pl_synapse_hom_ax_delay`` is a connector to create synapses with spike time
47dependent plasticity using homogeneous parameters (as defined in :footcite:p:`Morrison2007c`).
48In contrast to ``stdp_pl_synapse_hom``, no single ``delay`` is specified. Instead, the delay is split into a
49dendritic and an axonal contribution, and both have to be specified individually via ``dendritic_delay`` and
50``axonal_delay``.
51
52Parameters
53++++++++++
54
55========= ====== ====================================================
56 tau_plus ms Time constant of STDP window, potentiation
57 (tau_minus defined in postsynaptic neuron)
58 lambda real Learning rate
59 alpha real Asymmetry parameter (scales depressing increments as
60 alpha*lambda)
61 mu real Weight dependence exponent, potentiation
62========= ====== ====================================================
63
64The parameters can only be set by SetDefaults and apply to all synapses of
65the model.
66
67.. warning::
68
69 This synaptic plasticity rule does not take
70 :ref:`precise spike timing <sim_precise_spike_times>` into
71 account. When calculating the weight update, the precise spike time part
72 of the timestamp is ignored.
73
74References
75++++++++++
76
77.. footbibliography::
78
79Transmits
80+++++++++
81
82SpikeEvent
83
84See also
85++++++++
86
87stdp_synapse, tsodyks_synapse, static_synapse
88
89EndUserDocs */
90
96{
97
98public:
104
108 void get_status( Dictionary& d ) const;
109
113 void set_status( const Dictionary& d, ConnectorModel& cm );
114
115 // data members common to all connections
116 double tau_plus_;
118 double lambda_;
119 double alpha_;
120 double mu_;
121};
122
127void register_stdp_pl_synapse_hom_ax_delay( const std::string& name );
128
129template < typename targetidentifierT >
130class stdp_pl_synapse_hom_ax_delay : public Connection< targetidentifierT, AxonalDendriticDelay >
131{
132
133public:
136
140
146
153
154 // Explicitly declare all methods inherited from the dependent base
155 // ConnectionBase. This avoids explicit name prefixes in all places these
156 // functions are used. Since ConnectionBase depends on the template parameter,
157 // they are not automatically found in the base class.
165
169 void get_status( Dictionary& d ) const;
170
174 void set_status( const Dictionary& d, ConnectorModel& cm );
175
180 bool send( Event& e, size_t t, const STDPPLHomAxDelayCommonProperties& );
181
187 void correct_weight_stdp_ax_delay( const size_t tid,
189 const double t_spike_critical_interval_end,
190 const double t_post_spike,
192
194 {
195 public:
196 // Ensure proper overriding of overloaded virtual functions.
197 // Return values from functions are ignored.
199 size_t
200 handles_test_event( SpikeEvent&, size_t ) override
201 {
202 return invalid_port;
203 }
204 };
205
206 /*
207 * This function calls check_connection on the sender and checks if the
208 * receiver accepts the event type and receptor type requested by the sender.
209 * Node::check_connection() will either confirm the receiver port by returning
210 * true or false if the connection should be ignored.
211 * We have to override the base class' implementation, since for STDP
212 * connections we have to call register_stdp_pl_connection on the target
213 * neuron to inform the Archiver to collect spikes for this connection.
214 *
215 * \param s The source node
216 * \param r The target node
217 * \param receptor_type The ID of the requested receptor type
218 */
219 void
220 check_connection( Node& s, Node& t, const size_t receptor_type, const synindex syn_id, const CommonPropertiesType& )
221 {
222 if ( kernel().sp_manager.is_structural_plasticity_enabled() )
223 {
224 throw IllegalConnection( "Structural plasticity is not supported in combination with axonal delays." );
225 }
226
227 ConnTestDummyNode dummy_target;
228
229 ConnectionBase::check_connection_( dummy_target, s, t, syn_id, receptor_type );
230
231 if ( get_axonal_delay_ms() + get_dendritic_delay_ms() < kernel().connection_manager.get_stdp_eps() )
232 {
233 throw BadProperty( "Combination of axonal and dendritic delay has to be more than 0." );
234 }
235
237 {
238 // Reject targets which cannot drive the correction mechanism, instead of silently computing wrong
239 // weights for them.
241 {
242 throw IllegalConnection(
243 "Target model does not support synapses with predominantly axonal delay, i.e., with an axonal "
244 "delay of at least the dendritic delay." );
245 }
246
248 t.handles_test_event( e, receptor_type );
249 }
250
254
255 // The last spike reference value must resemble a spike that arrived at the synapse at t=0
257 }
258
259 void
260 set_weight( double w )
261 {
262 weight_ = w;
263 }
264
265private:
266 double
267 facilitate_( double w, double kplus, const STDPPLHomAxDelayCommonProperties& cp )
268 {
269 return w + ( cp.lambda_ * std::pow( w, cp.mu_ ) * kplus );
270 }
271
272 double
273 depress_( double w, double kminus, const STDPPLHomAxDelayCommonProperties& cp )
274 {
275 double new_w = w - ( cp.lambda_ * cp.alpha_ * w * kminus );
276 return new_w > 0.0 ? new_w : 0.0;
277 }
278
279 // data members of each connection
280 double weight_;
281 double Kplus_;
283};
284
285template < typename targetidentifierT >
287
289template < typename targetidentifierT >
290inline bool
292 size_t tid,
294{
295 // synapse STDP depressing/facilitation dynamics
296 const double axonal_delay_ms = get_axonal_delay_ms();
297 const double dendritic_delay_ms = get_dendritic_delay_ms();
298 const double t_spike = e.get_stamp().get_ms();
299
300 // t_lastspike_ = 0 initially
301 Node* target = get_target( tid );
302
303 // get spike history in relevant range (t1, t2] from postsynaptic neuron
304 std::deque< histentry >::iterator start;
305 std::deque< histentry >::iterator finish;
306 target->get_history( t_lastspike_ - dendritic_delay_ms + axonal_delay_ms,
307 t_spike - dendritic_delay_ms + axonal_delay_ms,
308 &start,
309 &finish );
310
311 // Framework for STDP with predominantly axonal delays:
312 // Store pre-synaptic trace for potential later correction
313 const double K_plus_revert = Kplus_;
314
315 // facilitation due to postsynaptic spikes since last pre-synaptic spike
316 double minus_dt = 0.;
317 while ( start != finish )
318 {
319 minus_dt = t_lastspike_ + axonal_delay_ms - ( start->t_ + dendritic_delay_ms );
320 // get_history() should make sure that
321 // start->t_ > t_lastspike - dendritic_delay, i.e. minus_dt < 0
322 assert( minus_dt < -1.0 * kernel().connection_manager.get_stdp_eps() );
323 weight_ = facilitate_( weight_, Kplus_ * std::exp( minus_dt * cp.tau_plus_inv_ ), cp );
324 ++start;
325 }
326
327 // Framework for STDP with predominantly axonal delays:
328 // Store weight before depression for potential later correction
329 const double weight_revert = weight_;
330
331 // depression due to new pre-synaptic spike
332 const double K_minus = target->get_K_value( t_spike + axonal_delay_ms - dendritic_delay_ms );
333 weight_ = depress_( weight_, K_minus, cp );
334
335 e.set_receiver( *target );
336 e.set_weight( weight_ );
337 e.set_delay_steps( get_delay_steps() );
338 e.set_rport( get_rport() );
339 e();
340
341 // A correction can only ever be needed if the spike reaches the synapse after a post-synaptic spike the synapse
342 // should have seen first, which requires the axonal delay to be at least the dendritic one. Testing that first --
343 // both values are already in hand -- keeps the arithmetic below off the hot path of every synapse that does not use
344 // predominantly axonal delays. That arithmetic is not free: get_rel_delivery_steps goes through Time::get_steps(),
345 // which costs two infinity tests and a pair of integer/double conversions, and it ran on every spike delivery even
346 // though its result cannot be positive unless the axonal delay reaches the dendritic one.
347 if ( axonal_delay_ms >= dendritic_delay_ms )
348 {
349 // axonal_delay-dendritic_delay = total_delay-2*dendritic_delay
350 const long time_while_critical =
351 e.get_rel_delivery_steps( kernel().simulation_manager.get_slice_origin() ) - 2 * get_dendritic_delay_steps() + 1;
352 // Only add correction entry if there could potentially be any post-synaptic spike that occurs before the
353 // pre-synaptic one arrives at the synapse.
354 if ( time_while_critical > 0 )
355 {
357 static_cast< SpikeEvent& >( e ), t_lastspike_, weight_revert, weight_, K_plus_revert, time_while_critical );
358 }
359 }
360
361 Kplus_ = Kplus_ * std::exp( ( t_lastspike_ - t_spike ) * cp.tau_plus_inv_ ) + 1.0;
362
363 t_lastspike_ = t_spike;
364
365 return true;
366}
367
368template < typename targetidentifierT >
376
377template < typename targetidentifierT >
378void
380{
381
382 // base class properties, different for individual synapse
384 d[ names::weight ] = weight_;
385
386 // own properties, different for individual synapse
387 d[ names::Kplus ] = Kplus_;
388 d[ names::size_of ] = static_cast< long >( sizeof( *this ) );
389}
390
391template < typename targetidentifierT >
392void
399
400template < typename targetidentifierT >
401void
404 const double t_spike_critical_interval_end,
405 const double t_post_spike,
407{
408 const double wrong_weight = weight_; // incorrectly transmitted weight
409 Node* target = get_target( tid );
410
411 // Read everything required from the entry up front, since updating the weights to revert to below also modifies
412 // this entry.
413 const size_t lcid = entry.get_lcid();
414 const double t_last_spike = entry.get_t_last_pre_spike();
415 const double weight_revert = entry.get_weight_revert();
416 const double K_plus_revert = entry.get_K_plus_revert();
417
418 const double axonal_delay_ms = get_axonal_delay_ms();
419 double dendritic_delay_ms = get_dendritic_delay_ms();
420
421 const double t_spike = t_spike_critical_interval_end + dendritic_delay_ms - axonal_delay_ms;
422
423 // facilitation due to new post-synaptic spike
424 const double minus_dt = t_last_spike + axonal_delay_ms - ( t_post_spike + dendritic_delay_ms );
425
426 // Only facilitate if not facilitated already (only if first correction for this post-spike)
427 if ( minus_dt < -1.0 * kernel().connection_manager.get_stdp_eps() )
428 {
429 weight_ = facilitate_( weight_revert, K_plus_revert * std::exp( minus_dt * cp.tau_plus_inv_ ), cp );
430
431 // Hand this in-progress weight to the connection's other entries now, instead of waiting for this
432 // entry to expire. The same post-synaptic spike can also correct a later spike of this connection,
433 // and that correction happens in this same scan -- long before the hand-off in
434 // clear_expired_correction_entries_stdp_ax_delay_(), which only runs once this entry leaves the buffer. The
435 // two are therefore not alternatives: dropping this call makes 10 of the 13 cases in
436 // test_axonal_delay_corrected_weights fail. Note that test_stdp_pl_synapse_hom still passes all 48 of
437 // its cases without it, because the weights it compares are the transmitted, pre-correction ones.
438 static_cast< AxonalDelayArchivingNode& >( *target ).update_weight_revert( lcid, weight_ );
439 }
440
441 // depression taking into account new post-synaptic spike
442 const double K_minus = target->get_K_value( t_spike + axonal_delay_ms - dendritic_delay_ms );
443 weight_ = depress_( weight_, K_minus, cp );
444
445 entry.set_new_weight( weight_ );
446
447 // send a correcting event to the target neuron
449 e.set_receiver( *target );
450 e.set_weight( wrong_weight );
451 e.set_new_weight( weight_ );
452 e.set_delay_steps( get_delay_steps() );
453 e.set_rport( get_rport() );
454 e.set_stamp( Time::ms_stamp( t_spike ) );
455 e();
456}
457
458} // of namespace nest
459
460#endif // of #ifndef STDP_PL_SYNAPSE_HOM_AX_DELAY_H
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
A node which buffers the information needed to retrospectively correct incoming STDP synapses with pr...
Definition axonal_delay_archiving_node.h:181
void update_weight_revert(const size_t lcid, const double weight_revert)
In case a correction is applied for a pre-synaptic spike, any other pre-synaptic spikes from the same...
Definition axonal_delay_archiving_node.cpp:150
void add_correction_entry_stdp_ax_delay(SpikeEvent &spike_event, const double t_last_pre_spike, const double weight_revert, const double new_weight, const double K_plus_revert, const double time_while_critical)
Buffer a correction entry for the critical time window.
Definition axonal_delay_archiving_node.cpp:67
Exception to be thrown if a status parameter is incomplete or inconsistent.
Definition exceptions.h:680
CommonSynapseProperties()
Standard constructor.
Definition common_synapse_properties.cpp:36
Base class for dummy nodes used in connection testing.
Definition connection.h:70
size_t get_rport() const
Definition connection.h:316
long get_delay_steps() const
Definition connection.h:271
double get_axonal_delay_ms() const
Definition connection.h:235
void set_status(const Dictionary &d, ConnectorModel &cm)
long get_dendritic_delay_steps() const
Definition connection.h:199
Node * get_target(const size_t tid) const
Definition connection.h:311
double get_axonal_delay_steps() const
Definition connection.h:253
double get_dendritic_delay_ms() const
Definition connection.h:190
void check_connection_(Node &dummy_target, Node &source, Node &target, const synindex syn_id, const size_t receptor_type)
Definition connector_model.h:69
Information on a received pre-synaptic spike which is buffered by an AxonalDelayArchivingNode,...
Definition axonal_delay_archiving_node.h:46
double get_K_plus_revert() const
Pre-synaptic trace before the possibly incorrect facilitation.
Definition axonal_delay_archiving_node.h:114
size_t get_lcid() const
Local connection index of the synapse which transmitted the spike.
Definition axonal_delay_archiving_node.h:67
void set_new_weight(const double new_weight)
Definition axonal_delay_archiving_node.h:107
double get_weight_revert() const
Synaptic weight to revert to (STDP depression needs to be undone) before a correction.
Definition axonal_delay_archiving_node.h:88
double get_t_last_pre_spike() const
Time of the last pre-synaptic spike before this spike.
Definition axonal_delay_archiving_node.h:81
Encapsulate information sent between nodes.
Definition event.h:103
To be thrown if a connection is not possible.
Definition exceptions.h:490
Base class for all NEST network objects.
Definition node.h:99
virtual bool supports_axonal_delay_corrections() const
Whether this model can be the target of a synapse with predominantly axonal delay.
Definition node.cpp:217
virtual void register_stdp_connection(double, double, double)
Register a STDP connection.
Definition node.cpp:211
Class containing the common properties for all synapses of type stdp_pl_synapse_hom_ax_delay.
Definition stdp_pl_synapse_hom_ax_delay.h:96
double tau_plus_
Definition stdp_pl_synapse_hom_ax_delay.h:116
STDPPLHomAxDelayCommonProperties()
Default constructor.
Definition stdp_pl_synapse_hom_ax_delay.cpp:44
double lambda_
Definition stdp_pl_synapse_hom_ax_delay.h:118
double mu_
Definition stdp_pl_synapse_hom_ax_delay.h:120
double alpha_
Definition stdp_pl_synapse_hom_ax_delay.h:119
void get_status(Dictionary &d) const
Get all properties and put them into a dictionary.
Definition stdp_pl_synapse_hom_ax_delay.cpp:55
double tau_plus_inv_
1 / tau_plus for efficiency
Definition stdp_pl_synapse_hom_ax_delay.h:117
void set_status(const Dictionary &d, ConnectorModel &cm)
Set properties from the values given in dictionary.
Definition stdp_pl_synapse_hom_ax_delay.cpp:66
Event for spike information.
Definition event.h:420
Definition event.h:457
Definition stdp_pl_synapse_hom_ax_delay.h:194
size_t handles_test_event(SpikeEvent &, size_t) override
Check if the node can handle a particular event and receptor type.
Definition stdp_pl_synapse_hom_ax_delay.h:200
void check_connection(Node &s, Node &t, const size_t receptor_type, const synindex syn_id, const CommonPropertiesType &)
Definition stdp_pl_synapse_hom_ax_delay.h:220
double get_dendritic_delay_ms() const
Return the proportion of the transmission delay attributed to the dendrite.
Definition connection.h:190
size_t get_rport() const
Definition connection.h:316
long get_delay_steps() const
Return the delay of the connection in steps.
Definition connection.h:271
stdp_pl_synapse_hom_ax_delay & operator=(const stdp_pl_synapse_hom_ax_delay &)=default
double facilitate_(double w, double kplus, const STDPPLHomAxDelayCommonProperties &cp)
Definition stdp_pl_synapse_hom_ax_delay.h:267
Connection< targetidentifierT, AxonalDendriticDelay > ConnectionBase
Definition stdp_pl_synapse_hom_ax_delay.h:135
void set_status(const Dictionary &d, ConnectorModel &cm)
Set properties of this connection from the values given in dictionary.
Definition stdp_pl_synapse_hom_ax_delay.h:393
bool send(Event &e, size_t t, const STDPPLHomAxDelayCommonProperties &)
Send an event to the receiver of this connection.
Definition stdp_pl_synapse_hom_ax_delay.h:291
long get_dendritic_delay_steps() const
Return the proportion of the transmission delay attributed to the dendrite.
Definition connection.h:199
void set_weight(double w)
Definition stdp_pl_synapse_hom_ax_delay.h:260
double get_axonal_delay_ms() const
Get the proportion of the transmission delay attributed to the axon.
Definition connection.h:235
void get_status(Dictionary &d) const
Get all properties of this connection and put them into a dictionary.
Definition stdp_pl_synapse_hom_ax_delay.h:379
double Kplus_
Definition stdp_pl_synapse_hom_ax_delay.h:281
static constexpr ConnectionModelProperties properties
Definition stdp_pl_synapse_hom_ax_delay.h:137
STDPPLHomAxDelayCommonProperties CommonPropertiesType
Definition stdp_pl_synapse_hom_ax_delay.h:134
stdp_pl_synapse_hom_ax_delay(const stdp_pl_synapse_hom_ax_delay &)=default
Copy constructor from a property object.
void correct_weight_stdp_ax_delay(const size_t tid, CorrectionEntrySTDPAxDelay &entry, const double t_spike_critical_interval_end, const double t_post_spike, const STDPPLHomAxDelayCommonProperties &cp)
Framework for STDP with predominantly axonal delays: Correct this synapse and the corresponding previ...
Definition stdp_pl_synapse_hom_ax_delay.h:402
Node * get_target(const size_t tid) const
Definition connection.h:311
stdp_pl_synapse_hom_ax_delay()
Default Constructor.
Definition stdp_pl_synapse_hom_ax_delay.h:369
double t_lastspike_
Definition stdp_pl_synapse_hom_ax_delay.h:282
double weight_
Definition stdp_pl_synapse_hom_ax_delay.h:280
double depress_(double w, double kminus, const STDPPLHomAxDelayCommonProperties &cp)
Definition stdp_pl_synapse_hom_ax_delay.h:273
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:282
const std::string Kplus("Kplus")
const std::string weight("weight")
const std::string size_of("sizeof")
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
KernelManager & kernel()
Definition kernel_manager.h:311
ConnectionModelProperties
Definition connector_model.h:49
@ HAS_DELAY
Definition connector_model.h:54
@ SUPPORTS_LBL
Definition connector_model.h:52
@ SUPPORTS_HPC
Definition connector_model.h:51
@ IS_PRIMARY
Definition connector_model.h:53
void register_stdp_pl_synapse_hom_ax_delay(const std::string &name)
Class representing an STDP connection with homogeneous parameters, i.e.
Definition stdp_pl_synapse_hom_ax_delay.cpp:32
constexpr size_t invalid_port
Value for invalid connection port number.
Definition nest_types.h:147
size_t synindex
For enumerations of synapse types.
Definition nest_types.h:121
Definition nest_time.h:264