There is indeed no function named “gsl_cdf_gaussian_p”. However, there is a
function named "gsl_cdf_gaussian_P", as documented in the GSL manual here:
https://www.gnu.org/software/gsl/doc/html/randist.html.

The following rewritten version of your code compiles, though I cannot
comment on whether it does what you want:

#include <math.h>

#include <gsl/gsl_cdf.h>
#include <gsl/gsl_randist.h>

double truncnorm(double mu, double s, double a, double b, const gsl_rng *r)
{
  double sqrt_s = sqrt(s);
  double pa = gsl_cdf_gaussian_P(a - mu, sqrt_s);
  double pb = gsl_cdf_gaussian_P(b - mu, sqrt_s);
  double z = gsl_ran_flat(r, a, b);
  return gsl_cdf_gaussian_Pinv(z, sqrt_s) + mu;
}

I'm assuming you are aware of the following paper:

Geweke, J. (1991). Efficient simulation from the multivariate normal and
student-t distributions subject to linear constraints. In Computing Science
and Statistics: Proceedings of the 23rd Symposium on the Interface, Ed. E.
Keramidas and S. Kaufman, pp. 571-8. Fairfax Station, VA: Interface
Foundation of North America.

Hope this helps!

On Tue, Jun 30, 2020 at 4:25 AM 李 思达 <s...@knights.ucf.edu> wrote:

> Dear GSL
>
> I encounter problems in using GSL.
>
> GSL version: 2.4.0.8788, Visual Studio 2017 Release GSL as NuGet package.
> Operating system: Win10, X64
> Compiler: Visual Studio 2019, C++
> Behavior: #include<gsl/gsl_cdf.h>, could not find “gsl_cdf_gaussian_p”
> function when call it. Also, “gsl_cdf_gaussian_pinv” could not be found.
> Short program:
> double truncnorm(double mu, double s, double a, double b){
> #include <gsl/gsl_cdf.h>
>     double z;
>     a = gsl_cdf_gaussian_p(a-mu,sqrt(s));
>     b = gsl_cdf_gaussian_p(b-mu,sqrt(s));
>     z = gsl_ran_flat(r,a,b);
>     return gsl_cdf_gaussian_pinv(z,sqrt(s)) + mu;
> }
>
> Could you help me solve that?
> Thanks in advance.
> Best,
> Sida Li
> PhD student
>
> National Center for Integrated Coastal Research, UCF, USA
> Cell:  407 879 3347
> E-mail: s...@knights.ucf.edu
>
>

Reply via email to