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

Remove irregular spike arrival #20

Merged
Merged
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
12 changes: 4 additions & 8 deletions models/eprop_iaf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ eprop_iaf::Parameters_::Parameters_()
, beta_( 1.0 )
, gamma_( 0.3 )
, I_e_( 0.0 )
, regular_spike_arrival_( true )
, surrogate_gradient_function_( "piecewise_linear" )
, t_ref_( 2.0 )
, tau_m_( 10.0 )
Expand Down Expand Up @@ -122,7 +121,6 @@ eprop_iaf::Parameters_::get( DictionaryDatum& d ) const
def< double >( d, names::beta, beta_ );
def< double >( d, names::gamma, gamma_ );
def< double >( d, names::I_e, I_e_ );
def< bool >( d, names::regular_spike_arrival, regular_spike_arrival_ );
def< std::string >( d, names::surrogate_gradient_function, surrogate_gradient_function_ );
def< double >( d, names::t_ref, t_ref_ );
def< double >( d, names::tau_m, tau_m_ );
Expand Down Expand Up @@ -155,7 +153,6 @@ eprop_iaf::Parameters_::set( const DictionaryDatum& d, Node* node )
updateValueParam< double >( d, names::beta, beta_, node );
updateValueParam< double >( d, names::gamma, gamma_, node );
updateValueParam< double >( d, names::I_e, I_e_, node );
updateValueParam< bool >( d, names::regular_spike_arrival, regular_spike_arrival_, node );
updateValueParam< std::string >( d, names::surrogate_gradient_function, surrogate_gradient_function_, node );
updateValueParam< double >( d, names::t_ref, t_ref_, node );
updateValueParam< double >( d, names::tau_m, tau_m_, node );
Expand Down Expand Up @@ -274,7 +271,6 @@ eprop_iaf::pre_run_hook()

V_.P_v_m_ = std::exp( -dt / P_.tau_m_ );
V_.P_i_in_ = P_.tau_m_ / P_.C_m_ * ( 1.0 - V_.P_v_m_ );
V_.P_z_in_ = P_.regular_spike_arrival_ ? 1.0 : 1.0 - V_.P_v_m_;
}

long
Expand Down Expand Up @@ -307,8 +303,7 @@ eprop_iaf::update( Time const& origin, const long from, const long to )

S_.z_in_ = B_.spikes_.get_value( lag );

S_.v_m_ = V_.P_i_in_ * S_.i_in_ + V_.P_z_in_ * S_.z_in_ + V_.P_v_m_ * S_.v_m_;
S_.v_m_ -= P_.V_th_ * S_.z_;
S_.v_m_ = V_.P_i_in_ * S_.i_in_ + S_.z_in_ + V_.P_v_m_ * S_.v_m_;
S_.v_m_ = std::max( S_.v_m_, P_.V_min_ );

S_.z_ = 0.0;
Expand All @@ -321,6 +316,7 @@ eprop_iaf::update( Time const& origin, const long from, const long to )
kernel().event_delivery_manager.send( *this, se, lag );

S_.z_ = 1.0;
S_.v_m_ -= P_.V_th_ * S_.z_;
S_.r_ = V_.RefractoryCounts_;
}

