diff options
author | Arun Isaac | 2022-01-08 12:46:58 +0530 |
---|---|---|
committer | Arun Isaac | 2022-01-08 12:46:58 +0530 |
commit | e3adf9d9793aa1302548a63a1e7d84a25e1420a8 (patch) | |
tree | aabaf42d2fbe7f8901083eb9aba54423851ce04f /experiments/cube.c | |
parent | 0ef42dfb41960ffa49aafc04fc7c9bfd49d13857 (diff) | |
download | nsmc-e3adf9d9793aa1302548a63a1e7d84a25e1420a8.tar.gz nsmc-e3adf9d9793aa1302548a63a1e7d84a25e1420a8.tar.lz nsmc-e3adf9d9793aa1302548a63a1e7d84a25e1420a8.zip |
Add C code for experiments.
* experiments/cube.c, experiments/integral.c, experiments/spheroid.c,
experiments/volume.c: New files.
Diffstat (limited to 'experiments/cube.c')
-rw-r--r-- | experiments/cube.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/experiments/cube.c b/experiments/cube.c new file mode 100644 index 0000000..845688c --- /dev/null +++ b/experiments/cube.c @@ -0,0 +1,46 @@ +/* How does the cube fare with unbiased extent sampling? + */ + +#include <stdio.h> +#include <gsl/gsl_vector.h> +#include "oracles.h" +#include "extent-sampling.h" + +#define DIMENSION_START 5 +#define DIMENSION_STEP 5 +#define DIMENSION_STOP 50 + +#define TRIALS 100 + +#define RTOL 0.1 +#define EDGE 1.0 + +double cube_oracle (const gsl_vector* x) { + return cube_extent_oracle(x, EDGE); +} + +int main () +{ + gsl_rng_env_setup(); + gsl_rng* r = gsl_rng_alloc(gsl_rng_default); + + FILE* fp = fopen("cube-window.dat", "w"); + printf("dimension\tsamples\n"); + fprintf(fp, "dimension\tsamples\n"); + for (int dim=DIMENSION_START; dim<=DIMENSION_STOP; dim+=DIMENSION_STEP) { + unsigned int total_samples=0; + for (int i=0; i<TRIALS; i++) { + unsigned int number_of_samples; + volume_window(cube_oracle, cube_true_volume(EDGE, dim), r, dim, RTOL, &number_of_samples); + total_samples += number_of_samples; + } + double average_samples = ((double)total_samples)/TRIALS; + printf("%d\t%g\n", dim, average_samples); + fprintf(fp, "%d\t%g\n", dim, average_samples); + fflush(NULL); + } + fclose(fp); + + gsl_rng_free(r); + return 0; +} |