forked from personal/squiggle.c
continue minimizing nested functions
This commit is contained in:
parent
fa832cbd17
commit
86b12db894
|
@ -3,6 +3,10 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
double sample_model(uint64_t* seed){
|
||||||
|
return sample_to(1, 10, seed);
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// set randomness seed
|
// set randomness seed
|
||||||
|
|
|
@ -3,6 +3,10 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
double sample_model(uint64_t * seed)
|
||||||
|
{
|
||||||
|
return sample_lognormal(0, 10, seed);
|
||||||
|
}
|
||||||
// Estimate functions
|
// Estimate functions
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
@ -13,13 +17,9 @@ int main()
|
||||||
|
|
||||||
int n_samples = 1000 * 1000 * 1000;
|
int n_samples = 1000 * 1000 * 1000;
|
||||||
int n_threads = 16;
|
int n_threads = 16;
|
||||||
double sampler(uint64_t * seed)
|
|
||||||
{
|
|
||||||
return sample_lognormal(0, 10, seed);
|
|
||||||
}
|
|
||||||
double* results = malloc((size_t)n_samples * sizeof(double));
|
double* results = malloc((size_t)n_samples * sizeof(double));
|
||||||
|
|
||||||
sampler_parallel(sampler, results, n_threads, n_samples);
|
sampler_parallel(sample_model, results, n_threads, n_samples);
|
||||||
double avg = array_sum(results, n_samples) / n_samples;
|
double avg = array_sum(results, n_samples) / n_samples;
|
||||||
printf("Average of 1B lognormal(0,10): %f\n", avg);
|
printf("Average of 1B lognormal(0,10): %f\n", avg);
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
int main()
|
double sampler_result(uint64_t * seed)
|
||||||
{
|
{
|
||||||
double p_a = 0.8;
|
double p_a = 0.8;
|
||||||
double p_b = 0.5;
|
double p_b = 0.5;
|
||||||
|
@ -17,10 +17,11 @@ 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 sampler_result(uint64_t * seed)
|
return sample_mixture(samplers, weights, n_dists, seed);
|
||||||
{
|
}
|
||||||
return sample_mixture(samplers, weights, n_dists, seed);
|
|
||||||
}
|
int main()
|
||||||
|
{
|
||||||
|
|
||||||
int n_samples = 1000 * 1000, n_threads = 16;
|
int n_samples = 1000 * 1000, n_threads = 16;
|
||||||
double* results = malloc((size_t)n_samples * sizeof(double));
|
double* results = malloc((size_t)n_samples * sizeof(double));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user