forked from personal/squiggle.c
new pattern: define sampler and then sample from it
This commit is contained in:
parent
6199e43ae4
commit
279fb12dee
|
@ -3,33 +3,13 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
// Estimate functions
|
// Estimate functions
|
||||||
double sample_0(uint64_t* seed)
|
|
||||||
{
|
|
||||||
UNUSED(seed);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
double sample_1(uint64_t* seed)
|
double sample_model(uint64_t* seed){
|
||||||
{
|
|
||||||
UNUSED(seed);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
double sample_few(uint64_t* seed)
|
double sample_0(uint64_t* seed) { UNUSED(seed); return 0; }
|
||||||
{
|
double sample_1(uint64_t* seed) { UNUSED(seed); return 1; }
|
||||||
return sample_to(1, 3, seed);
|
double sample_few(uint64_t* seed) { return sample_to(1, 3, seed); }
|
||||||
}
|
double sample_many(uint64_t* seed) { return sample_to(2, 10, seed); }
|
||||||
|
|
||||||
double sample_many(uint64_t* seed)
|
|
||||||
{
|
|
||||||
return sample_to(2, 10, seed);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
// set randomness seed
|
|
||||||
uint64_t* seed = malloc(sizeof(uint64_t));
|
|
||||||
*seed = 1000; // xorshift can't start with 0
|
|
||||||
|
|
||||||
double p_a = 0.8;
|
double p_a = 0.8;
|
||||||
double p_b = 0.5;
|
double p_b = 0.5;
|
||||||
|
@ -38,8 +18,17 @@ int main()
|
||||||
int n_dists = 4;
|
int n_dists = 4;
|
||||||
double weights[] = { 1 - p_c, p_c / 2, p_c / 4, p_c / 4 };
|
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 };
|
double (*samplers[])(uint64_t*) = { sample_0, sample_1, sample_few, sample_many };
|
||||||
|
double result = sample_mixture(samplers, weights, n_dists, seed);
|
||||||
|
|
||||||
double result_one = sample_mixture(samplers, weights, n_dists, seed);
|
return result;
|
||||||
printf("result_one: %f\n", result_one);
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// set randomness seed
|
||||||
|
uint64_t* seed = malloc(sizeof(uint64_t));
|
||||||
|
*seed = 1000; // xorshift can't start with 0
|
||||||
|
|
||||||
|
printf("result_one: %f\n", sample_model(seed));
|
||||||
free(seed);
|
free(seed);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user