sPyNNaker neural_modelling  development
neuron_model_if_trunc.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 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_IF_TRUNC_H_
20 #define _NEURON_MODEL_IF_TRUNC_H_
21 
22 #include "neuron_model.h"
23 
25 struct neuron_params_t {
28 
31 
34 
37 
40 
43 
46 
49 };
50 
51 
53 struct neuron_t {
56 
59 
62 
64  int32_t refract_timer;
65 
68 
70  int32_t T_refract;
71 };
72 
76 static inline int32_t lif_ceil_accum(REAL value) {
77  int32_t bits = bitsk(value);
78  int32_t integer = bits >> 15;
79  int32_t fraction = bits & 0x7FFF;
80  if (fraction > 0) {
81  return integer + 1;
82  }
83  return integer;
84 }
85 
86 static inline void neuron_model_initialise(
88  REAL ts = kdivui(params->time_step, n_steps_per_timestep);
89  state->V_membrane = params->V_init;
90  state->R_membrane = kdivk(params->tau_m, params->c_m);
91  state->I_offset = params->I_offset;
92  state->refract_timer = params->refract_timer_init;
93  state->V_reset = params->V_reset;
94  state->T_refract = lif_ceil_accum(kdivk(params->T_refract_ms, ts));
95 }
96 
97 static inline void neuron_model_save_state(neuron_t *state, neuron_params_t *params) {
98  params->V_init = state->V_membrane;
99  params->refract_timer_init = state->refract_timer;
100 }
101 
118  uint16_t num_excitatory_inputs, const input_t *exc_input,
119  uint16_t num_inhibitory_inputs, const input_t *inh_input,
120  input_t external_bias, REAL current_offset, neuron_t *restrict neuron) {
121 
122  // If outside of the refractory period
123  if (neuron->refract_timer <= 0) {
124  REAL total_exc = ZERO;
125  REAL total_inh = ZERO;
126 
127  for (int i=0; i < num_excitatory_inputs; i++) {
128  total_exc += exc_input[i];
129  }
130  for (int i=0; i< num_inhibitory_inputs; i++) {
131  total_inh += inh_input[i];
132  }
133  // Get the input in nA
135  total_exc - total_inh + external_bias + neuron->I_offset + current_offset;
136 
137  // Simply add on the input scaled by the resistance
138  neuron->V_membrane = (input_this_timestep * neuron->R_membrane) + neuron->V_membrane;
139 
140  // Disallow the membrane going below the reset voltage for simplicity
141  if (neuron->V_membrane < neuron->V_reset) {
142  neuron->V_membrane = neuron->V_reset;
143  }
144  } else {
145  // countdown refractory timer
146  neuron->refract_timer--;
147  }
148  return neuron->V_membrane;
149 }
150 
154 static inline void neuron_model_has_spiked(neuron_t *restrict neuron) {
155  // reset membrane voltage
156  neuron->V_membrane = neuron->V_reset;
157 
158  // reset refractory timer
159  neuron->refract_timer = neuron->T_refract;
160 }
161 
167 static inline state_t neuron_model_get_membrane_voltage(const neuron_t *neuron) {
168  return neuron->V_membrane;
169 }
170 
171 static inline void neuron_model_print_state_variables(const neuron_t *neuron) {
172  log_info("V membrane = %11.4k mv", neuron->V_membrane);
173  log_info("Refract timer = %u timesteps", neuron->refract_timer);
174 }
175 
176 static inline void neuron_model_print_parameters(const neuron_t *neuron) {
177  log_info("V reset = %11.4k mv", neuron->V_reset);
178 
179  log_info("I offset = %11.4k nA", neuron->I_offset);
180  log_info("R membrane = %11.4k Mohm", neuron->R_membrane);
181 
182  log_info("T refract = %u timesteps", neuron->T_refract);
183 }
184 
185 
186 #endif //_NEURON_MODEL_IF_TRUNC_H_
accum REAL
Type used for "real" numbers.
Definition: maths-util.h:91
static REAL kdivk(REAL a, REAL b)
Divides an accum by another accum.
Definition: maths-util.h:234
static REAL kdivui(REAL a, uint32_t b)
Divides an accum by an unsigned integer.
Definition: maths-util.h:258
#define ZERO
A REAL 0.0.
Definition: maths-util.h:123
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.
static void neuron_model_print_state_variables(const neuron_t *neuron)
printout of state variables i.e. those values that might change
static void neuron_model_initialise(neuron_t *state, neuron_params_t *params, uint32_t n_steps_per_timestep)
initialise the structure from the parameters
static void neuron_model_save_state(neuron_t *state, neuron_params_t *params)
save parameters and state back to SDRAM for reading by host and recovery on restart
static void neuron_model_print_parameters(const neuron_t *neuron)
printout of parameters i.e. those values that don't change
static state_t neuron_model_get_membrane_voltage(const neuron_t *neuron)
get the neuron membrane voltage for a given neuron parameter set
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
static void neuron_model_has_spiked(neuron_t *restrict neuron)
Indicates that the neuron has spiked.
static int32_t lif_ceil_accum(REAL value)
Performs a ceil operation on an accum.
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 I_offset
offset current [nA]
int32_t T_refract
refractory time of neuron [timesteps]
REAL time_step
The time step in milliseconds.
REAL R_membrane
membrane resistance [MOhm]
int32_t refract_timer_init
initial refractory timer value (saved)
REAL tau_m
membrane decay time constant
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.
static stdp_params params
Configuration parameters.