time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

commit 3b29ad7e4534fa397136204d41c2823bd9f96df4
parent 39652b3bfe328e1cd41cdcef523ed21716c2d01a
Author: NunoSempere <nuno.sempere@protonmail.com>
Date:   Mon, 26 Jun 2023 18:44:04 +0100

more work on squiggle_c

Diffstat:
MC/C-01-simple/samples | 0
DC/squiggle_c/example_simple/example.c | 62--------------------------------------------------------------
RC/squiggle_c/example_simple/example -> C/squiggle_c/examples/01_one_sample/example | 0
AC/squiggle_c/examples/01_one_sample/example.c | 50++++++++++++++++++++++++++++++++++++++++++++++++++
RC/squiggle_c/example_simple/makefile -> C/squiggle_c/examples/01_one_sample/makefile | 0
RC/squiggle_c/example_simple/example -> C/squiggle_c/examples/02_many_samples/example | 0
AC/squiggle_c/examples/02_many_samples/example.c | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
RC/squiggle_c/example_simple/makefile -> C/squiggle_c/examples/02_many_samples/makefile | 0
8 files changed, 109 insertions(+), 62 deletions(-)

diff --git a/C/C-01-simple/samples b/C/C-01-simple/samples Binary files differ. diff --git a/C/squiggle_c/example_simple/example.c b/C/squiggle_c/example_simple/example.c @@ -1,62 +0,0 @@ -#include "../squiggle.h" -#include <stdint.h> -#include <stdlib.h> -#include <stdio.h> - -// Estimate functions -float sample_0(uint32_t* seed) -{ - return 0; -} - -float sample_1(uint32_t* seed) -{ - return 1; -} - -float sample_few(uint32_t* seed) -{ - return random_to(1, 3, seed); -} - -float sample_many(uint32_t* seed) -{ - return random_to(2, 10, seed); -} - -int main(){ - // set randomness seed - uint32_t* seed = malloc(sizeof(uint32_t)); - *seed = 1000; // xorshift can't start with 0 - - float p_a = 0.8; - float p_b = 0.5; - float p_c = p_a * p_b; - - int n_dists = 4; - float weights[] = { 1 - p_c, p_c / 2, p_c / 4, p_c / 4 }; - float (*samplers[])(uint32_t*) = { sample_0, sample_1, sample_few, sample_many }; - - float result_one = mixture(samplers, weights, n_dists, seed); - printf("result_one: %f\n", result_one); - - int n_samples = 1000000; - float* result_many = (float *) malloc(n_samples * sizeof(float)); - for(int i=0; i<n_samples; i++){ - result_many[i] = mixture(samplers, weights, n_dists, seed); - } - - printf("result_many: ["); - for(int i=0; i<100; i++){ - printf("%.2f, ", result_many[i]); - } - printf("]\n"); -} - -/* -Aggregation mechanisms: -- Quantiles (requires a sort) -- Sum -- Average -- Std -*/ diff --git a/C/squiggle_c/example_simple/example b/C/squiggle_c/examples/01_one_sample/example Binary files differ. diff --git a/C/squiggle_c/examples/01_one_sample/example.c b/C/squiggle_c/examples/01_one_sample/example.c @@ -0,0 +1,50 @@ +#include "../../squiggle.h" +#include <stdint.h> +#include <stdlib.h> +#include <stdio.h> + +// Estimate functions +float sample_0(uint32_t* seed) +{ + return 0; +} + +float sample_1(uint32_t* seed) +{ + return 1; +} + +float sample_few(uint32_t* seed) +{ + return random_to(1, 3, seed); +} + +float sample_many(uint32_t* seed) +{ + return random_to(2, 10, seed); +} + +int main(){ + // set randomness seed + uint32_t* seed = malloc(sizeof(uint32_t)); + *seed = 1000; // xorshift can't start with 0 + + float p_a = 0.8; + float p_b = 0.5; + float p_c = p_a * p_b; + + int n_dists = 4; + float weights[] = { 1 - p_c, p_c / 2, p_c / 4, p_c / 4 }; + float (*samplers[])(uint32_t*) = { sample_0, sample_1, sample_few, sample_many }; + + float result_one = mixture(samplers, weights, n_dists, seed); + printf("result_one: %f\n", result_one); +} + +/* +Aggregation mechanisms: +- Quantiles (requires a sort) +- Sum +- Average +- Std +*/ diff --git a/C/squiggle_c/example_simple/makefile b/C/squiggle_c/examples/01_one_sample/makefile diff --git a/C/squiggle_c/example_simple/example b/C/squiggle_c/examples/02_many_samples/example Binary files differ. diff --git a/C/squiggle_c/examples/02_many_samples/example.c b/C/squiggle_c/examples/02_many_samples/example.c @@ -0,0 +1,59 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdio.h> +#include "../../squiggle.h" + +// Estimate functions +float sample_0(uint32_t* seed) +{ + return 0; +} + +float sample_1(uint32_t* seed) +{ + return 1; +} + +float sample_few(uint32_t* seed) +{ + return random_to(1, 3, seed); +} + +float sample_many(uint32_t* seed) +{ + return random_to(2, 10, seed); +} + +int main(){ + // set randomness seed + uint32_t* seed = malloc(sizeof(uint32_t)); + *seed = 1000; // xorshift can't start with 0 + + float p_a = 0.8; + float p_b = 0.5; + float p_c = p_a * p_b; + + int n_dists = 4; + float weights[] = { 1 - p_c, p_c / 2, p_c / 4, p_c / 4 }; + float (*samplers[])(uint32_t*) = { sample_0, sample_1, sample_few, sample_many }; + + int n_samples = 1000000; + float* result_many = (float *) malloc(n_samples * sizeof(float)); + for(int i=0; i<n_samples; i++){ + result_many[i] = mixture(samplers, weights, n_dists, seed); + } + + printf("result_many: ["); + for(int i=0; i<100; i++){ + printf("%.2f, ", result_many[i]); + } + printf("]\n"); +} + +/* +Aggregation mechanisms: +- Quantiles (requires a sort) +- Sum +- Average +- Std +*/ diff --git a/C/squiggle_c/example_simple/makefile b/C/squiggle_c/examples/02_many_samples/makefile