积分时从gsl进行卡方检验给出0

时间:2015-09-21 08:50:37

标签: c++ gsl chi-squared

我试图使用gsl库计算多重积分,但它似乎无穷无尽,因为chisq值不断等于0.这是我的积分方法:

double Integr::Fgg(double x_val, double k_val){

    double result, error;
    double bound_up[] = {2*M_PI, 2*M_PI, k_max, k_max};
    double bound_down[] = {0,0,k_min, k_min};
    const gsl_rng_type *T;
    gsl_rng *r;

    struct f_params params = {x_val, k_val};
    gsl_monte_function Fgg = {&Integr::integrant_prot, 4, &params};
    size_t calls = 5000;
    gsl_rng_env_setup();
    T = gsl_rng_default;
    r = gsl_rng_alloc(T);

    //warm up
    gsl_monte_vegas_state *s = gsl_monte_vegas_alloc(4);
    gsl_monte_vegas_integrate(&Fgg, bound_down, bound_up, 4, 1000, r, s, &result, &error);

    //integration
    do{
        gsl_monte_vegas_integrate(&Fgg, bound_down, bound_up, 4, calls/5, r, s, &result, &error);
    }while(fabs(s->chisq - 1.0)>0.5);

    gsl_monte_vegas_free(s);
    return result;
}

有谁可以告诉我为什么这个价值不会发生变化?我的代码或我的gsl用法有问题吗?我不得不承认我是gsl的新人。

[编辑] 被动函数:

double Integr::integrant_prot(double *args, size_t dim, void *params){

    struct f_params *fp = (struct f_params *) params;
    return Integr::integrantFgg(fp->x_val, fp->k_val, args[0], args[1], args[2], args[3]);
}

0 个答案:

没有答案