From 36249ebf394422d7f86559ecba51944e2c0b88b4 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sat, 22 Jul 2023 19:24:00 +0200 Subject: [PATCH] small reorg, comment purpose of functions --- squiggle.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/squiggle.c b/squiggle.c index a718e0d..6887c2f 100644 --- a/squiggle.c +++ b/squiggle.c @@ -28,6 +28,7 @@ uint32_t xorshift32(uint32_t* seed) } // Distribution & sampling functions +// Unit distributions float sample_unit_uniform(uint32_t* seed) { // samples uniform from [0,1] interval. @@ -43,11 +44,13 @@ float sample_unit_normal(uint32_t* seed) return z; } +// Composite distributions float sample_uniform(float from, float to, uint32_t* seed) { return sample_unit_uniform(seed) * (to - from) + from; } + float sample_normal(float mean, float sigma, uint32_t* seed) { return (mean + sigma * sample_unit_normal(seed)); @@ -60,6 +63,9 @@ float sample_lognormal(float logmean, float logsigma, uint32_t* seed) float sample_to(float low, float high, uint32_t* seed) { + // Given a (positive) 90% confidence interval, + // returns a sample from a lognormal + // with a matching 90% c.i. const float NORMAL95CONFIDENCE = 1.6448536269514722; float loglow = logf(low); float loghigh = logf(high);