sPyNNaker neural_modelling 7.1.1
Loading...
Searching...
No Matches
neuron_model_lif_impl.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 The University of Manchester
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
19#ifndef _NEURON_MODEL_LIF_CURR_IMPL_H_
20#define _NEURON_MODEL_LIF_CURR_IMPL_H_
21
22#include "neuron_model.h"
23
25struct neuron_params_t {
28
31
33 REAL c_m;
34
36 REAL tau_m;
37
40
43
46
48 int32_t refract_timer_init;
49
52};
53
54
56struct neuron_t {
59
62
65
70
73
75 int32_t refract_timer;
76
79
81 int32_t T_refract;
82};
83
87static inline int32_t lif_ceil_accum(REAL value) {
88 int32_t bits = bitsk(value);
89 int32_t integer = bits >> 15;
90 int32_t fraction = bits & 0x7FFF;
91 if (fraction > 0) {
92 return integer + 1;
93 }
94 return integer;
95}
96
97static inline void neuron_model_initialise(
99 REAL ts = kdivui(params->time_step, n_steps_per_timestep);
100 state->V_membrane = params->V_init;
101 state->V_rest = params->V_rest;
102 state->R_membrane = kdivk(params->tau_m, params->c_m);
103 state->exp_TC = expk(-kdivk(ts, params->tau_m));
104 state->I_offset = params->I_offset;
105 state->refract_timer = params->refract_timer_init;
106 state->V_reset = params->V_reset;
107 state->T_refract = lif_ceil_accum(kdivk(params->T_refract_ms, ts));
108}
109
110static inline void neuron_model_save_state(neuron_t *state, neuron_params_t *params) {
111 params->V_init = state->V_membrane;
112 params->refract_timer_init = state->refract_timer;
113}
114
119static inline void lif_neuron_closed_form(
120 neuron_t *neuron, REAL V_prev, input_t input_this_timestep) {
121 REAL alpha = input_this_timestep * neuron->R_membrane + neuron->V_rest;
122
123 // update membrane voltage
124 neuron->V_membrane = alpha - (neuron->exp_TC * (alpha - V_prev));
125}
126
143 uint16_t num_excitatory_inputs, const input_t *exc_input,
144 uint16_t num_inhibitory_inputs, const input_t *inh_input,
145 input_t external_bias, REAL current_offset, neuron_t *restrict neuron) {
146
147 // If outside of the refractory period
148 if (neuron->refract_timer <= 0) {
149 REAL total_exc = ZERO;
150 REAL total_inh = ZERO;
151
152 for (int i=0; i < num_excitatory_inputs; i++) {
153 total_exc += exc_input[i];
154 }
155 for (int i=0; i< num_inhibitory_inputs; i++) {
156 total_inh += inh_input[i];
157 }
158 // Get the input in nA
160 total_exc - total_inh + external_bias + neuron->I_offset + current_offset;
161
163 neuron, neuron->V_membrane, input_this_timestep);
164 } else {
165 // countdown refractory timer
166 neuron->refract_timer--;
167 }
168 return neuron->V_membrane;
169}
170
174static inline void neuron_model_has_spiked(neuron_t *restrict neuron) {
175 // reset membrane voltage
176 neuron->V_membrane = neuron->V_reset;
177
178 // reset refractory timer
179 neuron->refract_timer = neuron->T_refract;
180}
181
188 return neuron->V_membrane;
189}
190
191static inline void neuron_model_print_state_variables(const neuron_t *neuron) {
192 log_info("V membrane = %11.4k mv", neuron->V_membrane);
193 log_info("Refract timer = %u timesteps", neuron->refract_timer);
194}
195
196static inline void neuron_model_print_parameters(const neuron_t *neuron) {
197 log_info("V reset = %11.4k mv", neuron->V_reset);
198 log_info("V rest = %11.4k mv", neuron->V_rest);
199
200 log_info("I offset = %11.4k nA", neuron->I_offset);
201 log_info("R membrane = %11.4k Mohm", neuron->R_membrane);
202
203 log_info("exp(-ms/(RC)) = %11.4k [.]", neuron->exp_TC);
204
205 log_info("T refract = %u timesteps", neuron->T_refract);
206}
207
208
209#endif // _NEURON_MODEL_LIF_CURR_IMPL_H_
void log_info(const char *message,...)
accum REAL
Type used for "real" numbers.
Definition maths-util.h:89
static REAL kdivk(REAL a, REAL b)
Divides an accum by another accum.
Definition maths-util.h:222
static REAL kdivui(REAL a, uint32_t b)
Divides an accum by an unsigned integer.
Definition maths-util.h:246
#define ZERO
A REAL 0.0.
Definition maths-util.h:121
REAL state_t
The type of a state variable.
REAL input_t
The type of an input.
static uint n_steps_per_timestep
The number of steps to run per timestep.
The API for neuron models themselves.
REAL V_init
membrane voltage [mV]
REAL V_reset
post-spike reset membrane voltage [mV]
REAL c_m
membrane capacitance [nF]
REAL V_reset
post-spike reset membrane voltage [mV]
REAL T_refract_ms
refractory time of neuron [ms]
REAL V_rest
membrane resting voltage [mV]
static state_t neuron_model_get_membrane_voltage(const neuron_t *neuron)
get the neuron membrane voltage for a given neuron parameter set
REAL V_rest
membrane resting voltage [mV]
REAL I_offset
offset current [nA]
int32_t T_refract
refractory time of neuron [timesteps]
static state_t neuron_model_state_update(uint16_t num_excitatory_inputs, const input_t *exc_input, uint16_t num_inhibitory_inputs, const input_t *inh_input, input_t external_bias, REAL current_offset, neuron_t *restrict neuron)
primary function called in timer loop after synaptic updates
UREAL time_step
The timestep of the neuron being used.
static void neuron_model_has_spiked(neuron_t *restrict neuron)
Indicates that the neuron has spiked.
REAL R_membrane
membrane resistance [MOhm]
static int32_t lif_ceil_accum(REAL value)
Performs a ceil operation on an accum.
int32_t refract_timer_init
initial refractory timer value (saved)
REAL tau_m
membrane decay time constant
static void lif_neuron_closed_form(neuron_t *neuron, REAL V_prev, input_t input_this_timestep)
simple Leaky I&F ODE
REAL V_membrane
membrane voltage [mV]
REAL I_offset
offset current [nA]
int32_t refract_timer
countdown to end of next refractory period [timesteps]
definition of neuron parameters
definition for LIF neuron state
static uint16_t * input_this_timestep
The inputs to be sent at the end of this timestep.
s1615 expk(s1615 x)
static stdp_params params
Configuration parameters.