Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set vt_num as long int #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Tests/Check_Models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@
"Wmin": 0.0, # double - Minimal synaptic weight
"Wmax": 4.0, # double - Maximal synaptic weight,
"weight": 1.0,
"delay": 1.0}
"delay": 1.0,
"vt_num": 0}

nest.Connect(PRE,POST,{'rule': 'one_to_one'},conn_param1)
A=nest.GetConnections(PRE,POST)
nest.SetStatus(A,{'vt_num': 0.0})
nest.SetStatus(A,{'vt_num': 1}) # check if also 'after set' still works

conn_param2 = {"model": 'stdp_synapse_cosexp',
"A_minus": -0.01, # double - Amplitude of weight change for depression
"A_plus": 0.01, # double - Amplitude of weight change for facilitation
"Wmin": 0.0, # double - Minimal synaptic weight
"Wmax": 4.0, # double - Maximal synaptic weight,
"weight": 1.0,
"delay": 1.0}
"delay": 1.0,
"vt_num": 0}

nest.Connect(POST,PRE,{'rule': 'one_to_one'},conn_param2)
A=nest.GetConnections(POST,PRE)
nest.SetStatus(A,{'vt_num': 0.0})
nest.SetStatus(A,{"vt_num": 1}) # check if also 'after set' still works

sys.exit(0) #Everything went fine
2 changes: 1 addition & 1 deletion Tests/Check_MultiThreading.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

nest.Connect(PRE,POST,{'rule': 'one_to_one'},conn_param1)
A = nest.GetConnections(PRE,POST)
nest.SetStatus(A, {"vt_num" : 0.0})
nest.SetStatus(A, {"vt_num" : 0})
SPIKES1 = [50.0, 100.0, 110.0, 120.0, 130.0, 210.0, 370.0, 490.0]
SPIKES2 = [1.0, 200.0, 220.0, 230.0]

Expand Down
2 changes: 1 addition & 1 deletion Tests/Learning_Performance_Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
PFPC_conn_param = {"model": 'stdp_synapse_sinexp',
"weight": Init_PFPC,
"delay": 1.0,
"vt_num": float(n)
"vt_num": n
}
nest.Connect(GR, [PCi], {'rule': "fixed_indegree", 'indegree': 65600, "multapses": False, "autapses": False},
PFPC_conn_param)
Expand Down
2 changes: 1 addition & 1 deletion Tests/Learning_Performance_Test2.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def main():
MFDCN_conn_param = {"model": 'stdp_synapse_cosexp',
"weight": Init_MFDCN,
"delay": 1.0,
"vt_num": float(i)}
"vt_num": i}

nest.Connect([MF[i]], [DCNind], "one_to_one", MFDCN_conn_param)

Expand Down
17 changes: 6 additions & 11 deletions cerebmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,18 @@ mynest::CerebModule::init( SLIInterpreter* i )
Kunkel et al, Front Neurofinfom 8:78 (2014), Sec 3.3.2, for details.
*/
nest::kernel()
.model_manager.register_connection_model< STDPAlphaConnection< nest::
TargetIdentifierPtrRport > >( "stdp_synapse_alpha" );

.model_manager.register_connection_model< STDPAlphaConnection >( "stdp_synapse_alpha" );

nest::kernel()
.model_manager.register_connection_model< STDPSinExpConnection< nest::
TargetIdentifierPtrRport > >( "stdp_synapse_sinexp" );
.model_manager.register_connection_model< STDPSinExpConnection >( "stdp_synapse_sinexp" );

nest::kernel()
.model_manager.register_connection_model< STDPCosExpConnection< nest::
TargetIdentifierPtrRport > >( "stdp_synapse_cosexp" );
.model_manager.register_connection_model< STDPCosExpConnection >( "stdp_synapse_cosexp" );

nest::kernel()
.model_manager.register_connection_model< iSTDP< nest::
TargetIdentifierPtrRport > >( "istdp_synapse" );
.model_manager.register_connection_model< iSTDP >( "istdp_synapse" );

nest::kernel()
.model_manager.register_connection_model< Sgritta2017< nest::
TargetIdentifierPtrRport > >( "sgritta_synapse" );
.model_manager.register_connection_model< Sgritta2017 >( "sgritta_synapse" );

} // CerebModule::init()
62 changes: 42 additions & 20 deletions stdp_connection_alpha.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ class STDPAlphaConnection : public nest::Connection< targetidentifierT >
ConnTestDummyNode dummy_target;
ConnectionBase::check_connection_( dummy_target, s, t, receptor_type );
t.register_stdp_connection( t_lastspike_ - get_delay(), get_delay() );
vt_num_is_long_ = 1;
}

void set_weight( double w ){
weight_ = w;
vt_num_is_long_ = 0;
}

void set_vt_num( double n ){
vt_num_ = n;
}
void set_vt_num(const DictionaryDatum& d);

