/* * stdp_izh_connection.h * * This file is part of NEST. * * Copyright (C) 2004 The NEST Initiative * * NEST is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * NEST is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with NEST. If not, see . * */ #ifndef STDP_IZH_CONNECTION_H #define STDP_IZH_CONNECTION_H /* BeginDocumentation Name: stdp_izh_synapse - Synapse type for spike-timing dependent plasticity. Description: stdp_izh_synapse is a connector to create synapses with spike time dependent plasticity (as defined in [1]). Parameters: tau_LTP double - Time constant of STDP window, potentiation in ms tau_LTD double - Time constant of STDP window, depression in ms lambda double - Step size alpha double - Asymmetry parameter (scales depressing increments as alpha*lambda) Wmax double - Maximum allowed weight Transmits: SpikeEvent References: [1] Izhikevich EM (2006) Polychronization: computation with spikes. Neural Comput. 18(2):245-82. Author: Abigail Morrison Adapted by: Philipp Weidel, Susanne Kunkel SeeAlso: synapsedict, stdp_synapse */ // Includes from nestkernel: #include "common_synapse_properties.h" #include "connection.h" #include "connector_model.h" #include "event.h" #include "target_identifier.h" // Includes from sli: #include "dictdatum.h" #include "dictutils.h" namespace nest { class STDPIzhCommonProperties : public CommonSynapseProperties { public: /** * Default constructor. * Sets all property values to defaults. */ STDPIzhCommonProperties(); /** * Get all properties and put them into a dictionary. */ void get_status( DictionaryDatum& d ) const; /** * Set properties from the values given in dictionary. */ void set_status( const DictionaryDatum& d, ConnectorModel& cm ); double LTP_; double LTD_; double tau_LTP_; double tau_LTD_; double Wmax_; double tau_syn_update_interval_; double constant_additive_value_; bool reset_weight_change_; }; template < typename targetidentifierT > class STDPIzhConnection: public nest::Connection< targetidentifierT > //class STDPIzhConnection : public Connection< TargetIdentifierPtrRport > { public: typedef nest::CommonSynapseProperties CommonPropertiesType; // typedef STDPIzhCommonProperties CommonPropertiesType; typedef nest::Connection< targetidentifierT > ConnectionBase; // typedef Connection< TargetIdentifierPtrRport > ConnectionBase; /** * Default Constructor. * Sets default values for all parameters. Needed by GenericConnectorModel. */ STDPIzhConnection(); /** * Copy constructor. * Needs to be defined properly in order for GenericConnector to work. */ STDPIzhConnection( const STDPIzhConnection& ); // Explicitly declare all methods inherited from the dependent base // ConnectionBase. This avoids explicit name prefixes in all places these // functions are used. Since ConnectionBase depends on the template parameter, // they are not automatically found in the base class. using ConnectionBase::get_delay_steps; using ConnectionBase::get_delay; using ConnectionBase::get_rport; using ConnectionBase::get_target; /** * Get all properties of this connection and put them into a dictionary. */ void get_status( DictionaryDatum& d ) const; /** * Set properties of this connection from the values given in dictionary. */ // void set_status( const DictionaryDatum& d, ConnectorModel& cm ); void set_status( const DictionaryDatum& d, nest::ConnectorModel& cm ); /** * Send an event to the receiver of this connection. * \param e The event to send * \param tid thread of this synapse // * \param t_lastspike Point in time of last spike sent. //deleted comment per ref: https://nest.github.io/nest-simulator/model_conversion_5g * \param cp common properties of all synapses (empty). */ // void send( Event& e, //deleted per ref: https://nest.github.io/nest-simulator/model_conversion_5g // thread tid, //deleted per ref: https://nest.github.io/nest-simulator/model_conversion_5g // double t_lastspike, //deleted per ref: https://nest.github.io/nest-simulator/model_conversion_5g // const CommonPropertiesType& cp ); //deleted per ref: https://nest.github.io/nest-simulator/model_conversion_5g // void send( Event& e, thread tid, const CommonSynapseProperties& cp ); //added per ref: https://nest.github.io/nest-simulator/model_conversion_5g void send( nest::Event& e, nest::thread tid, const CommonSynapseProperties& cp ); //changed above per sample in ref: https://github.com/nest/nest-simulator/blob/master/examples/MyModule/drop_odd_spike_connection.h bool requires_time_driven_update() const { return true; } void time_driven_update( const thread tid, const double t_trig, const CommonPropertiesType& ); class ConnTestDummyNode : public nest::ConnTestDummyNodeBase //replaced below per sample in ref: https://github.com/nest/nest-simulator/blob/master/examples/MyModule/drop_odd_spike_connection.h // class ConnTestDummyNode : public ConnTestDummyNodeBase { public: // Ensure proper overriding of overloaded virtual functions. // Return values from functions are ignored. using nest::ConnTestDummyNodeBase::handles_test_event; //replaced below per sample in ref: https://github.com/nest/nest-simulator/blob/master/examples/MyModule/drop_odd_spike_connection.h // using ConnTestDummyNodeBase::handles_test_event; port handles_test_event( nest::SpikeEvent&, nest::rport ) //replaced below per sample in ref: https://github.com/nest/nest-simulator/blob/master/examples/MyModule/drop_odd_spike_connection.h // handles_test_event( SpikeEvent&, rport ) { return nest::invalid_port_; //replaced below per sample in ref: https://github.com/nest/nest-simulator/blob/master/examples/MyModule/drop_odd_spike_connection.h // return invalid_port_; } }; /** * Check that requested connection can be created. * * This function is a boilerplate function that should be included unchanged * in all synapse models. It is called before a connection is added to check * that the connection is legal. It is a wrapper that allows us to call * the "real" `check_connection_()` method with the `ConnTestDummyNode * dummy_target;` class for this connection type. This avoids a virtual * function call for better performance. * * @param source Source node for connection * @param target Target node for connection * @param receptor_type Receptor type for connection */ void // check_connection( Node& source, // // Node& target, // // rport receptor_type, // // const CommonPropertiesType& ) // check_connection( nest::Node& source, //replaced above per sample in ref: https://github.com/nest/nest-simulator/blob/master/examples/MyModule/drop_odd_spike_connection.h nest::Node& target, // nest::rport receptor_type, // const CommonPropertiesType& ) // { ConnTestDummyNode dummy_target; ConnectionBase::check_connection_( dummy_target, source, target, receptor_type ); // target.register_stdp_connection( t_lastspike - get_delay() ); //deleted per ref: https://nest.github.io/nest-simulator/model_conversion_5g // target.register_stdp_connection( t_lastspike_ - get_delay() ); //replaced t_lastspike with t_lastspike_ per ref: https://nest.github.io/nest-simulator/model_conversion_5g target.register_stdp_connection( t_lastspike_ - get_delay(),get_delay() ); //changed above to address error by adding second double per example ref: https://github.com/nest/nest-simulator/blob/master/models/stdp_connection_hom.h } double get_weight() const { return weight_; } void set_weight( const double weight ) { weight_ = weight; } private: // data members of each connection double weight_; double wdev_; double t_lastspike_; //addedd per ref: https://nest.github.io/nest-simulator/model_conversion_5g double t_last_update_; double t_last_post_spike_; std::vector< double > pre_spikes_; }; /** * Send an event to the receiver of this connection. * \param e The event to send. * \param tid The thread on which this connection is stored. */ template < typename targetidentifierT > inline void STDPIzhConnection< targetidentifierT >::send( nest::Event& e, //replaced below per sample in ref: https://github.com/nest/nest-simulator/blob/master/examples/MyModule/drop_odd_spike_connection.h nest::thread tid, // const CommonPropertiesType& props) // //STDPIzhConnection::send( Event& e, // // thread tid, // // double, // // const CommonPropertiesType& ) // { // The update of the synaptic weight is implemented in // time_driven_update(), which is triggered in intervals // of one second (syn_update_interval can be adjusted). // keep track of the current presynaptic spike // add delay to spike time to account for purely axonal delay pre_spikes_.push_back( e.get_stamp().get_ms() + get_delay() ); Node* target = get_target( tid ); // send an event to the postsynaptic neuron e.set_receiver(*target); // This is a work-around in order to enable purely axonal delays: // As postsynaptic spikes that are relevant for the update // might not yet be available, do not send the current synaptic // weight but a pointer to this synapse. The postsynaptic // neuron retrieves the correct synaptic weight later when the // spike is due at time t_pre_spike + delay. e.set_weight( static_cast< double >( reinterpret_cast< long >(this) ) ); // Default multiplicity is 1 // Use multiplicity -1 to signal to postsynaptic neuron that this // event is delivered through an STDPIzhBitwiseCorrectConnection e.set_multiplicity( -1 ); e.set_delay( get_delay_steps() ); e.set_rport( get_rport() ); e(); // t_lastspike_ = t_spike; //not included due to error saying t_spike is undefined when include here //tried but deleted to address error although recommended to add per ref: https://nest.github.io/nest-simulator/model_conversion_5g } } // of namespace nest #endif // of #ifndef STDP_IZH_CONNECTION_H