Пример #1
0
double Model::n1CDF(Eigen::VectorXd &d) {

  gsl_function F;
  F.function = &n1PDF;
  F.params = &d;

  double result, error;

  // integration sometimes fails
  gsl_set_error_handler_off();

  int limit = 10000;
  gsl_integration_workspace *w = gsl_integration_workspace_alloc(limit);

  double epsabs = 0, epsrel = 1e-7;
  double lower = 0, upper;

  const double chi = 2,
               sdI = 1; // following assumes these values. do not change these.

  int status = gsl_integration_qagiu(&F, lower, epsabs, epsrel, limit, w,
                                     &result, &error);

  if (status != GSL_SUCCESS) {

    double mean_drift = d.mean();
    if (mean_drift > d(0)) {
      lower = (chi - 0.98) / (mean_drift + 2 * sdI);
    } else {
      lower = (chi - 0.98) / (d(0) + 2 * sdI);
    }

    upper = 0.02 * chi / (mean_drift - 2 * sdI);

    size_t neval;
    status = gsl_integration_qng(&F, lower, upper, epsabs, epsrel, &result,
                                 &error, &neval);
  }

  if (status != GSL_SUCCESS) {
    // std::cout << "Integration Failed" << std::endl;
    // result = GSL_NAN;
    result = 0.0;
  }

  gsl_integration_workspace_free(w);

  return result;
}
Пример #2
0
double mean(Eigen::VectorXd &v)
{
	return v.mean();
}