sPyNNaker neural_modelling 7.1.1
Loading...
Searching...
No Matches
synapse_types_alpha_impl.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 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
22#ifndef _ALPHA_SYNAPSE_H_
23#define _ALPHA_SYNAPSE_H_
24
25//---------------------------------------
26// Macros
27//---------------------------------------
30#define SYNAPSE_TYPE_BITS 1
33#define SYNAPSE_TYPE_COUNT 2
34
36#define NUM_EXCITATORY_RECEPTORS 1
38#define NUM_INHIBITORY_RECEPTORS 1
39
40#include <neuron/decay.h>
41#include <debug.h>
42#include "synapse_types.h"
43
44//---------------------------------------
45// Synapse parameters
46//---------------------------------------
48typedef struct alpha_params_t {
49 input_t lin_init;
50 input_t exp_init;
51 input_t q_init;
52 REAL tau;
54
60
70
75
81
82//---------------------------------------
83// Synapse shaping inline implementation
84//---------------------------------------
85
86static inline void get_alpha_state(alpha_state_t *state, alpha_params_t *params,
87 REAL time_step_ms, uint32_t n_steps_per_timestep) {
88 REAL ts = kdivui(time_step_ms, n_steps_per_timestep);
89 decay_t decay = expulr(-kdivk(ts, params->tau));
90 decay_t init = kdivk(ts, (params->tau * params->tau));
91 state->lin_buff = params->lin_init;
92 state->exp_buff = params->exp_init;
93 state->q_buff = params->q_init;
94 state->dt_divided_by_tau_sqr = init;
95 state->decay = decay;
96}
97
98static inline void synapse_types_initialise(synapse_types_t *state,
100 get_alpha_state(&state->exc, &params->exc, params->time_step_ms, n_steps_per_timestep);
101 get_alpha_state(&state->inh, &params->inh, params->time_step_ms, n_steps_per_timestep);
102}
103
104static void synapse_types_save_state(synapse_types_t *state, synapse_types_params_t *params) {
105 params->exc.lin_init = state->exc.lin_buff;
106 params->exc.exp_init = state->exc.exp_buff;
107 params->exc.q_init = state->exc.q_buff;
108 params->inh.lin_init = state->inh.lin_buff;
109 params->inh.exp_init = state->inh.exp_buff;
110 params->inh.q_init = state->inh.q_buff;
111}
112
115static inline void alpha_shaping(alpha_state_t* a_params) {
116 a_params->lin_buff = a_params->lin_buff + (
117 a_params->q_buff * a_params->dt_divided_by_tau_sqr);
118
119 // Update exponential buffer
120 a_params->exp_buff = decay_s1615(a_params->exp_buff, a_params->decay);
121}
122
131static inline void synapse_types_shape_input(
132 synapse_types_t *parameters) {
133 alpha_shaping(&parameters->exc);
134 alpha_shaping(&parameters->inh);
135}
136
141static inline void add_input_alpha(alpha_state_t *a_params, input_t input) {
142 a_params->q_buff = input;
143
144 a_params->exp_buff =
145 decay_s1615(a_params->exp_buff, a_params->decay) + ONE;
146
147 a_params->lin_buff =
148 (a_params->lin_buff + (input * a_params->dt_divided_by_tau_sqr))
149 * (ONE - kdivk(ONE, a_params->exp_buff));
150}
151
161 index_t synapse_type_index, synapse_types_t *parameters,
162 input_t input) {
163 if (input > ZERO) {
164 switch (synapse_type_index) {
165 case EXCITATORY:
166 add_input_alpha(&parameters->exc, input);
167 break;
168 case INHIBITORY:
169 add_input_alpha(&parameters->inh, input);
170 break;
171 }
172 }
173}
174
181 input_t *excitatory_response, synapse_types_t *parameters) {
182 excitatory_response[0] =
183 parameters->exc.lin_buff * parameters->exc.exp_buff;
184 return &excitatory_response[0];
185}
186
193 input_t *inhibitory_response, synapse_types_t *parameters) {
194 inhibitory_response[0] =
195 parameters->inh.lin_buff * parameters->inh.exp_buff;
196 return &inhibitory_response[0];
197}
198
205static inline const char *synapse_types_get_type_char(
206 index_t synapse_type_index) {
207 switch (synapse_type_index) {
208 case EXCITATORY:
209 return "X";
210 case INHIBITORY:
211 return "I";
212 default:
213 log_debug("did not recognise synapse type %i", synapse_type_index);
214 return "?";
215 }
216}
217
222static inline void synapse_types_print_input(
223 synapse_types_t *parameters) {
224 io_printf(IO_BUF, "%12.6k - %12.6k",
225 parameters->exc.lin_buff * parameters->exc.exp_buff,
226 parameters->inh.lin_buff * parameters->inh.exp_buff);
227}
228
231static inline void synapse_types_print_parameters(synapse_types_t *parameters) {
232 log_debug("-------------------------------------\n");
233 log_debug("exc_response = %11.4k\n",
234 parameters->exc.lin_buff * parameters->exc.exp_buff);
235 log_debug("inh_response = %11.4k\n",
236 parameters->inh.lin_buff * parameters->inh.exp_buff);
237}
238
239#endif // _ALPHA_SYNAPSE_H_
uint32_t index_t
void log_debug(const char *message,...)
utility method for decaying a value by a given amount
#define decay(x, d)
This is a type-generic decay "function".
Definition decay.h:118
UFRACT decay_t
Definition decay.h:44
static s1615 decay_s1615(s1615 x, decay_t decay)
this method takes a s1615 and decays it by a given amount (denoted by the decay) (to compensate for t...
Definition decay.h:52
#define ONE
A REAL 1.0.
Definition maths-util.h:117
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 input_t
The type of an input.
static uint n_steps_per_timestep
The number of steps to run per timestep.
void io_printf(char *stream, char *format,...)
#define IO_BUF
static stdp_params params
Configuration parameters.
API for synaptic behaviour types (see also src/neuron/input_types)
static const char * synapse_types_get_type_char(index_t synapse_type_index)
returns a human readable character for the type of synapse.
static input_t * synapse_types_get_excitatory_input(input_t *excitatory_response, synapse_types_t *parameters)
extracts the excitatory input buffers from the buffers available for a given neuron ID
input_t lin_buff
buffer for linear term
input_t q_buff
Temporary value of input.
decay_t decay
Exponential decay multiplier.
synapse_alpha_input_buffer_regions
The supported synapse type indices.
@ INHIBITORY
Inhibitory synaptic input.
@ EXCITATORY
Excitatory synaptic input.
static void synapse_types_add_neuron_input(index_t synapse_type_index, synapse_types_t *parameters, input_t input)
adds the inputs for a give timer period to a given neuron that is being simulated by this model
static void alpha_shaping(alpha_state_t *a_params)
Applies alpha shaping to a parameter.
static void synapse_types_print_input(synapse_types_t *parameters)
prints the input for a neuron ID given the available inputs currently only executed when the models a...
static void synapse_types_print_parameters(synapse_types_t *parameters)
prints the parameters of the synapse type
static void add_input_alpha(alpha_state_t *a_params, input_t input)
helper function to add input for a given timer period to a given neuron
static void synapse_types_shape_input(synapse_types_t *parameters)
decays the stuff thats sitting in the input buffers as these have not yet been processed and applied ...
static input_t * synapse_types_get_inhibitory_input(input_t *inhibitory_response, synapse_types_t *parameters)
extracts the inhibitory input buffers from the buffers available for a given neuron ID
input_t dt_divided_by_tau_sqr
τ-1 pre-multiplied by dt
Parameters of an alpha synaptic input.
Internal structure of an alpha-shaped synaptic input.
alpha_state_t inh
Inhibitory synaptic input.
alpha_params_t exc
First excitatory synaptic input.
alpha_state_t exc
Excitatory synaptic input.
Delta synapses support just a single excitatory and inhibitory input each.