sPyNNaker neural_modelling 7.1.1
Loading...
Searching...
No Matches
param_generator_exponential_clipped.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 <random.h>
27
31#define MAX_REDRAWS 1000
32
37 accum beta;
38 accum low;
39 accum high;
41
49
57 // Allocate memory for the data
59 spin1_malloc(sizeof(struct param_generator_exponential_clipped));
60
61 // Copy the parameters in
63 params->params = *params_sdram;
64 *region = &params_sdram[1];
65 log_debug("exponential clipped beta = %k, low = %k, high = %k",
66 params->params.beta, params->params.low, params->params.high);
67
68 return params;
69}
70
75static void param_generator_exponential_clipped_free(void *generator) {
76 sark_free(generator);
77}
78
84static accum param_generator_exponential_clipped_generate(void *generator) {
85 // generate an exponentially distributed value
86 struct param_generator_exponential_clipped *obj = generator;
87 uint32_t n_draws = 0;
88 accum value = 0k;
89 do {
90 value = rng_normal(core_rng);
91 value = value * obj->params.beta;
92 n_draws++;
93 } while ((value < obj->params.low || value > obj->params.high)
94 && (n_draws < MAX_REDRAWS));
95 if (n_draws == MAX_REDRAWS) {
96 log_error("Maximum number of redraws (%u) exceeded on clipped exponential "
97 "distribution with beta=%k, low=%k, high=%k",
98 n_draws, obj->params.beta, obj->params.low, obj->params.high);
100 }
101 return value;
102}
void log_error(const char *message,...)
void log_debug(const char *message,...)
General types associated with generators.
rng_t * core_rng
An RNG that is local to the current core.
#define MAX_REDRAWS
The maximum number of redraws performed before giving up.
static accum param_generator_exponential_clipped_generate(void *generator)
How to generate values with the exponential RNG parameter generator.
static void * param_generator_exponential_clipped_initialize(void **region)
How to initialise the exponential RNG parameter generator.
static void param_generator_exponential_clipped_free(void *generator)
How to free any data for the exponential RNG parameter generator.
The data structure to be passed around for this generator. This includes the parameters and an RNG.
The parameters that can be copied in from SDRAM.
accum rng_normal(rng_t *rng)
Generate an normally-distributed random number.
Definition rng.c:34
Random number generator interface.
RTE_SWERR
void sark_free(void *ptr)
void rt_error(uint code,...)
region
spike source array region IDs in human readable form
static stdp_params params
Configuration parameters.