23#ifndef EPROP_SYNAPSE_BSSHSLM_2020_H
24#define EPROP_SYNAPSE_BSSHSLM_2020_H
237template <
typename target
identifierT >
370template <
typename target
identifierT >
386template <
typename target
identifierT >
391 , t_spike_previous_( 0 )
392 , previous_was_flush_event_( false )
393 , t_previous_update_( 0 )
394 , t_next_update_( 0 )
395 , t_previous_trigger_spike_( 0 )
396 , tau_m_readout_( 10.0 )
397 , kappa_( std::exp( -
Time::get_resolution().get_ms() / tau_m_readout_ ) )
398 , is_recurrent_to_recurrent_conn_( false )
399 , optimizer_( nullptr )
403template <
typename target
identifierT >
410template <
typename target
identifierT >
413 , weight_( es.weight_ )
414 , gradient_( es.gradient_ )
415 , t_spike_previous_( 0 )
416 , previous_was_flush_event_( false )
417 , t_previous_update_( 0 )
418 , t_next_update_(
kernel().simulation_manager.get_eprop_update_interval().get_steps() )
419 , t_previous_trigger_spike_( 0 )
420 , tau_m_readout_( es.tau_m_readout_ )
421 , kappa_( std::exp( -
Time::get_resolution().get_ms() / tau_m_readout_ ) )
422 , is_recurrent_to_recurrent_conn_( es.is_recurrent_to_recurrent_conn_ )
423 , optimizer_( es.optimizer_ )
428template <
typename target
identifierT >
437 ConnectionBase::operator=( es );
454template <
typename target
identifierT >
457 , weight_( es.weight_ )
458 , gradient_( es.gradient_ )
459 , t_spike_previous_( 0 )
460 , previous_was_flush_event_( false )
461 , t_previous_update_( 0 )
462 , t_next_update_( es.t_next_update_ )
463 , t_previous_trigger_spike_( 0 )
464 , tau_m_readout_( es.tau_m_readout_ )
465 , kappa_( es.kappa_ )
466 , is_recurrent_to_recurrent_conn_( es.is_recurrent_to_recurrent_conn_ )
467 , optimizer_( es.optimizer_ )
469 es.optimizer_ =
nullptr;
473template <
typename target
identifierT >
482 ConnectionBase::operator=( es );
484 weight_ = es.weight_;
485 gradient_ = es.gradient_;
486 t_spike_previous_ = es.t_spike_previous_;
487 previous_was_flush_event_ = es.previous_was_flush_event_;
488 t_previous_update_ = es.t_previous_update_;
489 t_next_update_ = es.t_next_update_;
490 t_previous_trigger_spike_ = es.t_previous_trigger_spike_;
491 tau_m_readout_ = es.tau_m_readout_;
493 is_recurrent_to_recurrent_conn_ = es.is_recurrent_to_recurrent_conn_;
495 optimizer_ = es.optimizer_;
496 es.optimizer_ =
nullptr;
501template <
typename target
identifierT >
505 size_t receptor_type,
509 if ( get_delay_steps() != 1 )
511 throw IllegalConnection(
"eprop synapses currently require a delay of one simulation step" );
515 ConnectionBase::check_connection_( dummy_target, s, t, receptor_type );
523template <
typename target
identifierT >
531template <
typename target
identifierT >
537 Node* target = get_target( thread );
540 const long t_spike = e.get_stamp().get_steps();
541 const bool is_flush_event = e.is_flush_event();
543 if ( previous_was_flush_event_ )
545 if ( is_flush_event )
550 t_spike_previous_ = t_spike;
551 t_previous_trigger_spike_ = t_spike;
555 const long shift = target->get_shift();
557 const long interval_step = ( t_spike - shift ) % update_interval;
559 if ( target->is_eprop_recurrent_node() and interval_step == 0 )
564 if ( t_previous_trigger_spike_ == 0 )
566 t_previous_trigger_spike_ = t_spike;
569 if ( t_spike_previous_ > 0 )
571 const long presyn_isi =
572 std::min( t_spike, t_next_update_ + shift ) - std::min( t_spike_previous_, t_next_update_ + shift );
574 if ( presyn_isi > 0 )
576 presyn_isis_.push_back( presyn_isi );
580 if ( t_spike > t_next_update_ + shift )
582 const long idx_current_update = ( t_spike - shift ) / update_interval;
583 const long t_current_update = idx_current_update * update_interval;
585 target->write_update_to_history( t_previous_update_, t_current_update, is_flush_event, previous_was_flush_event_ );
587 if ( not presyn_isis_.empty() and t_spike_previous_ > 0 )
589 gradient_ += target->compute_gradient(
590 presyn_isis_, t_previous_update_, t_previous_trigger_spike_, kappa_, cp.
average_gradient_ );
593 if ( not is_flush_event )
595 weight_ = optimizer_->optimized_weight( *cp.
optimizer_cp_, idx_current_update, gradient_, weight_ );
599 t_previous_update_ = t_current_update;
600 t_next_update_ = t_current_update + update_interval;
602 t_previous_trigger_spike_ = t_spike;
606 if ( not is_flush_event and previous_was_flush_event_ )
608 const long idx_current_update = ( t_spike - shift ) / update_interval;
609 const long t_current_update = idx_current_update * update_interval;
611 target->write_update_to_history(
612 t_previous_update_, t_current_update, is_flush_event, previous_was_flush_event_ );
614 weight_ = optimizer_->optimized_weight( *cp.
optimizer_cp_, idx_current_update, gradient_, weight_ );
619 if ( not is_flush_event )
621 t_spike_previous_ = t_spike;
623 e.set_receiver( *target );
624 e.set_weight( weight_ );
625 e.set_delay_steps( get_delay_steps() );
626 e.set_rport( get_rport() );
630 previous_was_flush_event_ = is_flush_event;
635template <
typename target
identifierT >
639 ConnectionBase::get_status( d );
649 optimizer_->get_status( optimizer_dict );
654template <
typename target
identifierT >
658 ConnectionBase::set_status( d, cm );
670 if ( tau_m_readout_ <= 0 )
672 throw BadProperty(
"Membrane time constant of readout neuron tau_m_readout > 0 required." );
680 if ( weight_ < epcp.optimizer_cp_->get_Wmin() )
682 throw BadProperty(
"Minimal weight Wmin ≤ weight required." );
685 if ( weight_ > epcp.optimizer_cp_->get_Wmax() )
687 throw BadProperty(
"weight ≤ maximal weight Wmax required." );
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
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
Homogeneous connector, contains synapses of one particular type (syn_id_).
Definition connector_base.h:221
"Callback request event" for use in Device.
Definition event.h:521
Base class implementing common properties for e-prop synapses.
Definition eprop_synapse_bsshslm_2020.h:177
void get_status(Dictionary &d) const
Get parameter dictionary.
Definition eprop_synapse_bsshslm_2020.cpp:58
~EpropSynapseBSSHSLM2020CommonProperties()
Destructor.
Definition eprop_synapse_bsshslm_2020.cpp:52
WeightOptimizerCommonProperties * optimizer_cp_
Pointer to common properties object for weight optimizer.
Definition eprop_synapse_bsshslm_2020.h:205
EpropSynapseBSSHSLM2020CommonProperties & operator=(const EpropSynapseBSSHSLM2020CommonProperties &)=delete
Assignment operator.
EpropSynapseBSSHSLM2020CommonProperties()
Definition eprop_synapse_bsshslm_2020.cpp:37
void set_status(const Dictionary &d, ConnectorModel &cm)
Update values in parameter dictionary.
Definition eprop_synapse_bsshslm_2020.cpp:68
bool average_gradient_
If True, average the gradient over the learning window.
Definition eprop_synapse_bsshslm_2020.h:198
Encapsulate information sent between nodes.
Definition event.h:103
Definition connector_model.h:152
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 void register_eprop_connection()
Registers an eprop connection.
Definition node.cpp:217
virtual void initialize_update_history()
Initializes the update history.
Definition node.cpp:223
Time get_eprop_update_interval() const
Definition simulation_manager.h:343
Event for spike information.
Definition event.h:418
Definition nest_time.h:135
static Time get_resolution()
Definition nest_time.h:325
long get_steps() const
Definition nest_time.h:504
Base class implementing common properties of a weight optimizer model.
Definition weight_optimizer.h:154
virtual WeightOptimizer * get_optimizer() const =0
Get optimizer.
Base class implementing a weight optimizer model.
Definition weight_optimizer.h:238
Dummy node for testing the connection.
Definition eprop_synapse_bsshslm_2020.h:294
size_t handles_test_event(SpikeEvent &, size_t)
Check if the node can handle a particular event and receptor type.
Definition eprop_synapse_bsshslm_2020.h:299
size_t handles_test_event(DSSpikeEvent &, size_t)
Definition eprop_synapse_bsshslm_2020.h:305
Class implementing a synapse model for e-prop plasticity.
Definition eprop_synapse_bsshslm_2020.h:239
double weight_
Synaptic weight.
Definition eprop_synapse_bsshslm_2020.h:330
Connection< targetidentifierT > ConnectionBase
Type of the connection base.
Definition eprop_synapse_bsshslm_2020.h:246
void check_connection(Node &s, Node &t, size_t receptor_type, const CommonPropertiesType &cp)
Check if the target accepts the event and receptor type requested by the sender.
Definition eprop_synapse_bsshslm_2020.h:503
eprop_synapse_bsshslm_2020 & operator=(const eprop_synapse_bsshslm_2020 &)
Assignment operator.
Definition eprop_synapse_bsshslm_2020.h:430
long t_previous_update_
The time step when the previous e-prop update was.
Definition eprop_synapse_bsshslm_2020.h:342
WeightOptimizer * optimizer_
Optimizer.
Definition eprop_synapse_bsshslm_2020.h:367
static constexpr bool supports_flush_event
Whether this connection type supports flush events.
Definition eprop_synapse_bsshslm_2020.h:249
~eprop_synapse_bsshslm_2020()
Destructor.
Definition eprop_synapse_bsshslm_2020.h:404
void set_weight(const double w)
Set the synaptic weight to the provided value.
Definition eprop_synapse_bsshslm_2020.h:320
long t_next_update_
The time step when the next e-prop update will be.
Definition eprop_synapse_bsshslm_2020.h:345
double kappa_
Low-pass filter of the eligibility trace.
Definition eprop_synapse_bsshslm_2020.h:354
bool is_recurrent_to_recurrent_conn_
If this connection is between two recurrent neurons.
Definition eprop_synapse_bsshslm_2020.h:357
void delete_optimizer()
Delete optimizer.
Definition eprop_synapse_bsshslm_2020.h:525
long t_spike_previous_
The time step when the previous spike arrived.
Definition eprop_synapse_bsshslm_2020.h:336
void get_status(Dictionary &d) const
Get parameter dictionary.
Definition eprop_synapse_bsshslm_2020.h:637
static constexpr ConnectionModelProperties properties
Properties of the connection model.
Definition eprop_synapse_bsshslm_2020.h:256
EpropSynapseBSSHSLM2020CommonProperties CommonPropertiesType
Type of the common synapse properties.
Definition eprop_synapse_bsshslm_2020.h:243
bool send(Event &e, size_t thread, const EpropSynapseBSSHSLM2020CommonProperties &cp)
Send the spike event.
Definition eprop_synapse_bsshslm_2020.h:533
eprop_synapse_bsshslm_2020()
Default constructor.
Definition eprop_synapse_bsshslm_2020.h:387
double gradient_
Gradient used for the weight update.
Definition eprop_synapse_bsshslm_2020.h:333
std::vector< long > presyn_isis_
Vector of presynaptic inter-spike-intervals.
Definition eprop_synapse_bsshslm_2020.h:360
double tau_m_readout_
Time constant for low-pass filtering the eligibility trace.
Definition eprop_synapse_bsshslm_2020.h:351
bool previous_was_flush_event_
Previous event was a flush event.
Definition eprop_synapse_bsshslm_2020.h:339
void set_status(const Dictionary &d, ConnectorModel &cm)
Update values in parameter dictionary.
Definition eprop_synapse_bsshslm_2020.h:656
long t_previous_trigger_spike_
The time step when the spike arrived that triggered the previous e-prop update.
Definition eprop_synapse_bsshslm_2020.h:348
SimulationManager simulation_manager
Definition kernel_manager.h:237
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 optimizer("optimizer")
const std::string weight("weight")
const std::string tau_m_readout("tau_m_readout")
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
@ REQUIRES_EPROP_ARCHIVING
void register_eprop_synapse_bsshslm_2020(const std::string &name)
Register the eprop synapse model.
Definition eprop_synapse_bsshslm_2020.cpp:32
constexpr size_t invalid_port
Value for invalid connection port number.
Definition nest_types.h:141