private:
// update dopamine trace from last to current dopamine spike and increment index
Expand All @@ -212,9 +212,25 @@ class STDPAlphaConnection : public nest::Connection< targetidentifierT >
// time of last update, which is either time of last presyn. spike or time-driven update
double t_last_update_;

double vt_num_;
long vt_num_;

double t_lastspike_;

// This bool is necessary when the user wants to contemporary create the connection and
// set the value of vt_num_ (passing it in the dictionary), without generating a type error
// (probably caused by a nest old version bug).
// In fact, just in this type of connection definition, the "vt_num" element in the dictionary
// is converted to double and we should re-convert to long before assign to vt_num_.
// To properly identify this situation, we use vt_num_is_long_, whose default value is 1.
// If the user uses the function nest.Connect(..., {'vt_num': i}), nest calls the
// following custom functions, in order:
// 1. set_weight(),
// 2. set_status(),
// 3. check_connection().
// In set_weight we update vt_num_is_long_=0, so that we are ready to convert vt_num to long
// in set_status. In check_connection we reset vt_num_is_long_=1, ready for eventual consequent
// calls. This structure is also robust to other strategies of setting connection parameters.
bool vt_num_is_long_;
};

//
Expand All @@ -227,8 +243,9 @@ template < typename targetidentifierT > STDPAlphaConnection< targetidentifierT >
, weight_( 1.0 )
, dopa_spikes_idx_( 0 )
, t_last_update_( 0.0 )
, vt_num_ ( 0.0 )
, vt_num_ ( 0 )
, t_lastspike_( 0.0 )
, vt_num_is_long_ ( 1 )
{
}

Expand All @@ -240,6 +257,7 @@ template < typename targetidentifierT > STDPAlphaConnection< targetidentifierT >
, t_last_update_( rhs.t_last_update_ )
, vt_num_ ( rhs.vt_num_ )
, t_lastspike_( rhs.t_lastspike_ )
, vt_num_is_long_ ( rhs.vt_num_is_long_ )
{
}

