UNPKG

als-statistics

Version:

A powerful and lightweight JavaScript library for descriptive statistics, regression, clustering, outlier detection, and noise analysis using a flexible table/column architecture.

28 lines (22 loc) 1.73 kB
const test = require('node:test'); const assert = require('node:assert'); const { gammaLn, betaLn, regularizedIncompleteBeta, tCDF } = require('../../lib/table/instruments/cdf'); function approxEqual(actual, expected, tolerance, message='') { const diff = Math.abs(actual - expected); assert.ok(diff <= tolerance, `${message}\nactual=${actual}, expected=${expected}, diff=${diff}`); } test('gammaLn: проверка нескольких известных точек', () => { approxEqual(gammaLn(1), 0, 1e-14, 'lnGamma(1) должно быть ~0'); // 1) gamma(1) = 1 => ln(gamma(1)) = 0 approxEqual(gammaLn(0.5), Math.log(Math.sqrt(Math.PI)), 1e-12, 'lnGamma(0.5) должно быть ln(sqrt(pi))'); // 2) gamma(1/2) = sqrt(pi) => lnGamma(1/2) = 0.5723649... Для удобства округлим до ~7 знаков approxEqual(gammaLn(5), Math.log(24), 1e-12, 'lnGamma(5) должно быть ln(24)'); // 3) gamma(5) = 24 => ln(gamma(5)) = ln(24) = 3.1780538303... }); test('betaLn: проверка известных значений Beta(a,b)', () => { approxEqual(betaLn(1,1), 0, 1e-14, 'betaLn(1,1) должно быть 0'); // 1) Beta(1,1)=1 => ln(Beta(1,1))=0 approxEqual(betaLn(0.5, 0.5), Math.log(Math.PI), 1e-12, 'betaLn(0.5,0.5) должно быть ln(pi)'); // 2) Beta(0.5,0.5) = pi => ln(pi)=1.14472988585... }); test('regularizedIncompleteBeta: несколько тестов I_x(a,b)', () => { approxEqual(regularizedIncompleteBeta(0.4, 2, 3), 0.5248, 1e-6, 'I_0.4(2,3) ~0.5248'); }); test('tCDF: проверка распределения Стьюдента', () => { approxEqual(tCDF(10, 1), 0.968274, 1e-6, 'tCDF(10; df=1) ~ 0.968274'); });