sPyNNaker neural_modelling  7.4.2
param_generator_normal.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 #include <stdfix.h>
22 #include <spin1_api.h>
23 #include <stdfix-full-iso.h>
24 #include <normal.h>
25 #include <synapse_expander/rng.h>
27 
31 struct normal_params {
32  accum mu;
33  accum sigma;
34 };
35 
41  struct normal_params params;
42 };
43 
51  // Allocate memory for the data
52  struct param_generator_normal *obj =
53  spin1_malloc(sizeof(struct param_generator_normal));
54  struct normal_params *params_sdram = *region;
55 
56  // Copy the parameters in
57  obj->params = *params_sdram;
58  *region = &params_sdram[1];
59 
60  log_debug("normal mu = %k, sigma = %k",
61  obj->params.mu, obj->params.sigma);
62  return obj;
63 }
64 
69 static void param_generator_normal_free(void *generator) {
70  sark_free(generator);
71 }
72 
78 static accum param_generator_normal_generate(void *generator) {
79  // For each index, generate a normally distributed random value
80  struct param_generator_normal *obj = generator;
81  return (rng_normal(core_rng) * obj->params.sigma) + obj->params.mu;
82 }
General types associated with generators.
rng_t * core_rng
An RNG that is local to the current core.
static void param_generator_normal_free(void *generator)
How to free any data for the normal RNG parameter generator.
static accum param_generator_normal_generate(void *generator)
How to generate values with the normal RNG parameter generator.
static void * param_generator_normal_initialize(void **region)
How to initialise the normal RNG parameter generator.
The parameters that can be copied in from SDRAM.
The data structure to be passed around for this generator. This includes the parameters and an RNG.
accum rng_normal(rng_t *rng)
Generate an normally-distributed random number.
Definition: rng.c:34
Random number generator interface.
region
spike source array region IDs in human readable form
static stdp_params params
Configuration parameters.