NEST main@caf0ae8
 
Loading...
Searching...
No Matches
rate_transformer_node_impl.h
Go to the documentation of this file.
1/*
2 * rate_transformer_node_impl.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 RATE_TRANSFORMER_NODE_IMPL_H
24#define RATE_TRANSFORMER_NODE_IMPL_H
25
27
28// C++ includes:
29#include <cmath> // in case we need isnan() // fabs
30#include <cstdio>
31#include <iomanip>
32#include <iostream>
33#include <limits>
34#include <string>
35
36// Includes from libnestutil:
37#include "dict_util.h"
38#include "numerics.h"
39
40
41// Includes from nestkernel:
42#include "exceptions.h"
43#include "kernel_manager.h"
45
46
47namespace nest
48{
49
50/* ----------------------------------------------------------------
51 * Recordables map
52 * ---------------------------------------------------------------- */
53
54template < class TNonlinearities >
55RecordablesMap< rate_transformer_node< TNonlinearities > > rate_transformer_node< TNonlinearities >::recordablesMap_;
56
57/* ----------------------------------------------------------------
58 * Default constructors defining default parameters and state
59 * ---------------------------------------------------------------- */
60
61template < class TNonlinearities >
66
67template < class TNonlinearities >
72
73/* ----------------------------------------------------------------
74 * Parameter and state extractions and manipulation functions
75 * ---------------------------------------------------------------- */
76
77template < class TNonlinearities >
78void
83
84template < class TNonlinearities >
85void
90
91template < class TNonlinearities >
92void
97
98template < class TNonlinearities >
99void
104
105template < class TNonlinearities >
110
111template < class TNonlinearities >
117
118/* ----------------------------------------------------------------
119 * Default and copy constructor for node
120 * ---------------------------------------------------------------- */
121
122template < class TNonlinearities >
124 : ArchivingNode()
125 , S_()
126 , B_( *this )
127{
128 recordablesMap_.create();
129 Node::set_node_uses_wfr( kernel().simulation_manager.use_wfr() );
130}
131
132template < class TNonlinearities >
134 : ArchivingNode( n )
135 , nonlinearities_( n.nonlinearities_ )
136 , S_( n.S_ )
137 , B_( n.B_, *this )
138{
139 Node::set_node_uses_wfr( kernel().simulation_manager.use_wfr() );
140}
141
142/* ----------------------------------------------------------------
143 * Node initialization functions
144 * ---------------------------------------------------------------- */
145
146template < class TNonlinearities >
147void
149{
150 B_.delayed_rates_.clear(); // includes resize
151
152 // resize buffers
153 const size_t buffer_size = kernel().connection_manager.get_min_delay();
154 B_.instant_rates_.resize( buffer_size, 0.0 );
155 B_.last_y_values.resize( buffer_size, 0.0 );
156
157 B_.logger_.reset(); // includes resize
159}
160
161template < class TNonlinearities >
162void
164{
165 B_.logger_.init(); // ensures initialization in case mm connected after Simulate
166}
167
168/* ----------------------------------------------------------------
169 * Update and event handling functions
170 */
171
172template < class TNonlinearities >
173bool
175 const long from,
176 const long to,
177 const bool called_from_wfr_update )
178{
179 const size_t buffer_size = kernel().connection_manager.get_min_delay();
180 const double wfr_tol = kernel().simulation_manager.get_wfr_tol();
181 bool wfr_tol_exceeded = false;
182
183 // allocate memory to store rates to be sent by rate events
184 std::vector< double > new_rates( buffer_size, 0.0 );
185
186 for ( long lag = from; lag < to; ++lag )
187 {
188 // store rate
189 new_rates[ lag ] = S_.rate_;
190 // reinitialize output rate
191 S_.rate_ = 0.0;
192
193 double delayed_rates = 0;
194 if ( called_from_wfr_update )
195 {
196 // use get_value_wfr_update to keep values in buffer
197 delayed_rates = B_.delayed_rates_.get_value_wfr_update( lag );
198 }
199 else
200 {
201 // use get_value to clear values in buffer after reading
202 delayed_rates = B_.delayed_rates_.get_value( lag );
203 }
204
205 if ( P_.linear_summation_ )
206 {
207 S_.rate_ += nonlinearities_.input( delayed_rates + B_.instant_rates_[ lag ] );
208 }
209 else
210 {
211 S_.rate_ += delayed_rates + B_.instant_rates_[ lag ];
212 }
213
214 if ( called_from_wfr_update )
215 {
216 // check if deviation from last iteration exceeds wfr_tol
217 wfr_tol_exceeded = wfr_tol_exceeded or fabs( S_.rate_ - B_.last_y_values[ lag ] ) > wfr_tol;
218 // update last_y_values for next wfr iteration
219 B_.last_y_values[ lag ] = S_.rate_;
220 }
221 else
222 {
223 // rate logging
224 B_.logger_.record_data( origin.get_steps() + lag );
225 }
226 }
227
228 if ( not called_from_wfr_update )
229 {
230 // Send delay-rate-neuron-event. This only happens in the final iteration
231 // to avoid accumulation in the buffers of the receiving neurons.
233 drve.set_coeffarray( new_rates );
235
236 // clear last_y_values
237 std::vector< double >( buffer_size, 0.0 ).swap( B_.last_y_values );
238
239 // modifiy new_rates for rate-neuron-event as proxy for next min_delay
240 for ( long temp = from; temp < to; ++temp )
241 {
242 new_rates[ temp ] = S_.rate_;
243 }
244 }
245
246 // Send rate-neuron-event
248 rve.set_coeffarray( new_rates );
250
251 // Reset variables
252 std::vector< double >( buffer_size, 0.0 ).swap( B_.instant_rates_ );
253
254 return wfr_tol_exceeded;
255}
256
257
258template < class TNonlinearities >
259void
261{
262 const double weight = e.get_weight();
263
264 size_t i = 0;
265 std::vector< unsigned int >::iterator it = e.begin();
266 // The call to get_coeffvalue( it ) in this loop also advances the iterator it
267 while ( it != e.end() )
268 {
269 if ( P_.linear_summation_ )
270 {
271 B_.instant_rates_[ i ] += weight * e.get_coeffvalue( it );
272 }
273 else
274 {
275 B_.instant_rates_[ i ] += weight * nonlinearities_.input( e.get_coeffvalue( it ) );
276 }
277 ++i;
278 }
279}
280
281template < class TNonlinearities >
282void
284{
285 const double weight = e.get_weight();
286 const long delay = e.get_delay_steps() - kernel().connection_manager.get_min_delay();
287
288 size_t i = 0;
289 std::vector< unsigned int >::iterator it = e.begin();
290 // The call to get_coeffvalue( it ) in this loop also advances the iterator it
291 while ( it != e.end() )
292 {
293 if ( P_.linear_summation_ )
294 {
295 B_.delayed_rates_.add_value( delay + i, weight * e.get_coeffvalue( it ) );
296 }
297 else
298 {
299 B_.delayed_rates_.add_value( delay + i, weight * nonlinearities_.input( e.get_coeffvalue( it ) ) );
300 }
301 ++i;
302 }
303}
304
305template < class TNonlinearities >
306void
311
312} // namespace
313
314#endif /* #ifndef RATE_TRANSFORMER_NODE_IMPL_H */
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
A node which archives spike history for the purposes of spike-timing dependent plasticity (STDP)
Definition archiving_node.h:49
void clear_history()
Clear spike history.
Definition archiving_node.cpp:269
long get_min_delay() const
Return minimal connection delay, which is precomputed by update_delay_extrema_().
Definition connection_manager.h:728
Request data to be logged/logged data to be sent.
Definition event.h:636
void set_coeffarray(std::vector< DataType > &ca)
Definition secondary_event.h:224
Event for rate model connections with delay.
Definition secondary_event.h:331
void send_secondary(Node &source, SecondaryEvent &e)
Send a secondary event remote.
Definition event_delivery_manager_impl.h:138
Event for rate model connections without delay.
Definition secondary_event.h:315
Base class for all NEST network objects.
Definition node.h:99
void set_node_uses_wfr(const bool)
Sets node_uses_wfr_ member variable (to be able to set it to "true" for any class derived from Node)
Definition node.h:1158
double get_wfr_tol() const
Get the convergence tolerance of the waveform relaxation method.
Definition simulation_manager.h:331
Definition nest_time.h:135
Definition rate_transformer_node.h:104
rate_transformer_node()
Definition rate_transformer_node_impl.h:123
State_ S_
Definition rate_transformer_node.h:238
void init_buffers_() override
Configure persistent internal data structures.
Definition rate_transformer_node_impl.h:148
bool update_(Time const &, const long, const long, const bool)
Definition rate_transformer_node_impl.h:174
static RecordablesMap< rate_transformer_node< TNonlinearities > > recordablesMap_
Mapping of recordables names to access functions.
Definition rate_transformer_node.h:242
Buffers_ B_
Definition rate_transformer_node.h:239
void pre_run_hook() override
Re-calculate dependent parameters of the node.
Definition rate_transformer_node_impl.h:163
void handle(InstantaneousRateConnectionEvent &) override
Handler for rate neuron events.
Definition rate_transformer_node_impl.h:260
ConnectionManager connection_manager
Definition kernel_manager.h:239
EventDeliveryManager event_delivery_manager
Definition kernel_manager.h:241
SimulationManager simulation_manager
Definition kernel_manager.h:237
const std::string linear_summation("linear_summation")
const std::string rate("rate")
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
KernelManager & kernel()
Definition kernel_manager.h:311
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
Buffers of the model.
Definition rate_transformer_node.h:208
Buffers_(rate_transformer_node &)
Definition rate_transformer_node_impl.h:106
Parameters_()
Sets default parameter values.
Definition rate_transformer_node_impl.h:62
void get(Dictionary &) const
Store current values in dictionary.
Definition rate_transformer_node_impl.h:79
void set(const Dictionary &, Node *node)
Definition rate_transformer_node_impl.h:86
void get(Dictionary &) const
Definition rate_transformer_node_impl.h:93
State_()
Default initialization.
Definition rate_transformer_node_impl.h:68
void set(const Dictionary &, Node *node)
Set values from dictionary.
Definition rate_transformer_node_impl.h:100