sPyNNaker neural_modelling 7.3.1
Loading...
Searching...
No Matches
param_generator_normal_clipped_to_boundary.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#include <stdfix.h>
23#include <spin1_api.h>
24#include <stdfix-full-iso.h>
25#include <normal.h>
28
33 accum mu;
34 accum sigma;
35 accum low;
36 accum high;
37};
38
46
54 // Allocate memory for the data
56 spin1_malloc(sizeof(struct param_generator_normal_clipped_boundary));
57 struct normal_clipped_boundary_params *params_sdram = *region;
58
59 // Copy the parameters in
60 obj->params = *params_sdram;
61 *region = &params_sdram[1];
62
63 log_debug("normal clipped to boundary mu = %k, sigma = %k, low = %k, high = %k",
64 obj->params.mu, obj->params.sigma, obj->params.low, obj->params.high);
65
66 return obj;
67}
68
74 sark_free(generator);
75}
76
83 // Generate a normally distributed value, clipping
84 // it to the given boundary
85 struct param_generator_normal_clipped_boundary *obj = generator;
86 accum value = rng_normal(core_rng);
87 value = obj->params.mu + (value * obj->params.sigma);
88 if (value < obj->params.low) {
89 return obj->params.low;
90 }
91 if (value > obj->params.high) {
92 return obj->params.high;
93 }
94 return value;
95}
void log_debug(const char *message,...)
General types associated with generators.
rng_t * core_rng
An RNG that is local to the current core.
static void * param_generator_normal_clipped_boundary_initialize(void **region)
How to initialise the clamped normal RNG parameter generator.
static void param_generator_normal_clipped_boundary_free(void *generator)
How to free any data for the clamped normal RNG parameter generator.
static accum param_generator_normal_clipped_boundary_generate(void *generator)
How to generate values with the clamped 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.
void sark_free(void *ptr)
region
spike source array region IDs in human readable form
static stdp_params params
Configuration parameters.