NEST main@caf0ae8
 
Loading...
Searching...
No Matches
stdp_nn_pre_centered_synapse.h
Go to the documentation of this file.
1/*
2 * stdp_nn_pre_centered_synapse.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_NN_PRE_CENTERED_SYNAPSE_H
24#define STDP_NN_PRE_CENTERED_SYNAPSE_H
25
26// C++ includes:
27#include <cmath>
28
29// Includes from nestkernel:
31#include "connection.h"
32#include "connector_model.h"
33#include "event.h"
34
35
36namespace nest
37{
38
39/* BeginUserDocs: synapse, chemical, functional, stdp
40
41Short description
42+++++++++++++++++
43
44Synapse type for spike-timing dependent plasticity with
45presynaptic-centered nearest-neighbour spike pairing scheme
46
47Description
48+++++++++++
49
50``stdp_nn_pre_centered_synapse`` is a connector to create synapses with spike
51time dependent plasticity with the ``presynaptic``-centered nearest-neighbour
52spike pairing scheme, as described in :footcite:p:`Izhikevich2003b`.
53
54Each presynaptic spike is taken into account in the STDP weight change rule
55with the nearest preceding postsynaptic one and the nearest succeeding
56postsynaptic one (instead of pairing with all spikes, like in ``stdp_synapse``).
57So, when a presynaptic spike occurs, it is accounted in the depression rule
58with the nearest preceding postsynaptic one; and when a postsynaptic spike
59occurs, it is accounted in the facilitation rule with all preceding
60presynaptic spikes that were not earlier than the previous postsynaptic
61spike. For a clear illustration of this scheme see fig. 7B in :footcite:p:`Morrison2008`.
62
63The pairs exactly coinciding (so that ``presynaptic_spike == postsynaptic_spike
64+ dendritic_delay``), leading to zero ``delta_t``, are discarded. In this case the
65concerned pre/postsynaptic spike is paired with the second latest preceding
66post/presynaptic one (for example, ``pre=={10 ms; 20 ms}`` and ``post=={20 ms}`` will
67result in a potentiation pair 20-to-10).
68
69The implementation involves two additional variables - presynaptic and
70postsynaptic traces :footcite:p:`Morrison2008`. The presynaptic trace decays exponentially over
71time with the time constant ``tau_plus``, increases by 1 on a pre-spike
72occurrence, and is reset to 0 on a post-spike occurrence. The postsynaptic
73trace (implemented on the postsynaptic neuron side) decays with the time
74constant ``tau_minus`` and increases to 1 on a post-spike occurrence.
75
76.. warning::
77
78 This synaptic plasticity rule does not take
79 :ref:`precise spike timing <sim_precise_spike_times>` into
80 account. When calculating the weight update, the precise spike time part
81 of the timestamp is ignored.
82
83Parameters
84++++++++++
85
86========= ======= ======================================================
87 tau_plus ms Time constant of STDP window, potentiation
88 (tau_minus defined in postsynaptic neuron)
89 lambda real Step size
90 alpha real Asymmetry parameter (scales depressing increments as
91 alpha*lambda)
92 mu_plus real Weight dependence exponent, potentiation
93 mu_minus real Weight dependence exponent, depression
94 Wmax real Maximum allowed weight
95========= ======= ======================================================
96
97Transmits
98+++++++++
99
100SpikeEvent
101
102References
103++++++++++
104
105.. footbibliography::
106
107See also
108++++++++
109
110stdp_synapse, stdp_nn_symm_synapse
111
112Examples using this model
113+++++++++++++++++++++++++
114
115.. listexamples:: stdp_nn_pre_centered_synapse
116
117EndUserDocs */
118
119// connections are templates of target identifier type (used for pointer /
120// target index addressing) derived from generic connection template
121
122void register_stdp_nn_pre_centered_synapse( const std::string& name );
123
124template < typename targetidentifierT >
125class stdp_nn_pre_centered_synapse : public Connection< targetidentifierT >
126{
127
128public:
131
135
141
142
149
150 // Explicitly declare all methods inherited from the dependent base
151 // ConnectionBase. This avoids explicit name prefixes in all places these
152 // functions are used. Since ConnectionBase depends on the template parameter,
153 // they are not automatically found in the base class.
158
162 void get_status( Dictionary& d ) const;
163
167 void set_status( const Dictionary& d, ConnectorModel& cm );
168
174 bool send( Event& e, size_t t, const CommonSynapseProperties& cp );
175
177 {
178 public:
179 // Ensure proper overriding of overloaded virtual functions.
180 // Return values from functions are ignored.
182 size_t
183 handles_test_event( SpikeEvent&, size_t ) override
184 {
185 return invalid_port;
186 }
187 };
188
189 void
190 check_connection( Node& s, Node& t, size_t receptor_type, const CommonPropertiesType& )
191 {
192 ConnTestDummyNode dummy_target;
193
194 ConnectionBase::check_connection_( dummy_target, s, t, receptor_type );
195
197 }
198
199 void
200 set_weight( double w )
201 {
202 weight_ = w;
203 }
204
205private:
206 double
207 facilitate_( double w, double kplus )
208 {
209 double norm_w = ( w / Wmax_ ) + ( lambda_ * std::pow( 1.0 - ( w / Wmax_ ), mu_plus_ ) * kplus );
210 return norm_w < 1.0 ? norm_w * Wmax_ : Wmax_;
211 }
212
213 double
214 depress_( double w, double kminus )
215 {
216 double norm_w = ( w / Wmax_ ) - ( alpha_ * lambda_ * std::pow( w / Wmax_, mu_minus_ ) * kminus );
217 return norm_w > 0.0 ? norm_w * Wmax_ : 0.0;
218 }
219
220 // data members of each connection
221 double weight_;
222 double tau_plus_;
223 double lambda_;
224 double alpha_;
225 double mu_plus_;
226 double mu_minus_;
227 double Wmax_;
228 double Kplus_;
229
231};
232
233template < typename targetidentifierT >
235
242template < typename targetidentifierT >
243inline bool
245{
246 // synapse STDP depressing/facilitation dynamics
247 double t_spike = e.get_stamp().get_ms();
248
249 // use accessor functions (inherited from Connection< >) to obtain delay and
250 // target
251 Node* target = get_target( t );
252 double dendritic_delay = get_delay();
253
254 // get spike history in relevant range (t1, t2] from postsynaptic neuron
255 std::deque< histentry >::iterator start;
256 std::deque< histentry >::iterator finish;
257
258 // For a new synapse, t_lastspike_ contains the point in time of the last
259 // spike. So we initially read the
260 // history(t_last_spike - dendritic_delay, ..., T_spike-dendritic_delay]
261 // which increases the access counter for these entries.
262 // At registration, all entries' access counters of
263 // history[0, ..., t_last_spike - dendritic_delay] have been
264 // incremented by ArchivingNode::register_stdp_connection(). See bug #218 for
265 // details.
266 target->get_history( t_lastspike_ - dendritic_delay, t_spike - dendritic_delay, &start, &finish );
267 // If there were no postsynaptic spikes between the current pre-synaptic one
268 // t_spike and the previous pre-synaptic one t_lastspike_, there are no pairs
269 // to account.
270 if ( start != finish )
271 {
272 // facilitation due to the first postsynaptic spike start->t_
273 // since the previous pre-synaptic spike t_lastspike_
274
275 double minus_dt;
276 minus_dt = t_lastspike_ - ( start->t_ + dendritic_delay );
277
278 // get_history() should make sure that
279 // start->t_ > t_lastspike_ - dendritic_delay, i.e. minus_dt < 0
280 assert( minus_dt < -1.0 * kernel().connection_manager.get_stdp_eps() );
281
282 weight_ = facilitate_( weight_, Kplus_ * std::exp( minus_dt / tau_plus_ ) );
283
284 // According to the presynaptic-centered nearest-neighbour scheme,
285 // a postsynaptic spike
286 // (we now know there was at least one between t_lastspike_ and t_spike)
287 // erases the state of the synapse,
288 // and all the preceding presynaptic spikes are forgotten.
289 Kplus_ = 0;
290 }
291
292 // depression due to the latest postsynaptic spike finish->t_
293 // before the current pre-synaptic spike t_spike
294 double nearest_neighbor_Kminus;
295 double value_to_throw_away; // discard Kminus and Kminus_triplet here
296 target->get_K_values( t_spike - dendritic_delay, value_to_throw_away, nearest_neighbor_Kminus, value_to_throw_away );
297 weight_ = depress_( weight_, nearest_neighbor_Kminus );
298
299 Kplus_ = Kplus_ * std::exp( ( t_lastspike_ - t_spike ) / tau_plus_ ) + 1.0;
300
301 e.set_receiver( *target );
302 e.set_weight( weight_ );
303 // use accessor functions (inherited from Connection< >) to obtain delay in
304 // steps and rport
305 e.set_delay_steps( get_delay_steps() );
306 e.set_rport( get_rport() );
307 e();
308
309 t_lastspike_ = t_spike;
310
311 return true;
312}
313
314
315template < typename targetidentifierT >
318 , weight_( 1.0 )
319 , tau_plus_( 20.0 )
320 , lambda_( 0.01 )
321 , alpha_( 1.0 )
322 , mu_plus_( 1.0 )
323 , mu_minus_( 1.0 )
324 , Wmax_( 100.0 )
325 , Kplus_( 0.0 )
326 , t_lastspike_( 0.0 )
327{
328}
329
330template < typename targetidentifierT >
331void
333{
334 ConnectionBase::get_status( d );
335 d[ names::weight ] = weight_;
336 d[ names::tau_plus ] = tau_plus_;
337 d[ names::lambda ] = lambda_;
338 d[ names::alpha ] = alpha_;
339 d[ names::mu_plus ] = mu_plus_;
340 d[ names::mu_minus ] = mu_minus_;
341 d[ names::Wmax ] = Wmax_;
342 d[ names::Kplus ] = Kplus_;
343 d[ names::size_of ] = static_cast< long >( sizeof( *this ) );
344}
345
346template < typename targetidentifierT >
347void
349{
350 ConnectionBase::set_status( d, cm );
351 d.update_value( names::weight, weight_ );
352 d.update_value( names::tau_plus, tau_plus_ );
353 d.update_value( names::lambda, lambda_ );
354 d.update_value( names::alpha, alpha_ );
355 d.update_value( names::mu_plus, mu_plus_ );
356 d.update_value( names::mu_minus, mu_minus_ );
357 d.update_value( names::Wmax, Wmax_ );
358 d.update_value( names::Kplus, Kplus_ );
359
360 // check if weight_ and Wmax_ have the same sign
361 if ( not( ( ( weight_ >= 0 ) - ( weight_ < 0 ) ) == ( ( Wmax_ >= 0 ) - ( Wmax_ < 0 ) ) ) )
362 {
363 throw BadProperty( "Weight and Wmax must have same sign." );
364 }
365
366 if ( Kplus_ < 0 )
367 {
368 throw BadProperty( "Kplus must be non-negative." );
369 }
370}
371
372} // of namespace nest
373
374#endif // of #ifndef STDP_NN_PRE_CENTERED_SYNAPSE_H
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
Exception to be thrown if a status parameter is incomplete or inconsistent.
Definition exceptions.h:680
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
Event for spike information.
Definition event.h:418
Definition stdp_nn_pre_centered_synapse.h:177
size_t handles_test_event(SpikeEvent &, size_t) override
Check if the node can handle a particular event and receptor type.
Definition stdp_nn_pre_centered_synapse.h:183
Definition stdp_nn_pre_centered_synapse.h:126
stdp_nn_pre_centered_synapse & operator=(const stdp_nn_pre_centered_synapse &)=default
double alpha_
Definition stdp_nn_pre_centered_synapse.h:224
double Kplus_
Definition stdp_nn_pre_centered_synapse.h:228
double weight_
Definition stdp_nn_pre_centered_synapse.h:221
void get_status(Dictionary &d) const
Get all properties of this connection and put them into a dictionary.
Definition stdp_nn_pre_centered_synapse.h:332
double tau_plus_
Definition stdp_nn_pre_centered_synapse.h:222
double depress_(double w, double kminus)
Definition stdp_nn_pre_centered_synapse.h:214
stdp_nn_pre_centered_synapse(const stdp_nn_pre_centered_synapse &)=default
Copy constructor.
static constexpr ConnectionModelProperties properties
Definition stdp_nn_pre_centered_synapse.h:132
double mu_plus_
Definition stdp_nn_pre_centered_synapse.h:225
Connection< targetidentifierT > ConnectionBase
Definition stdp_nn_pre_centered_synapse.h:130
double mu_minus_
Definition stdp_nn_pre_centered_synapse.h:226
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_nn_pre_centered_synapse.h:348
stdp_nn_pre_centered_synapse()
Default Constructor.
Definition stdp_nn_pre_centered_synapse.h:316
double facilitate_(double w, double kplus)
Definition stdp_nn_pre_centered_synapse.h:207
bool send(Event &e, size_t t, const CommonSynapseProperties &cp)
Send an event to the receiver of this connection.
Definition stdp_nn_pre_centered_synapse.h:244
CommonSynapseProperties CommonPropertiesType
Definition stdp_nn_pre_centered_synapse.h:129
void set_weight(double w)
Definition stdp_nn_pre_centered_synapse.h:200
double Wmax_
Definition stdp_nn_pre_centered_synapse.h:227
double t_lastspike_
Definition stdp_nn_pre_centered_synapse.h:230
double lambda_
Definition stdp_nn_pre_centered_synapse.h:223
void check_connection(Node &s, Node &t, size_t receptor_type, const CommonPropertiesType &)
Definition stdp_nn_pre_centered_synapse.h:190
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
const std::string mu_plus("mu_plus")
const std::string mu_minus("mu_minus")
const std::string lambda("lambda")
const std::string alpha("alpha")
const std::string Kplus("Kplus")
const std::string tau_plus("tau_plus")
const std::string weight("weight")
const std::string size_of("sizeof")
const std::string Wmax("Wmax")
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
void register_stdp_nn_pre_centered_synapse(const std::string &name)
Definition stdp_nn_pre_centered_synapse.cpp:32
KernelManager & kernel()
Definition kernel_manager.h:311
ConnectionModelProperties
Definition connector_model.h:49
constexpr size_t invalid_port
Value for invalid connection port number.
Definition nest_types.h:141