annotate xthresh.c @ 279:dee55886eca0 sampling

make the RNG a part of the audioDB object. Easier to deal with memory discipline and initialization (though note the FIXME comment in audioDB::initTables()). Also initialize the RNG from the current time. A mature implementation would use a proper source of entropy...
author mas01cr
date Wed, 02 Jul 2008 13:53:23 +0000
parents 5d721f1ead01
children
rev   line source
mas01cr@272 1 #include <gsl/gsl_sf.h>
mas01cr@272 2 #include <stdio.h>
mas01cr@272 3 #include <stdlib.h>
mas01cr@272 4 #include <math.h>
mas01cr@272 5
mas01cr@272 6 int main(int argc, char *argv[]) {
mas01cr@272 7 if(argc != 4) {
mas01cr@272 8 fprintf(stderr, "Wrong number of arguments: %d\n", argc);
mas01cr@272 9 exit(1);
mas01cr@272 10 }
mas01cr@272 11
mas01cr@272 12 long int meanN = strtol(argv[1], NULL, 10);
mas01cr@272 13
mas01cr@272 14 double d = strtod(argv[2], NULL);
mas01cr@272 15 double sigma2 = strtod(argv[3], NULL);
mas01cr@272 16
mas01cr@272 17 double logw = (2 / d) * gsl_sf_log(-gsl_sf_log(0.99));
mas01cr@272 18 double logxthresh = gsl_sf_log(sigma2) + logw
mas01cr@272 19 - (2 / d) * gsl_sf_log(meanN)
mas01cr@272 20 - gsl_sf_log(d/2)
mas01cr@272 21 - (2 / d) * gsl_sf_log(2 / d)
mas01cr@272 22 + (2 / d) * gsl_sf_lngamma(d / 2);
mas01cr@272 23
mas01cr@272 24 printf("w: %f\n", exp(logw));
mas01cr@272 25 printf("x_thresh: %f\n", exp(logxthresh));
mas01cr@272 26 exit(0);
mas01cr@272 27 }