sPyNNaker neural_modelling  7.4.2
current_source_noisy.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 
21 #ifndef _CURRENT_SOURCE_NOISY_H_
22 #define _CURRENT_SOURCE_NOISY_H_
23 
24 #include <random.h>
25 #include <normal.h>
26 
27 // Structures for different current sources in this impl
28 typedef struct noisy_current_source_t {
29  REAL mean;
30  REAL stdev;
31  uint32_t start;
32  uint32_t stop;
33  uint32_t dt;
34  mars_kiss64_seed_t seed;
36 
37 static noisy_current_source_t **noisy_source;
38 
39 static bool current_source_noisy_init(uint32_t n_noisy_sources, uint32_t *next) {
40  noisy_source = spin1_malloc(n_noisy_sources * sizeof(uint32_t*));
41  for (uint32_t n_noisy=0; n_noisy < n_noisy_sources; n_noisy++) {
42  noisy_source[n_noisy] = spin1_malloc(sizeof(noisy_current_source_t));
43  if (noisy_source[n_noisy] == NULL) {
44  log_error("Unable to allocate DC source parameters - out of DTCM");
45  return false;
46  }
47  *next += sizeof(noisy_current_source_t) / 4;
48  }
49  return true;
50 }
51 
52 static bool current_source_noisy_load_parameters(
53  address_t cs_address, uint32_t n_noisy_sources, uint32_t *next) {
54  for (uint32_t n_noisy=0; n_noisy < n_noisy_sources; n_noisy++) {
55  spin1_memcpy(noisy_source[n_noisy], &cs_address[*next], sizeof(noisy_current_source_t));
56  *next += sizeof(noisy_current_source_t) / 4;
57  }
58  return true;
59 }
60 
61 static REAL current_source_noisy_get_offset(uint32_t cs_index, uint32_t time) {
62  if ((time >= noisy_source[cs_index]->start) && (time < noisy_source[cs_index]->stop)) {
63  // Pick a normally-distributed value based on the mean and SD provided
64  REAL random_value = norminv_urt(mars_kiss64_seed(noisy_source[cs_index]->seed));
65  REAL noisy_current_offset = noisy_source[cs_index]->mean + (
66  noisy_source[cs_index]->stdev * random_value);
67  return noisy_current_offset;
68  }
69  return ZERO;
70 }
71 
72 #endif // _CURRENT_SOURCE_NOISY_H_
static uint32_t time
Simulation time.
accum REAL
Type used for "real" numbers.
Definition: maths-util.h:91
#define ZERO
A REAL 0.0.
Definition: maths-util.h:123
static mars_kiss64_seed_t seed
YUCK copy and pasted RNG to allow inlining and also to avoid horrific executable bloat.
Definition: random_util.h:31