2023-06-26 17:44:41 +00:00
|
|
|
#include "../../squiggle.h"
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
2023-11-18 21:10:21 +00:00
|
|
|
#include <stdlib.h>
|
2023-06-26 17:44:41 +00:00
|
|
|
|
|
|
|
// Estimate functions
|
2023-07-23 11:02:56 +00:00
|
|
|
double sample_0(uint64_t* seed)
|
2023-06-26 17:44:41 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-07-23 11:02:56 +00:00
|
|
|
double sample_1(uint64_t* seed)
|
2023-06-26 17:44:41 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-07-23 11:02:56 +00:00
|
|
|
double sample_few(uint64_t* seed)
|
2023-06-26 17:44:41 +00:00
|
|
|
{
|
2023-07-22 17:21:20 +00:00
|
|
|
return sample_to(1, 3, seed);
|
2023-06-26 17:44:41 +00:00
|
|
|
}
|
|
|
|
|
2023-07-23 11:02:56 +00:00
|
|
|
double sample_many(uint64_t* seed)
|
2023-06-26 17:44:41 +00:00
|
|
|
{
|
2023-07-22 17:21:20 +00:00
|
|
|
return sample_to(2, 10, seed);
|
2023-06-26 17:44:41 +00:00
|
|
|
}
|
|
|
|
|
2023-11-18 21:10:21 +00:00
|
|
|
int main()
|
|
|
|
{
|
2023-06-26 17:44:41 +00:00
|
|
|
// set randomness seed
|
2023-11-18 21:10:21 +00:00
|
|
|
uint64_t* seed = malloc(sizeof(uint64_t));
|
|
|
|
*seed = 1000; // xorshift can't start with 0
|
2023-06-26 17:44:41 +00:00
|
|
|
|
2023-07-23 11:02:56 +00:00
|
|
|
double p_a = 0.8;
|
|
|
|
double p_b = 0.5;
|
|
|
|
double p_c = p_a * p_b;
|
2023-06-26 17:44:41 +00:00
|
|
|
|
|
|
|
int n_dists = 4;
|
2023-07-23 11:02:56 +00:00
|
|
|
double weights[] = { 1 - p_c, p_c / 2, p_c / 4, p_c / 4 };
|
|
|
|
double (*samplers[])(uint64_t*) = { sample_0, sample_1, sample_few, sample_many };
|
2023-06-26 17:44:41 +00:00
|
|
|
|
2023-07-23 11:02:56 +00:00
|
|
|
double result_one = sample_mixture(samplers, weights, n_dists, seed);
|
2023-11-18 21:10:21 +00:00
|
|
|
printf("result_one: %f\n", result_one);
|
|
|
|
free(seed);
|
2023-06-26 17:44:41 +00:00
|
|
|
}
|