aboutsummaryrefslogtreecommitdiff
path: root/experiments/cube.c
blob: 845688c3d312442f978aaa878b1ff3be642c7729 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;
}