sPyNNaker neural_modelling 7.3.1
Loading...
Searching...
No Matches
formation_distance_dependent_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
19#ifndef _FORMATION_DISTANCE_DEPENDENT_H_
20#define _FORMATION_DISTANCE_DEPENDENT_H_
21
22#include "formation.h"
23
25#define MAX_SHORT 65535
26
41 uint32_t grid_x;
43 uint32_t grid_y;
45 unsigned long fract grid_x_recip;
47 unsigned long fract grid_y_recip;
49 uint32_t ff_prob_size;
51 uint32_t lat_prob_size;
53 uint16_t prob_tables[];
54};
55
59static int my_abs(int a) {
60 return a < 0 ? -a : a;
61}
62
72 current_state_t *current_state, const formation_params_t *params,
73 UNUSED uint32_t time, synaptic_row_t row) {
74 // Compute distances
75 // To do this I need to take the DIV and MOD of the
76 // post-synaptic neuron ID, of the pre-synaptic neuron ID
77 // Compute the distance of these 2 measures
78 uint32_t pre_x, pre_y, post_x, post_y;
79 // Pre computation requires querying the table with global information
80 uint32_t pre_global_id = current_state->key_atom_info->lo_atom +
81 current_state->pre_syn_id;
82 uint32_t post_global_id = current_state->post_syn_id +
83 current_state->post_low_atom;
84
85 if (params->grid_x > 1) {
86 pre_x = muliulr(pre_global_id, params->grid_x_recip);
87 post_x = muliulr(post_global_id, params->grid_x_recip);
88 } else {
89 pre_x = 0;
90 post_x = 0;
91 }
92
93 if (params->grid_y > 1) {
94 uint32_t pre_y_div = muliulr(pre_global_id, params->grid_y_recip);
95 uint32_t post_y_div = muliulr(post_global_id, params->grid_y_recip);
96 pre_y = pre_global_id - (pre_y_div * params->grid_y);
97 post_y = post_global_id - (post_y_div * params->grid_y);
98 } else {
99 pre_y = 0;
100 post_y = 0;
101 }
102
103 // With periodic boundary conditions
104 uint32_t delta_x, delta_y;
105 delta_x = my_abs(pre_x - post_x);
106 delta_y = my_abs(pre_y - post_y);
107
108 if (delta_x > params->grid_x >> 1 && params->grid_x > 1) {
109 delta_x -= params->grid_x;
110 }
111
112 if (delta_y > params->grid_y >> 1 && params->grid_y > 1) {
113 delta_y -= params->grid_y;
114 }
115
116 uint32_t distance = delta_x * delta_x + delta_y * delta_y;
117
118 // Distance based probability extracted from the appropriate LUT
119 uint16_t probability;
120 int16_t controls = current_state->pre_population_info->sp_control;
121 if (!(controls & IS_CONNECTION_LAT)) {
122 if (distance >= params->ff_prob_size) {
123 return false;
124 }
125 probability = params->prob_tables[distance];
126 } else {
127 if (distance >= params->lat_prob_size) {
128 return false;
129 }
130 probability = params->prob_tables[params->ff_prob_size + distance];
131 }
132 uint32_t r = rand_int(MAX_SHORT, *(current_state->local_seed));
133 if (r > probability) {
134 return false;
135 }
136
137 return sp_structs_add_synapse(current_state, row);
138}
139
140#endif // _FORMATION_DISTANCE_DEPENDENT_H_
API for synapse formation.
uint32_t grid_y
Size of grid containing neurons, Y-dimension.
unsigned long fract grid_x_recip
Reciprocal of grid_x.
#define MAX_SHORT
Largest value in a uint16_t
static bool synaptogenesis_formation_rule(current_state_t *current_state, const formation_params_t *params, uint32_t time, synaptic_row_t row)
Formation rule for synaptogenesis; picks what neuron in the current population will have a synapse ad...
uint32_t grid_x
Size of grid containing neurons, X-dimension.
unsigned long fract grid_y_recip
Reciprocal of grid_y.
uint16_t prob_tables[]
Concatenated probability tables; first the FF table, then the LAT table.
uint32_t ff_prob_size
Size of FF probability table.
static int my_abs(int a)
abs function
uint32_t lat_prob_size
Size of LAT probability table.
Configuration of synapse formation rule.
struct synaptic_row * synaptic_row_t
The type of a synaptic row.
static bool sp_structs_add_synapse(current_state_t *restrict current_state, synaptic_row_t restrict row)
Adds a synapse to the relevant structures.
Definition sp_structs.h:210
uint32_t post_low_atom
Low atom copied from rewiring data.
Definition sp_structs.h:96
#define IS_CONNECTION_LAT
Flag: Is connection lateral?
Definition sp_structs.h:34
mars_kiss64_seed_t * local_seed
Seed referenced from rewiring data.
Definition sp_structs.h:94
static uint32_t rand_int(uint32_t max, mars_kiss64_seed_t seed)
Definition sp_structs.h:123
struct representing the current state of rewiring
Definition sp_structs.h:92
static stdp_params params
Configuration parameters.