Expand All @@ -248,7 +266,7 @@ template < typename targetidentifierT > void STDPAlphaConnection< targetidentifi
// base class properties, different for individual synapse
ConnectionBase::get_status( d );
def< double >( d, nest::names::weight, weight_ );
def< double >( d, "vt_num", vt_num_ );
def< long >( d, "vt_num", vt_num_ );
if ( vt_ != 0 )
{
def< long >( d, "modulator", vt_->get_gid() );
Expand Down Expand Up @@ -282,7 +300,7 @@ STDPAlphaConnection< targetidentifierT >::set_status( const DictionaryDatum& d,
// base class properties
ConnectionBase::set_status( d, cm );
updateValue< double >( d, nest::names::weight, weight_ );
updateValue< double >( d, "vt_num", vt_num_ );
set_vt_num( d );
long vtgid;
if ( updateValue< long >( d, nest::names::vt, vtgid ) )
{
Expand Down Expand Up @@ -349,7 +367,7 @@ STDPAlphaConnection< targetidentifierT >::process_dopa_spikes_(
// process dopa spikes in (t0, t1]
// propagate weight from t0 to t1
if ( ( dopa_spikes.size() > dopa_spikes_idx_ ) &&
( dopa_spikes[ dopa_spikes_idx_ ].spike_time_ <= t1 && dopa_spikes[ dopa_spikes_idx_+1 ].multiplicity_ == int (vt_num_ ) ) )
( dopa_spikes[ dopa_spikes_idx_ ].spike_time_ <= t1 && dopa_spikes[ dopa_spikes_idx_+1 ].multiplicity_ == vt_num_ ) )
{
// A IO SPIKE IS DETECTED AT TIME T0, LTD happens with a different amplitude, it depends on the distance between IO SPIKE and PF spikes
update_dopamine_( dopa_spikes, cp );
Expand Down Expand Up @@ -427,20 +445,24 @@ STDPAlphaConnection< targetidentifierT >::trigger_update_weight(


template < typename targetidentifierT >
inline nest::Node*
STDPAlphaConnection< targetidentifierT >::get_node()
void
STDPAlphaConnection< targetidentifierT >::set_vt_num (const DictionaryDatum& d)
{
if ( vt_ == 0 )
{
throw nest::BadProperty( "No neuron has been assigned as the modulator of the synapse." );
}
else
{
return vt_;
}
if (vt_num_is_long_)
{
updateValue< long >( d, mynames::vt_num, vt_num_ );
}
else
{
if (d->known(mynames::vt_num))
{
// only in this case is double in the dictionary
double tmp = getValue< double >( d, mynames::vt_num );
vt_num_ = (long) tmp;
}
}
}

} // of namespace mynest

#endif // of #ifndef STDP_CONNECTION_ALPHA_H

51 changes: 44 additions & 7 deletions stdp_connection_cosexp.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ class STDPCosExpConnection : public nest::Connection< targetidentifierT >
ConnTestDummyNode dummy_target;
ConnectionBase::check_connection_( dummy_target, s, t, receptor_type );
t.register_stdp_connection( t_lastspike_ - get_delay(), get_delay() );
vt_num_is_long_ = 1;
}

void set_weight( double w ){
weight_ = w;
vt_num_is_long_ = 0;
}

void set_vt_num( double n ){
vt_num_ = n;
}
void set_vt_num(const DictionaryDatum& d);

private:
// update dopamine trace from last to current dopamine spike and increment index
Expand All @@ -213,9 +213,25 @@ class STDPCosExpConnection : public nest::Connection< targetidentifierT >
// time of last update, which is either time of last presyn. spike or time-driven update
double t_last_update_;

double vt_num_;
long vt_num_;

double t_lastspike_;

// This bool is necessary when the user wants to contemporary create the connection and
// set the value of vt_num_ (passing it in the dictionary), without generating a type error
// (probably caused by a nest old version bug).
// In fact, just in this type of connection definition, the "vt_num" element in the dictionary
// is converted to double and we should re-convert to long before assign to vt_num_.
// To properly identify this situation, we use vt_num_is_long_, whose default value is 1.
// If the user uses the function nest.Connect(..., {'vt_num': i}), nest calls the
// following custom functions, in order:
// 1. set_weight(),
// 2. set_status(),
// 3. check_connection().
// In set_weight we update vt_num_is_long_=0, so that we are ready to convert vt_num to long
// in set_status. In check_connection we reset vt_num_is_long_=1, ready for eventual consequent
// calls. This structure is also robust to other strategies of setting connection parameters.
bool vt_num_is_long_;
};

//
Expand All @@ -230,6 +246,7 @@ template < typename targetidentifierT > STDPCosExpConnection< targetidentifierT
, t_last_update_( 0.0 )
, vt_num_ ( 0 )
, t_lastspike_( 0.0 )
, vt_num_is_long_ ( 1 )
{
}

Expand All @@ -241,6 +258,7 @@ template < typename targetidentifierT > STDPCosExpConnection< targetidentifierT
, t_last_update_( rhs.t_last_update_ )
, vt_num_ ( rhs.vt_num_ )
, t_lastspike_( rhs.t_lastspike_ )
, vt_num_is_long_ ( rhs.vt_num_is_long_ )
{
}

Expand All @@ -249,7 +267,7 @@ template < typename targetidentifierT > void STDPCosExpConnection< targetidentif
// base class properties, different for individual synapse
ConnectionBase::get_status( d );
def< double >( d, nest::names::weight, weight_ );
def< double >( d, "vt_num", vt_num_ );
def< long >( d, "vt_num", vt_num_ );
if ( vt_ != 0 )
{
def< long >( d, "modulator", vt_->get_gid() );
Expand Down Expand Up @@ -283,7 +301,7 @@ STDPCosExpConnection< targetidentifierT >::set_status( const DictionaryDatum& d,
// base class properties
ConnectionBase::set_status( d, cm );
updateValue< double >( d, nest::names::weight, weight_ );
updateValue< double >( d, "vt_num", vt_num_ );
set_vt_num( d );
long vtgid;
if ( updateValue< long >( d, nest::names::vt, vtgid ) )
{
Expand Down Expand Up @@ -364,7 +382,7 @@ STDPCosExpConnection< targetidentifierT >::process_dopa_spikes_(
// process dopa spikes in (t0, t1]
// propagate weight from t0 to t1
if ( ( dopa_spikes.size() > dopa_spikes_idx_ ) &&
( dopa_spikes[ dopa_spikes_idx_ ].spike_time_ <= t1 && dopa_spikes[ dopa_spikes_idx_+1 ].multiplicity_ == int ( vt_num_ ) ) )
( dopa_spikes[ dopa_spikes_idx_ ].spike_time_ <= t1 && dopa_spikes[ dopa_spikes_idx_+1 ].multiplicity_ == vt_num_ ) )
{
// A IO SPIKE IS DETECTED AT TIME T0, LTD happens with a different amplitude, it depends on the distance between IO SPIKE and PF spikes
update_dopamine_( dopa_spikes, cp );
Expand Down Expand Up @@ -466,6 +484,25 @@ STDPCosExpConnection< targetidentifierT >::get_node()
}
}

template < typename targetidentifierT >
void
STDPCosExpConnection< targetidentifierT >::set_vt_num (const DictionaryDatum& d)
{
if (vt_num_is_long_)
{
updateValue< long >( d, mynames::vt_num, vt_num_ );
}
else
{
if (d->known(mynames::vt_num))
{
// only in this case is double in the dictionary
double tmp = getValue< double >( d, mynames::vt_num );
vt_num_ = (long) tmp;
}
}
}

} // of namespace mynest

#endif // of #ifndef STDP_CONNECTION_COSEXP_H
Loading