Expand Down Expand Up @@ -415,9 +411,9 @@ eprop_iaf::compute_gradient( const long t_spike,
L = eprop_hist_it->learning_signal_;
firing_rate_reg = eprop_hist_it->firing_rate_reg_;

z_bar = V_.P_v_m_ * z_bar + V_.P_z_in_ * z;
z_bar = V_.P_v_m_ * z_bar + z;
e = psi * z_bar;
e_bar = P_.kappa_ * e_bar + ( 1.0 - P_.kappa_ ) * e;
e_bar = P_.kappa_ * e_bar + e;
e_bar_reg = P_.kappa_reg_ * e_bar_reg + ( 1.0 - P_.kappa_reg_ ) * e;

if ( optimize_each_step )
Expand Down
11 changes: 0 additions & 11 deletions models/eprop_iaf.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,6 @@ Parameter Unit Math equivalent Default Des
``C_m`` pF :math:`C_\text{m}` 250.0 Capacitance of the membrane
``E_L`` mV :math:`E_\text{L}` -70.0 Leak / resting membrane potential
``I_e`` pA :math:`I_\text{e}` 0.0 Constant external input current
``regular_spike_arrival`` Boolean ``True`` If ``True``, the input spikes
arrive at the end of the time step,
if ``False`` at the beginning
(determines PSC scale)
``t_ref`` ms :math:`t_\text{ref}` 2.0 Duration of the refractory period
``tau_m`` ms :math:`\tau_\text{m}` 10.0 Time constant of the membrane
``V_min`` mV :math:`v_\text{min}` negative maximum Absolute lower bound of the
Expand Down Expand Up @@ -440,9 +436,6 @@ class eprop_iaf : public EpropArchivingNodeRecurrent
//! Constant external input current (pA).
double I_e_;

//! If True, the input spikes arrive at the beginning of the time step, if False at the end (determines PSC scale).
bool regular_spike_arrival_;

//! Surrogate gradient / pseudo-derivative function of the membrane voltage ["piecewise_linear", "exponential",
//! "fast_sigmoid_derivative", "arctan"]
std::string surrogate_gradient_function_;
Expand Down Expand Up @@ -537,10 +530,6 @@ class eprop_iaf : public EpropArchivingNodeRecurrent
//! Propagator matrix entry for evolving the membrane voltage (mathematical symbol "alpha" in user documentation).
double P_v_m_;

//! Propagator matrix entry for evolving the incoming spike state variables (mathematical symbol "zeta" in user
//! documentation).
double P_z_in_;

//! Propagator matrix entry for evolving the incoming currents.
double P_i_in_;

Expand Down
12 changes: 4 additions & 8 deletions models/eprop_iaf_adapt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ eprop_iaf_adapt::Parameters_::Parameters_()
, beta_( 1.0 )
, gamma_( 0.3 )
, I_e_( 0.0 )
, regular_spike_arrival_( true )
, surrogate_gradient_function_( "piecewise_linear" )
, t_ref_( 2.0 )
, tau_m_( 10.0 )
Expand Down Expand Up @@ -130,7 +129,6 @@ eprop_iaf_adapt::Parameters_::get( DictionaryDatum& d ) const
def< double >( d, names::beta, beta_ );
def< double >( d, names::gamma, gamma_ );
def< double >( d, names::I_e, I_e_ );
def< bool >( d, names::regular_spike_arrival, regular_spike_arrival_ );
def< std::string >( d, names::surrogate_gradient_function, surrogate_gradient_function_ );
def< double >( d, names::t_ref, t_ref_ );
def< double >( d, names::tau_m, tau_m_ );
Expand Down Expand Up @@ -165,7 +163,6 @@ eprop_iaf_adapt::Parameters_::set( const DictionaryDatum& d, Node* node )
updateValueParam< double >( d, names::beta, beta_, node );
updateValueParam< double >( d, names::gamma, gamma_, node );
updateValueParam< double >( d, names::I_e, I_e_, node );
updateValueParam< bool >( d, names::regular_spike_arrival, regular_spike_arrival_, node );
updateValueParam< std::string >( d, names::surrogate_gradient_function, surrogate_gradient_function_, node );
updateValueParam< double >( d, names::t_ref, t_ref_, node );
updateValueParam< double >( d, names::tau_m, tau_m_, node );
Expand Down Expand Up @@ -308,7 +305,6 @@ eprop_iaf_adapt::pre_run_hook()

V_.P_v_m_ = std::exp( -dt / P_.tau_m_ );
V_.P_i_in_ = P_.tau_m_ / P_.C_m_ * ( 1.0 - V_.P_v_m_ );
V_.P_z_in_ = P_.regular_spike_arrival_ ? 1.0 : 1.0 - V_.P_v_m_;
V_.P_adapt_ = std::exp( -dt / P_.adapt_tau_ );
}

Expand Down Expand Up @@ -342,8 +338,7 @@ eprop_iaf_adapt::update( Time const& origin, const long from, const long to )

S_.z_in_ = B_.spikes_.get_value( lag );

S_.v_m_ = V_.P_i_in_ * S_.i_in_ + V_.P_z_in_ * S_.z_in_ + V_.P_v_m_ * S_.v_m_;
S_.v_m_ -= P_.V_th_ * S_.z_;
S_.v_m_ = V_.P_i_in_ * S_.i_in_ + S_.z_in_ + V_.P_v_m_ * S_.v_m_;
S_.v_m_ = std::max( S_.v_m_, P_.V_min_ );

