NunoSempere
04070a934e
This bash function was helpful: function replace(){ grep "$1" -rl . grep "$1" -rl . | xargs sed -i "s/$1/$2/g"; }
51 lines
930 B
C
51 lines
930 B
C
#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 sample_to(1, 3, seed);
|
|
}
|
|
|
|
float sample_many(uint32_t* seed)
|
|
{
|
|
return sample_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 = sample_mixture(samplers, weights, n_dists, seed);
|
|
printf("result_one: %f\n", result_one);
|
|
}
|
|
|
|
/*
|
|
Aggregation mechanisms:
|
|
- Quantiles (requires a sort)
|
|
- Sum
|
|
- Average
|
|
- Std
|
|
*/
|