NEST  2.6.0,not_revisioned_source_dir@0
binary_neuron_impl.h
Go to the documentation of this file.
1 /*
2  * binary_neuron_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 BINARY_NEURON_IMPL_H
24 #define BINARY_NEURON_IMPL_H
25 
26 #include "exceptions.h"
27 #include "binary_neuron.h"
28 #include "network.h"
29 #include "dict.h"
30 #include "integerdatum.h"
31 #include "doubledatum.h"
32 #include "dictutils.h"
33 #include "numerics.h"
35 
36 #include <limits>
37 
38 
39 namespace nest
40 {
41 
42 template<typename TGainfunction>
43 RecordablesMap< nest::binary_neuron<TGainfunction> > nest::binary_neuron<TGainfunction>::recordablesMap_;
44 
45 /* ----------------------------------------------------------------
46  * Default constructors defining default parameters and state
47  * ---------------------------------------------------------------- */
48 
49 template<class TGainfunction>
51  : tau_m_ ( 10.0 ) // ms
52 {
53  recordablesMap_.create();
54 }
55 
56 template<class TGainfunction>
58  : y_(false),
59  h_ (0.0),
60  last_in_gid_(0),
61  t_next_(Time::neg_inf()), // mark as not initialized
62  t_last_in_spike_(Time::neg_inf()) // mark as not intialized
63 {}
64 
65 /* ----------------------------------------------------------------
66  * Parameter and state extractions and manipulation functions
67  * ---------------------------------------------------------------- */
68 
69 template<class TGainfunction>
71 {
72  def<double>(d, names::tau_m, tau_m_);
73 }
74 
75 template<class TGainfunction>
77 {
78  updateValue<double>(d, names::tau_m, tau_m_);
79 
80  if ( tau_m_ <= 0 )
81  throw BadProperty("All time constants must be strictly positive.");
82 }
83 
84 template<class TGainfunction>
86 {
87  def<double>(d, names::h, h_); // summed input
88  def<double>(d, names::S, y_); // binary_neuron output state
89 }
90 
91 template<class TGainfunction>
93 {}
94 
95 template<class TGainfunction>
97  : logger_(n)
98 {}
99 
100 template<class TGainfunction>
102  : logger_(n)
103 {}
104 
105 
106 /* ----------------------------------------------------------------
107  * Default and copy constructor for node
108  * ---------------------------------------------------------------- */
109 
110 template<class TGainfunction>
112  : Archiving_Node(),
113  P_(),
114  S_(),
115  B_(*this)
116 {}
117 
118 template<class TGainfunction>
120  : Archiving_Node(n),
121  gain_(n.gain_),
122  P_(n.P_),
123  S_(n.S_),
124  B_(*this)
125 {}
126 
127 /* ----------------------------------------------------------------
128  * Node initialization functions
129  * ---------------------------------------------------------------- */
130 
131 template<class TGainfunction>
133 {
134  const binary_neuron& pr = downcast<binary_neuron>(proto);
135  S_ = pr.S_;
136 }
137 
138 template<class TGainfunction>
140 {
141  B_.spikes_.clear(); // includes resize
142  B_.currents_.clear(); // includes resize
143  B_.logger_.reset();
145 }
146 
147 template<class TGainfunction>
149 {
150  B_.logger_.init(); // ensures initialization in case mm connected after Simulate
151  V_.rng_ = net_->get_rng(get_thread());
152 
153  // draw next time of update for the neuron from exponential distribution
154  // only if not yet initialized
155  if ( S_.t_next_.is_neg_inf() )
156  S_.t_next_ = Time::ms ( V_.exp_dev_(V_.rng_) * P_.tau_m_ );
157 }
158 
159 
160 /* ----------------------------------------------------------------
161  * Update and spike handling functions
162  */
163 
164 template<class TGainfunction>
166  const long_t from, const long_t to)
167 {
168  assert(to >= 0 && (delay) from < Scheduler::get_min_delay());
169  assert(from < to);
170 
171  for ( long_t lag = from ; lag < to ; ++lag )
172  {
173  // update the input current
174  // the buffer for incoming spikes for every time step contains the difference
175  // of the total input h with respect to the previous step, so sum them up
176  S_.h_ += B_.spikes_.get_value(lag);
177 
178  double_t c = B_.currents_.get_value(lag);
179 
180  // check, if the update needs to be done
181  if ( Time::step(origin.get_steps()+lag) > S_.t_next_ )
182  {
183  // change the state of the neuron with probability given by
184  // gain function
185  // if the state has changed, the neuron produces an event sent to all its targets
186 
187  bool new_y = gain_(V_.rng_, S_.h_ + c);
188 
189  if ( new_y != S_.y_ )
190  {
191  SpikeEvent se;
192  // use multiplicity 2 to signalize transition to 1 state
193  // use multiplicity 1 to signalize transition to 0 state
194  se.set_multiplicity(new_y ? 2 : 1);
195  network()->send(*this, se, lag);
196  S_.y_ = new_y;
197  }
198 
199  // draw next update interval from exponential distribution
200  S_.t_next_ += Time::ms ( V_.exp_dev_(V_.rng_) * P_.tau_m_ );
201 
202  } // of if (update now)
203 
204  // log state data
205  B_.logger_.record_data(origin.get_steps() + lag);
206 
207  } // of for (lag ...
208 
209 }
210 
211 template<class TGainfunction>
213 {
214  assert(e.get_delay() > 0);
215 
216  // The following logic implements the encoding:
217  // A single spike signals a transition to 0 state, two spikes in same time step
218  // signal the transition to 1 state.
219  //
220  // Remember the global id of the sender of the last spike being received
221  // this assumes that several spikes being sent by the same neuron in the same time step
222  // are received consecutively or are conveyed by setting the multiplicity accordingly.
223 
224  long_t m = e.get_multiplicity();
225  long_t gid = e.get_sender_gid();
226  const Time &t_spike = e.get_stamp();
227 
228  if (m == 1)
229  { //multiplicity == 1, either a single 1->0 event or the first or second of a pair of 0->1 events
230  if (gid == S_.last_in_gid_ && t_spike == S_.t_last_in_spike_)
231  {
232  // received twice the same gid, so transition 0->1
233  // take double weight to compensate for subtracting first event
234  B_.spikes_.add_value(e.get_rel_delivery_steps(network()->get_slice_origin()),
235  2.0*e.get_weight());
236  }
237  else
238  {
239  // count this event negatively, assuming it comes as single event
240  // transition 1->0
241  B_.spikes_.add_value(e.get_rel_delivery_steps(network()->get_slice_origin()),
242  -e.get_weight());
243  }
244  }
245  else // multiplicity != 1
246  if (m == 2)
247  {
248  // count this event positively, transition 0->1
249  B_.spikes_.add_value(e.get_rel_delivery_steps(network()->get_slice_origin()),
250  e.get_weight());
251  }
252 
253  S_.last_in_gid_ = gid;
254  S_.t_last_in_spike_ = t_spike;
255 }
256 
257 template<class TGainfunction>
259 {
260  assert(e.get_delay() > 0);
261 
262  const double_t c=e.get_current();
263  const double_t w=e.get_weight();
264 
265  // we use the spike buffer to receive the binary events
266  // but also to handle the incoming current events added
267  // both contributions are directly added to the variable h
268  B_.currents_.add_value(e.get_rel_delivery_steps(network()->get_slice_origin()),
269  w*c);
270 
271 }
272 
273 
274 template<class TGainfunction>
276 {
277  B_.logger_.handle(e);
278 }
279 
280 
281 } // namespace
282 
283 #endif /* #ifndef BINARY_NEURON_IMPL_H */
Binary stochastic neuron with linear or sigmoidal gain function.
Definition: binary_neuron.h:48
const Name d("d")
Specific to Izhikevich 2003.
Definition: nest_names.h:83
State_()
Default initialization.
Definition: binary_neuron_impl.h:57
State_ S_
Definition: binary_neuron.h:171
Definition: nest_time.h:230
delay get_steps() const
Definition: nest_time.h:395
void handle(SpikeEvent &)
Handle incoming spike events.
Definition: binary_neuron_impl.h:212
Event for electrical currents.
Definition: event.h:420
static delay get_min_delay()
Return minimal connection delay.
Definition: scheduler.h:805
assert(pNet!=0)
void clear_history()
clear spike history
Definition: archiving_node.cpp:206
Parameters_ P_
Definition: binary_neuron.h:170
const Name h("h")
Summed input to a neuron (Ginzburg neuron)
Definition: nest_names.h:158
Definition: nest_time.h:235
const Name w("w")
Specific to Brette & Gerstner 2005 (aeif_cond-*)
Definition: nest_names.h:343
index get_sender_gid() const
Return GID of sending Node.
Definition: event.h:738
int_t get_multiplicity() const
Definition: event.h:352
Definition: nest_time.h:130
const Name tau_m("tau_m")
Membrane time constant.
Definition: nest_names.h:292
long_t get_rel_delivery_steps(const Time &t) const
Relative spike delivery time in steps.
Definition: event.h:775
const Name S("S")
Binary state (output) of neuron (Ginzburg neuron)
Definition: nest_names.h:255
Time const & get_stamp() const
Return time stamp of the event.
Definition: event.h:757
Declarations for class Network.
void set_multiplicity(int_t)
Definition: event.h:346
Independent parameters of the model.
Definition: binary_neuron.h:97
weight get_weight() const
Return the weight.
Definition: event.h:745
const Name origin("origin")
Device parameters.
Definition: nest_names.h:215
void init_state_(const Node &proto)
Private function to initialize the state of a node to model defaults.
Definition: binary_neuron_impl.h:132
Exception to be thrown if a status parameter is incomplete or inconsistent.
Definition: exceptions.h:420
a node which archives spike history for the purposes of timing dependent plasticity ...
Definition: archiving_node.h:50
double double_t
Double precision floating point numbers.
Definition: nest.h:93
Request data to be logged/logged data to be sent.
Definition: event.h:486
friend struct ms
Definition: nest_time.h:173
Buffers_(binary_neuron &)
Definition: binary_neuron_impl.h:96
static RecordablesMap< binary_neuron< TGainfunction > > recordablesMap_
Mapping of recordables names to access functions.
Definition: binary_neuron.h:177
Buffers of the model.
Definition: binary_neuron.h:130
const Name n("n")
Number of synaptic release sites (int >=0) (Tsodyks2_connection)
Definition: nest_names.h:202
binary_neuron()
Definition: binary_neuron_impl.h:111
long_t delay
Delay of a connection.
Definition: nest.h:178
Event for spike information.
Definition: event.h:320
void init_buffers_()
Private function to initialize the buffers of a node.
Definition: binary_neuron_impl.h:139
Base class for all NEST network objects.
Definition: node.h:96
void get(DictionaryDatum &, const Parameters_ &) const
Definition: binary_neuron_impl.h:85
void set(const DictionaryDatum &, const Parameters_ &)
Definition: binary_neuron_impl.h:92
const Name c("c")
Specific to Izhikevich 2003.
Definition: nest_names.h:62
long long_t
Integer number with at least 32 bit.
Definition: nest.h:96
Parameters_()
Sets default parameter values.
Definition: binary_neuron_impl.h:50
const double e
Definition: numerics.cpp:62
void set(const DictionaryDatum &)
Set values from dicitonary.
Definition: binary_neuron_impl.h:76
void update(Time const &, const long_t, const long_t)
Bring the node from state $t$ to $t+n*dt$.
Definition: binary_neuron_impl.h:165
void get(DictionaryDatum &) const
Store current values in dictionary.
Definition: binary_neuron_impl.h:70
void calibrate()
Re-calculate dependent parameters of the node.
Definition: binary_neuron_impl.h:148
double_t get_current() const
Definition: event.h:444
Buffers_ B_
Definition: binary_neuron.h:173
const Name t_spike("t_spike")
Time of last spike.
Definition: nest_names.h:281
delay get_delay() const
Return transmission delay of the event.
Definition: event.h:769