NEST main@caf0ae8
 
Loading...
Searching...
No Matches
eprop_archiving_node_recurrent.h
Go to the documentation of this file.
1/*
2 * eprop_archiving_node_recurrent.h
3 *
4 * This file is part of NEST.
5 *
6 * Copyright (C) 2004 The NEST Initiative
7 *
8 * NEST is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * NEST is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#ifndef EPROP_ARCHIVING_NODE_RECURRENT_H
24#define EPROP_ARCHIVING_NODE_RECURRENT_H
25
26// models
28
29// nestkernel
30#include "histentry.h"
31#include "nest_time.h"
32#include "nest_types.h"
33#include "node.h"
34
35namespace nest
36{
37
41template < bool hist_shift_required >
42class EpropArchivingNodeRecurrent : public EpropArchivingNode< HistEntryEpropRecurrent >
43{
44
45public:
50
57
63 typedef double (
64 EpropArchivingNodeRecurrent::*surrogate_gradient_function )( double, double, double, double, double );
65
72 surrogate_gradient_function find_surrogate_gradient( const std::string& surrogate_gradient_function_name );
73
88 const double v_m,
89 const double v_th,
90 const double height,
91 const double width );
92
106 double compute_exponential_surrogate_gradient( const double r,
107 const double v_m,
108 const double v_th,
109 const double height,
110 const double width );
111
126 const double v_m,
127 const double v_th,
128 const double height,
129 const double width );
130
146 const double v_m,
147 const double v_th,
148 const double height,
149 const double width );
150
156 void append_new_eprop_history_entry( const long time_step );
157
164 void write_surrogate_gradient_to_history( const long time_step, const double surrogate_gradient );
165
176 void write_learning_signal_to_history( const long time_step, const double learning_signal );
177
186 void write_firing_rate_reg_to_history( const long t_current_update, const double f_target, const double c_reg );
187
197 void write_firing_rate_reg_to_history( const long time_step,
198 const double z,
199 const double f_target,
200 const double kappa_reg,
201 const double c_reg );
202
210 double get_firing_rate_reg_history( const long time_step );
211
219 double get_learning_signal_from_history( const long time_step );
220
228
233
238
239 void get_status( Dictionary& d ) const override;
240 void set_status( const Dictionary& d ) override;
241
244
246 double f_av_;
247
248protected:
249 long model_dependent_history_shift_() const override;
250
254
255private:
257 size_t n_spikes_;
258
260 std::vector< HistEntryEpropFiringRateReg > firing_rate_reg_history_;
261
268 static std::map< std::string, surrogate_gradient_function > surrogate_gradient_funcs_;
269};
270
271template < bool hist_shift_required >
272inline void
274{
277
278 if constexpr ( not hist_shift_required )
279 {
280 d[ names::eprop_isi_trace_cutoff ] = eprop_isi_trace_cutoff_;
281 }
282}
283
284template < bool hist_shift_required >
285inline void
287{
288 FlushEventMechanism::set_status( d, this, hist_shift_required );
290
291 if constexpr ( not hist_shift_required )
292 {
293 double eprop_isi_trace_cutoff_tmp = eprop_isi_trace_cutoff_;
294
295 update_value_param( d, names::eprop_isi_trace_cutoff, eprop_isi_trace_cutoff_tmp, this );
296
297 if ( eprop_isi_trace_cutoff_tmp < 0.0 )
298 {
299 throw BadProperty( "eprop_isi_trace_cutoff ≥ 0 required." );
300 }
301
302 eprop_isi_trace_cutoff_ = eprop_isi_trace_cutoff_tmp;
303 }
304}
305
306template < bool hist_shift_required >
307inline void
312
313template < bool hist_shift_required >
314inline void
319
320template < bool hist_shift_required >
321long
323{
324 if constexpr ( hist_shift_required )
325 {
326 return get_shift();
327 }
328 else
329 {
330 return -delay_rec_out_;
331 }
332}
333
334}
335
336#endif
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 implementing an intermediate archiving node model for recurrent node models supporting e-prop p...
Definition eprop_archiving_node_recurrent.h:43
void reset_spike_count()
Resets the spike count for the firing rate regularization.
Definition eprop_archiving_node_recurrent.h:315
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 count_spike()
Counts an emitted spike for the firing rate regularization.
Definition eprop_archiving_node_recurrent.h:308
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
void set_status(const Dictionary &d) override
Change properties of the node according to the entries in the dictionary.
Definition eprop_archiving_node_recurrent.h:286
size_t n_spikes_
Count of the emitted spikes for the firing rate regularization.
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
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
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
void get_status(Dictionary &d) const override
Export properties of the node by setting entries in the status dictionary.
Definition eprop_archiving_node_recurrent.h:273
long model_dependent_history_shift_() const override
Returns the correct shift for history depending on whether it is a normal or a bsshslm_2020 model.
Definition eprop_archiving_node_recurrent.h:322
std::vector< HistEntryEpropFiringRateReg > firing_rate_reg_history_
History of the firing rate regularization.
Definition eprop_archiving_node_recurrent.h:260
surrogate_gradient_function compute_surrogate_gradient_
Pointer to member function selected for computing the surrogate gradient.
Definition eprop_archiving_node_recurrent.h:252
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
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
Base class implementing archiving for node models supporting e-prop plasticity.
Definition eprop_archiving_node.h:53
void set_status(const Dictionary &d, Node *node, const bool check_eprop_constraint=false)
Sets and validates parameters from the status dictionary.
Definition flush_event_mechanism.cpp:62
void get_status(Dictionary &d) const
Retrieves parameters and adds them to the status dictionary.
Definition flush_event_mechanism.cpp:56
void get_status(Dictionary &d) const
Retrieves parameters and adds them to the status dictionary.
Definition ignore_and_spike_mechanism.cpp:66
void set_status(const Dictionary &d, Node *node)
Sets and validates parameters from the status dictionary.
Definition ignore_and_spike_mechanism.cpp:74
const std::string eprop_isi_trace_cutoff("eprop_isi_trace_cutoff")
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
bool update_value_param(Dictionary const &d, const std::string &key, T &value, nest::Node *node)
Obtain value from parameter dictionary including evaluation of random or spatial parameters.
Definition dict_util.h:42
Declarations for base class Node.