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