aboutsummaryrefslogtreecommitdiff
path: root/experiments/spheroid.c
blob: c2c8403c2f324bee37720a7f37a6e04cbfdbe9f8 (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
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <math.h>
#include <time.h>
#include "extent-sampling.h"
#include "oracles.h"

#define DIMENSION_START 5
#define DIMENSION_STEP 5
#define DIMENSION_STOP 100

#define RTOL 0.1
#define SAMPLES_PER_CONE 1000
#define SOLID_ANGLE_FACTOR 1.1

void run_experiment
(double eccentricity, double solid_angle_threshold_exponent_factor, FILE* fp)
{
  gsl_rng_env_setup();
  gsl_rng* r = gsl_rng_alloc(gsl_rng_default);

  spheroid_params params = {eccentricity};
  extent_oracle_t oracle = {spheroid_extent_oracle, &params};

  fprintf(fp, "# spheroid eccentricity = %g\n", eccentricity);
  fprintf(fp, "# samples per cone = %d\n", SAMPLES_PER_CONE);
  fprintf(fp, "# solid angle threshold = 2^(-%gn)\n", solid_angle_threshold_exponent_factor);
  fprintf(fp, "# solid angle factor = %g\n", SOLID_ANGLE_FACTOR);
  fprintf(fp, "dimension\tvolume\tsamples\ttime\n");
  for (int dim=DIMENSION_START; dim<=DIMENSION_STOP; dim+=DIMENSION_STEP) {
    gsl_vector* mean = gsl_vector_alloc(dim);
    gsl_vector_set_basis(mean, 0);

    unsigned int samples;
    clock_t begin = clock();
    double volume = volume_importance(&oracle, r, mean, SAMPLES_PER_CONE,
                                      SOLID_ANGLE_FACTOR, solid_angle_threshold_exponent_factor, &samples);
    clock_t end = clock();
    fprintf(fp, "%d\t%g\t%d\t%g\n", dim, 2*volume / spheroid_true_volume(dim, &params),
            samples, (double)(end-begin)/CLOCKS_PER_SEC);
    fflush(NULL);

    gsl_vector_free(mean);
  }
  gsl_rng_free(r);
}

int main ()
{
  FILE* fp = fopen("spheroid-eccentricity10.dat", "w");
  run_experiment(10, 2, fp);
  fclose(fp);

  fp = fopen("spheroid-eccentricity100.dat", "w");
  run_experiment(100, 6, fp);
  fclose(fp);
  return 0;
}