S_.adapt_ = V_.P_adapt_ * S_.adapt_ + S_.z_;
Expand All @@ -360,6 +355,7 @@ eprop_iaf_adapt::update( Time const& origin, const long from, const long to )
kernel().event_delivery_manager.send( *this, se, lag );

S_.z_ = 1.0;
S_.v_m_ -= P_.V_th_ * S_.z_;
S_.r_ = V_.RefractoryCounts_;
}

Expand Down Expand Up @@ -454,10 +450,10 @@ eprop_iaf_adapt::compute_gradient( const long t_spike,
L = eprop_hist_it->learning_signal_;
firing_rate_reg = eprop_hist_it->firing_rate_reg_;

z_bar = V_.P_v_m_ * z_bar + V_.P_z_in_ * z;
z_bar = V_.P_v_m_ * z_bar + z;
e = psi * ( z_bar - P_.adapt_beta_ * epsilon );
epsilon = V_.P_adapt_ * epsilon + e;
e_bar = P_.kappa_ * e_bar + ( 1.0 - P_.kappa_ ) * e;
e_bar = P_.kappa_ * e_bar + e;
e_bar_reg = P_.kappa_reg_ * e_bar_reg + ( 1.0 - P_.kappa_reg_ ) * e;

if ( optimize_each_step )
Expand Down
11 changes: 0 additions & 11 deletions models/eprop_iaf_adapt.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ Parameter Unit Math equivalent Default Des
``C_m`` pF :math:`C_\text{m}` 250.0 Capacitance of the membrane
``E_L`` mV :math:`E_\text{L}` -70.0 Leak / resting membrane potential
``I_e`` pA :math:`I_\text{e}` 0.0 Constant external input current
``regular_spike_arrival`` Boolean ``True`` If ``True``, the input spikes
arrive at the end of the time step,
if ``False`` at the beginning
(determines PSC scale)
``t_ref`` ms :math:`t_\text{ref}` 2.0 Duration of the refractory period
``tau_m`` ms :math:`\tau_\text{m}` 10.0 Time constant of the membrane
``V_min`` mV :math:`v_\text{min}` negative maximum Absolute lower bound of the
Expand Down Expand Up @@ -414,9 +410,6 @@ class eprop_iaf_adapt : public EpropArchivingNodeRecurrent
//! Constant external input current (pA).
double I_e_;

//! If True, the input spikes arrive at the beginning of the time step, if False at the end (determines PSC scale).
bool regular_spike_arrival_;

//! Surrogate gradient / pseudo-derivative function of the membrane voltage ["piecewise_linear", "exponential",
//! "fast_sigmoid_derivative", "arctan"]
std::string surrogate_gradient_function_;
Expand Down Expand Up @@ -517,10 +510,6 @@ class eprop_iaf_adapt : public EpropArchivingNodeRecurrent
//! Propagator matrix entry for evolving the membrane voltage (mathematical symbol "alpha" in user documentation).
double P_v_m_;

//! Propagator matrix entry for evolving the incoming spike state variables (mathematical symbol "zeta" in user
//! documentation).
double P_z_in_;

//! Propagator matrix entry for evolving the incoming currents.
double P_i_in_;

Expand Down
2 changes: 1 addition & 1 deletion models/eprop_iaf_psc_delta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ eprop_iaf_psc_delta::compute_gradient( const long t_spike,

z_bar = V_.P_v_m_ * z_bar + z;
e = psi * z_bar;
e_bar = P_.kappa_ * e_bar + ( 1.0 - P_.kappa_ ) * e;
e_bar = P_.kappa_ * e_bar + e;
e_bar_reg = P_.kappa_reg_ * e_bar_reg + ( 1.0 - P_.kappa_reg_ ) * e;

if ( optimize_each_step )
Expand Down
2 changes: 1 addition & 1 deletion models/eprop_iaf_psc_delta_adapt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ eprop_iaf_psc_delta_adapt::compute_gradient( const long t_spike,
z_bar = V_.P_v_m_ * z_bar + z;
e = psi * ( z_bar - P_.adapt_beta_ * epsilon );
epsilon = V_.P_adapt_ * epsilon + e;
e_bar = P_.kappa_ * e_bar + ( 1.0 - P_.kappa_ ) * e;
e_bar = P_.kappa_ * e_bar + e;
e_bar_reg = P_.kappa_reg_ * e_bar_reg + ( 1.0 - P_.kappa_reg_ ) * e;

if ( optimize_each_step )
Expand Down
8 changes: 2 additions & 6 deletions models/eprop_readout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ eprop_readout::Parameters_::Parameters_()
: C_m_( 250.0 )
, E_L_( 0.0 )
, I_e_( 0.0 )
, regular_spike_arrival_( true )
, tau_m_( 10.0 )
, V_min_( -std::numeric_limits< double >::max() )
, eprop_isi_trace_cutoff_( 1000.0 )
Expand Down Expand Up @@ -109,7 +108,6 @@ eprop_readout::Parameters_::get( DictionaryDatum& d ) const
def< double >( d, names::C_m, C_m_ );
def< double >( d, names::E_L, E_L_ );
def< double >( d, names::I_e, I_e_ );
def< bool >( d, names::regular_spike_arrival, regular_spike_arrival_ );
def< double >( d, names::tau_m, tau_m_ );
def< double >( d, names::V_min, V_min_ + E_L_ );
def< double >( d, names::eprop_isi_trace_cutoff, eprop_isi_trace_cutoff_ );
Expand All @@ -127,7 +125,6 @@ eprop_readout::Parameters_::set( const DictionaryDatum& d, Node* node )

updateValueParam< double >( d, names::C_m, C_m_, node );
updateValueParam< double >( d, names::I_e, I_e_, node );
updateValueParam< bool >( d, names::regular_spike_arrival, regular_spike_arrival_, node );
updateValueParam< double >( d, names::tau_m, tau_m_, node );
updateValueParam< double >( d, names::eprop_isi_trace_cutoff, eprop_isi_trace_cutoff_, node );

Expand Down Expand Up @@ -210,7 +207,6 @@ eprop_readout::pre_run_hook()

V_.P_v_m_ = std::exp( -dt / P_.tau_m_ );
V_.P_i_in_ = P_.tau_m_ / P_.C_m_ * ( 1.0 - V_.P_v_m_ );
V_.P_z_in_ = P_.regular_spike_arrival_ ? 1.0 : 1.0 - V_.P_v_m_;
}

long
Expand Down Expand Up @@ -242,7 +238,7 @@ eprop_readout::update( Time const& origin, const long from, const long to )

S_.z_in_ = B_.spikes_.get_value( lag );

S_.v_m_ = V_.P_i_in_ * S_.i_in_ + V_.P_z_in_ * S_.z_in_ + V_.P_v_m_ * S_.v_m_;
S_.v_m_ = V_.P_i_in_ * S_.i_in_ + S_.z_in_ + V_.P_v_m_ * S_.v_m_;
S_.v_m_ = std::max( S_.v_m_, P_.V_min_ );

( this->*compute_error_signal )( lag );
Expand Down Expand Up @@ -361,7 +357,7 @@ eprop_readout::compute_gradient( const long t_spike,

L = eprop_hist_it->error_signal_;

z_bar = V_.P_v_m_ * z_bar + V_.P_z_in_ * z;
z_bar = V_.P_v_m_ * z_bar + z;

if ( optimize_each_step )
{
Expand Down
11 changes: 0 additions & 11 deletions models/eprop_readout.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ Parameter Unit Math equivalent Default Descr
``C_m`` pF :math:`C_\text{m}` 250.0 Capacitance of the membrane
``E_L`` mV :math:`E_\text{L}` 0.0 Leak / resting membrane potential
``I_e`` pA :math:`I_\text{e}` 0.0 Constant external input current
``regular_spike_arrival`` Boolean ``True`` If ``True``, the input spikes arrive
at the end of the time step, if
``False`` at the beginning
(determines PSC scale)
``tau_m`` ms :math:`\tau_\text{m}` 10.0 Time constant of the membrane
``V_min`` mV :math:`v_\text{min}` negative maximum Absolute lower bound of the membrane
value voltage
Expand Down Expand Up @@ -342,9 +338,6 @@ class eprop_readout : public EpropArchivingNodeReadout
//! Constant external input current (pA).
double I_e_;

//! If True, the input spikes arrive at the beginning of the time step, if False at the end (determines PSC scale).
bool regular_spike_arrival_;

//! Time constant of the membrane (ms).
double tau_m_;

Expand Down Expand Up @@ -423,10 +416,6 @@ class eprop_readout : public EpropArchivingNodeReadout
//! Propagator matrix entry for evolving the membrane voltage (mathematical symbol "kappa" in user documentation).
double P_v_m_;

//! Propagator matrix entry for evolving the incoming spike state variables (mathematical symbol "zeta" in user
//! documentation).
double P_z_in_;

//! Propagator matrix entry for evolving the incoming currents.
double P_i_in_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@
"E_L": 0.0, # mV, leak / resting membrane potential
"eprop_isi_trace_cutoff": 100, # cutoff of integration of eprop trace between spikes
"I_e": 0.0, # pA, external current input
"regular_spike_arrival": False, # If True, input spikes arrive at end of time step, if False at beginning
"tau_m": 20.0, # ms, membrane time constant
"V_m": 0.0, # mV, initial value of the membrane voltage
}
Expand All @@ -211,9 +210,8 @@
"f_target": 10.0, # spikes/s, target firing rate for firing rate regularization
"gamma": 0.5, # height scaling of the pseudo-derivative
"I_e": 0.0,
"kappa": 0.97, # low-pass filter of the eligibility trace
"kappa_reg": 0.97, # low-pass filter of the firing rate for regularization
"regular_spike_arrival": True,
"kappa": 0.95, # low-pass filter of the eligibility trace
"kappa_reg": 0.95, # low-pass filter of the firing rate for regularization
"surrogate_gradient_function": "piecewise_linear", # surrogate gradient / pseudo-derivative function
"t_ref": 5.0, # ms, duration of refractory period
"tau_m": 20.0,
Expand All @@ -232,9 +230,8 @@
"f_target": 10.0,
"gamma": 0.5,
"I_e": 0.0,
"kappa": 0.97,
"kappa_reg": 0.97,
"regular_spike_arrival": True,
"kappa": 0.95,
"kappa_reg": 0.95,
"surrogate_gradient_function": "piecewise_linear",
"t_ref": 5.0,
"tau_m": 20.0,
Expand All @@ -247,6 +244,10 @@
/ (1.0 - np.exp(-duration["step"] / params_nrn_ad["tau_m"]))
) # prefactor of adaptive threshold

scale_factor = 1.0 - params_nrn_reg["kappa"] # factor for rescaling due to removal of irregular spike arrival
params_nrn_reg["c_reg"] /= scale_factor**2
params_nrn_ad["c_reg"] /= scale_factor**2

####################

# Intermediate parrot neurons required between input spike generators and recurrent neurons,
Expand Down Expand Up @@ -363,8 +364,8 @@ def calculate_glorot_dist(fan_in, fan_out):
weights_in_rec = np.array(np.random.randn(n_in, n_rec).T / np.sqrt(n_in), dtype=dtype_weights)
weights_rec_rec = np.array(np.random.randn(n_rec, n_rec).T / np.sqrt(n_rec), dtype=dtype_weights)
np.fill_diagonal(weights_rec_rec, 0.0) # since no autapses set corresponding weights to zero
weights_rec_out = np.array(calculate_glorot_dist(n_rec, n_out).T, dtype=dtype_weights)
weights_out_rec = np.array(np.random.randn(n_rec, n_out), dtype=dtype_weights)
weights_rec_out = np.array(calculate_glorot_dist(n_rec, n_out).T, dtype=dtype_weights) * scale_factor
weights_out_rec = np.array(np.random.randn(n_rec, n_out), dtype=dtype_weights) / scale_factor

params_common_syn_eprop = {
"optimizer": {
Expand All @@ -373,7 +374,7 @@ def calculate_glorot_dist(fan_in, fan_out):
"beta_1": 0.9, # exponential decay rate for 1st moment estimate of Adam optimizer
"beta_2": 0.999, # exponential decay rate for 2nd moment raw estimate of Adam optimizer
"epsilon": 1e-8, # small numerical stabilization constant of Adam optimizer
"eta": 5e-3 / duration["learning_window"], # learning rate
"eta": 5e-3 / duration["learning_window"] * scale_factor**2, # learning rate
"optimize_each_step": True, # call optimizer every time step (True) or once per spike (False); only
# True implements original Adam algorithm, False offers speed-up; choice can affect learning performance
"Wmin": -100.0, # pA, minimal limit of the synaptic weights
Expand Down
Loading
Loading