32template <
bool hist_shift_required >
33std::map< std::string, typename EpropArchivingNodeRecurrent< hist_shift_required >::surrogate_gradient_function >
38 {
"fast_sigmoid_derivative",
40 {
"arctan_derivative",
44template <
bool hist_shift_required >
53template <
bool hist_shift_required >
62template <
bool hist_shift_required >
65 const std::string& surrogate_gradient_function_name )
71 return found_entry_it->second;
74 std::string error_message =
"Surrogate gradient / pseudo-derivate function surrogate_gradient_function from [";
77 error_message +=
" \"" + surrogate_gradient_func.first +
"\",";
79 error_message.pop_back();
80 error_message +=
" ] required.";
82 throw BadProperty( error_message );
85template <
bool hist_shift_required >
98 return height * std::max( 0.0, 1.0 - std::abs( v_m - v_th ) / width );
101template <
bool hist_shift_required >
114 return height * std::exp( -std::abs( v_m - v_th ) / width );
117template <
bool hist_shift_required >
130 return height * std::pow( 1.0 + std::abs( v_m - v_th ) / width, -2.0 );
133template <
bool hist_shift_required >
146 return height / ( 1.0 + std::pow( ( v_m - v_th ) / width, 2.0 ) );
149template <
bool hist_shift_required >
158 eprop_history_.emplace_back( time_step, 0.0, 0.0, 0.0 );
161template <
bool hist_shift_required >
164 const double surrogate_gradient )
172 it_hist->surrogate_gradient_ = surrogate_gradient;
175template <
bool hist_shift_required >
178 const double learning_signal )
187 if constexpr ( hist_shift_required )
192 auto it_hist = get_eprop_history( time_step - shift );
193 const auto it_hist_end = get_eprop_history( time_step - shift + delay_out_rec_ );
195 for ( ; it_hist != it_hist_end; ++it_hist )
197 it_hist->learning_signal_ += learning_signal;
201template <
bool hist_shift_required >
204 const double f_target,
216 const double f_av = n_spikes_ / update_interval;
217 const double f_target_ = f_target * dt;
218 const double firing_rate_reg = c_reg * ( f_av - f_target_ ) / update_interval;
223template <
bool hist_shift_required >
227 const double f_target,
228 const double kappa_reg,
238 const double f_target_ = f_target * dt;
240 f_av_ = kappa_reg *
f_av_ + ( 1.0 - kappa_reg ) * z / dt;
248template <
bool hist_shift_required >
255 return it_hist->firing_rate_reg_;
258template <
bool hist_shift_required >
264 if constexpr ( hist_shift_required )
275 return it->learning_signal_;
278template <
bool hist_shift_required >
287 if ( it_update_hist->access_counter_ == 0 )
double(EpropArchivingNodeRecurrent::* surrogate_gradient_function)(double, double, double, double, double)
Defines the pointer-to-member function type for the surrogate gradient function.
Definition eprop_archiving_node_recurrent.h:64
void write_firing_rate_reg_to_history(const long t_current_update, const double f_target, const double c_reg)
Calculates the firing rate regularization for the current update and writes it to a new entry in the ...
Definition eprop_archiving_node_recurrent_impl.h:203
void write_learning_signal_to_history(const long time_step, const double learning_signal)
Writes the learning signal to the eprop history entry at the specifed time step.
Definition eprop_archiving_node_recurrent_impl.h:177
void append_new_eprop_history_entry(const long time_step)
Creates an entry for the specified time step at the end of the eprop history.
Definition eprop_archiving_node_recurrent_impl.h:151
double f_av_
Average firing rate.
Definition eprop_archiving_node_recurrent.h:246
EpropArchivingNodeRecurrent()
Constructs a new EpropArchivingNodeRecurrent object.
Definition eprop_archiving_node_recurrent_impl.h:45
size_t n_spikes_
Definition eprop_archiving_node_recurrent.h:257
surrogate_gradient_function find_surrogate_gradient(const std::string &surrogate_gradient_function_name)
Validates and finds surrogate gradient function based on the specified name.
Definition eprop_archiving_node_recurrent_impl.h:64
double compute_exponential_surrogate_gradient(const double r, const double v_m, const double v_th, const double height, const double width)
Computes an exponential function as the surrogate gradient.
Definition eprop_archiving_node_recurrent_impl.h:103
double firing_rate_reg_
Firing rate regularization.
Definition eprop_archiving_node_recurrent.h:243
double compute_piecewise_linear_surrogate_gradient(const double r, const double v_m, const double v_th, const double height, const double width)
Computes a piecewise-linear function as the surrogate gradient.
Definition eprop_archiving_node_recurrent_impl.h:87
std::vector< HistEntryEpropFiringRateReg > firing_rate_reg_history_
Definition eprop_archiving_node_recurrent.h:260
double compute_arctan_derivative_surrogate_gradient(const double r, const double v_m, const double v_th, const double height, const double width)
Computes the derivative of an arctan surrogate function as the surrogate gradient.
Definition eprop_archiving_node_recurrent_impl.h:135
void erase_used_firing_rate_reg_history()
Erases the history of the used firing rate regularization history.
Definition eprop_archiving_node_recurrent_impl.h:280
double get_learning_signal_from_history(const long time_step)
Retrieves the learning signal from the eprop history at the specified time step.
Definition eprop_archiving_node_recurrent_impl.h:260
static std::map< std::string, surrogate_gradient_function > surrogate_gradient_funcs_
Maps provided names of surrogate gradients to corresponding pointers to member functions.
Definition eprop_archiving_node_recurrent.h:268
void write_surrogate_gradient_to_history(const long time_step, const double surrogate_gradient)
Writes the surrogate gradient to the eprop history entry at the specified time step.
Definition eprop_archiving_node_recurrent_impl.h:163
double get_firing_rate_reg_history(const long time_step)
Retrieves the firing rate regularization at the specified time step from the firing rate regularizati...
Definition eprop_archiving_node_recurrent_impl.h:250
double compute_fast_sigmoid_derivative_surrogate_gradient(const double r, const double v_m, const double v_th, const double height, const double width)
Computes the derivative of a fast-sigmoid surrogate function as the surrogate gradient.
Definition eprop_archiving_node_recurrent_impl.h:119
std::vector< HistEntryEpropRecurrent > eprop_history_
Definition eprop_archiving_node.h:162
std::vector< HistEntryEpropRecurrent >::iterator get_eprop_history(const long time_step)
Definition eprop_archiving_node_impl.h:157
EpropArchivingNode()
Definition eprop_archiving_node_impl.h:35
std::vector< HistEntryEpropUpdate > update_history_
Definition eprop_archiving_node.h:159
const long delay_rec_out_
Definition eprop_archiving_node.h:174
const long delay_out_rec_
Definition eprop_archiving_node.h:180
const long delay_out_norm_
Definition eprop_archiving_node.h:177
size_t eprop_indegree_
Definition eprop_archiving_node.h:153
Time get_eprop_update_interval() const
Definition simulation_manager.h:343
static Time get_resolution()
Definition nest_time.h:325
long get_steps() const
Definition nest_time.h:504
double get_ms() const
Definition nest_time.h:490
SimulationManager simulation_manager
Definition kernel_manager.h:237
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
KernelManager & kernel()
Definition kernel_manager.h:311
std::map< std::string, typename EpropArchivingNodeRecurrent< hist_shift_required >::surrogate_gradient_function > EpropArchivingNodeRecurrent< hist_shift_required >::surrogate_gradient_funcs_
Definition eprop_archiving_node_recurrent_impl.h:34