2023-09-27 14:25:12 +00:00
|
|
|
#include "../../squiggle.h"
|
2023-11-18 23:54:31 +00:00
|
|
|
#include "../../squiggle_more.h"
|
2023-09-27 14:25:12 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2023-11-18 21:10:21 +00:00
|
|
|
double sample_0(uint64_t* seed)
|
|
|
|
{
|
2023-09-27 14:25:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-11-18 21:10:21 +00:00
|
|
|
double sample_1(uint64_t* seed)
|
|
|
|
{
|
2023-09-27 14:25:12 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-11-18 21:10:21 +00:00
|
|
|
double sample_normal_mean_1_std_2(uint64_t* seed)
|
|
|
|
{
|
2023-09-27 14:25:12 +00:00
|
|
|
return sample_normal(1, 2, seed);
|
|
|
|
}
|
|
|
|
|
2023-11-18 21:10:21 +00:00
|
|
|
double sample_1_to_3(uint64_t* seed)
|
|
|
|
{
|
2023-09-27 14:25:12 +00:00
|
|
|
return sample_to(1, 3, seed);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
// set randomness seed
|
|
|
|
uint64_t* seed = malloc(sizeof(uint64_t));
|
|
|
|
*seed = 1000; // xorshift can't start with 0
|
|
|
|
|
|
|
|
int n_dists = 4;
|
|
|
|
double weights[] = { 1, 2, 3, 4 };
|
2023-11-18 21:10:21 +00:00
|
|
|
double (*samplers[])(uint64_t*) = {
|
|
|
|
sample_0,
|
|
|
|
sample_1,
|
|
|
|
sample_normal_mean_1_std_2,
|
|
|
|
sample_1_to_3
|
2023-09-27 14:25:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int n_samples = 10;
|
|
|
|
for (int i = 0; i < n_samples; i++) {
|
|
|
|
printf("Sample #%d: %f\n", i, sample_mixture(samplers, weights, n_dists, seed));
|
|
|
|
}
|
|
|
|
|
|
|
|
free(seed);
|
|
|
|
}
|