|
27 | 27 | /** |
28 | 28 | * Evaluates the natural logarithm of the cumulative distribution function (CDF) for a Normal distribution with mean `mu` and standard deviation `sigma` at a value `x`. |
29 | 29 | * |
30 | | -* @param x input value |
31 | | -* @param mu mean of the distribution |
32 | | -* @param sigma standard deviation of the distribution |
33 | | -* @return evaluated logarithm of probability density function |
| 30 | +* @param x input value |
| 31 | +* @param mu mean |
| 32 | +* @param sigma standard deviation |
| 33 | +* @return evaluated logarithm of probability density function |
34 | 34 | * |
35 | 35 | * @example |
36 | 36 | * double y = stdlib_base_dists_normal_logpdf( 2.0, 0.0, 1.0 ); |
37 | 37 | * // returns ~-2.919 |
38 | 38 | */ |
39 | 39 | double stdlib_base_dists_normal_logpdf( const double x, const double mu, const double sigma ) { |
40 | | - |
41 | | - double s2; |
42 | | - double A; |
43 | | - double B; |
| 40 | + double s2; |
| 41 | + double A; |
| 42 | + double B; |
44 | 43 |
|
45 | 44 | if ( |
46 | | - stdlib_base_is_nan( x ) || |
47 | | - stdlib_base_is_nan( mu ) || |
48 | | - stdlib_base_is_nan( sigma ) || |
49 | | - sigma < 0.0 |
50 | | - ) { |
51 | | - return 0.0 / 0.0; // NaN |
52 | | - } |
| 45 | + stdlib_base_is_nan( x ) || |
| 46 | + stdlib_base_is_nan( mu ) || |
| 47 | + stdlib_base_is_nan( sigma ) || |
| 48 | + sigma < 0.0 |
| 49 | + ) { |
| 50 | + return 0.0 / 0.0; // NaN |
| 51 | + } |
53 | 52 | if ( sigma == 0.0 ) { |
54 | 53 | return (x == mu) ? STDLIB_CONSTANT_FLOAT64_PINF : STDLIB_CONSTANT_FLOAT64_NINF; |
55 | 54 | } |
56 | | - s2 = stdlib_base_pow(sigma, 2.0); |
57 | | - A = (-0.5) * ( ( 2.0 * stdlib_base_ln(sigma) ) + STDLIB_CONSTANT_FLOAT64_LN_TWO_PI ); |
58 | | - B = -1.0 / ( 2.0 * s2 ); |
59 | | - return A + (B * stdlib_base_pow(x - mu, 2.0)); |
| 55 | + s2 = stdlib_base_pow( sigma, 2.0 ); |
| 56 | + A = (-0.5) * ( ( 2.0 * stdlib_base_ln(sigma) ) + STDLIB_CONSTANT_FLOAT64_LN_TWO_PI ); |
| 57 | + B = -1.0 / ( 2.0 * s2 ); |
| 58 | + return A + ( B * stdlib_base_pow( x - mu, 2.0 ) ); |
60 | 59 | } |
0 commit comments