Skip to content

Commit 2b6b96c

Browse files
committed
chore: minor clean-up and add comment
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 70ac9cf commit 2b6b96c

File tree

2 files changed

+25
-2
lines changed
  • lib/node_modules/@stdlib/stats/base/dists/bradford/skewness

2 files changed

+25
-2
lines changed

lib/node_modules/@stdlib/stats/base/dists/bradford/skewness/lib/main.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,25 @@ var ln = require( '@stdlib/math/base/special/ln' );
5252
*/
5353
function skewness( c ) {
5454
var ans;
55+
var t1;
56+
var t2;
57+
var t3;
5558
var p;
59+
5660
if ( isnan( c ) || c <= 0.0 ) {
5761
return NaN;
5862
}
63+
5964
p = ln( 1.0 + c );
60-
ans = SQRT2*( (12*c*c) - (9*c*p*(c+2)) + (2*p*p*((c*(c+3)) + 3)) );
61-
ans /= sqrt(c*((c*(p-2)) + (2*p)))*( (3*c*(p-2)) + (6*p));
65+
66+
t1 = 12.0 * ( c*c );
67+
t2 = 9.0 * c * p * ( c + 2.0 );
68+
t3 = 2.0 * ( p*p ) * ( ( c * ( c + 3.0 ) ) + 3.0 );
69+
ans = SQRT2 * ( t1 - t2 + t3 );
70+
71+
t1 = c * ( ( c * ( p - 2.0 ) ) + ( 2.0 * p ) );
72+
t2 = ( 3.0 * c * ( p - 2.0 ) ) + ( 6.0 * p );
73+
ans /= sqrt( t1 ) * t2;
6274
return ans;
6375
}
6476

lib/node_modules/@stdlib/stats/base/dists/bradford/skewness/test/test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ tape( 'the function returns the skewness of a bradford distribution', function t
7878
t.equal( y, expected[i], 'x:'+x[i]+', y: '+y+', expected: '+expected[i] );
7979
} else {
8080
delta = abs( y - expected[ i ] );
81+
82+
/*
83+
* NOTE: the tolerance is set high in this case due to the numerically challenging nature of the Bradford distribution skewness formula, which involves:
84+
*
85+
* 1. Complex expressions with nested logarithmic terms ln(1+c)
86+
* 2. Square roots in both numerator and denominator
87+
* 3. Products and differences of terms involving c and ln(1+c) that can be sensitive to floating-point precision
88+
* 4. The SQRT2 factor amplifying any accumulated numerical errors
89+
*
90+
* Out of 1000 test cases, only 1 requires tolerance higher than 500*EPS (specifically c=0.4 needs ~20000*EPS).
91+
*/
8192
tol = 20000 * EPS * abs( expected[ i ] );
8293
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
8394
}

0 commit comments

Comments
 (0)