deno.land / x / simplestatistic@v7.7.1 / src / error_function.js

error_function.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/** * **[Gaussian error function](http://en.wikipedia.org/wiki/Error_function)** * * The `errorFunction(x/(sd * Math.sqrt(2)))` is the probability that a value in a * normal distribution with standard deviation sd is within x of the mean. * * This function returns a numerical approximation to the exact value. * It uses Horner's method to evaluate the polynomial of τ (tau). * * @param {number} x input * @return {number} error estimation * @example * errorFunction(1).toFixed(2); // => '0.84' */function errorFunction(x) { const t = 1 / (1 + 0.5 * Math.abs(x)); const tau = t * Math.exp( -x * x + ((((((((0.17087277 * t - 0.82215223) * t + 1.48851587) * t - 1.13520398) * t + 0.27886807) * t - 0.18628806) * t + 0.09678418) * t + 0.37409196) * t + 1.00002368) * t - 1.26551223 ); if (x >= 0) { return 1 - tau; } else { return tau - 1; }}
export default errorFunction;
simplestatistic

Version Info

Tagged at
2 years ago