Cumulative Normal Distribution Function in C/C++

后端 未结 7 2206
走了就别回头了
走了就别回头了 2020-12-07 14:15

I was wondering if there were statistics functions built into math libraries that are part of the standard C++ libraries like cmath. If not, can you guys recommend a good st

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-07 14:44

    From NVIDIA CUDA samples:

    static double CND(double d)
    {
        const double       A1 = 0.31938153;
        const double       A2 = -0.356563782;
        const double       A3 = 1.781477937;
        const double       A4 = -1.821255978;
        const double       A5 = 1.330274429;
        const double RSQRT2PI = 0.39894228040143267793994605993438;
    
        double
        K = 1.0 / (1.0 + 0.2316419 * fabs(d));
    
        double
        cnd = RSQRT2PI * exp(- 0.5 * d * d) *
              (K * (A1 + K * (A2 + K * (A3 + K * (A4 + K * A5)))));
    
        if (d > 0)
            cnd = 1.0 - cnd;
    
        return cnd;
    }
    

    Copyright 1993-2012 NVIDIA Corporation. All rights reserved.

提交回复
热议问题