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.
69 lines (61 loc) • 2.29 kB
JavaScript
const { describe, it } = require('node:test');
const assert = require('node:assert');
const Noice = require('../../../lib/ratio-column/instruments/noice');
describe('Noice class', () => {
it('detects low noise using relative dispersion', () => {
const sample = { relativeDispersion: 0.5 };
const noise = new Noice(sample);
assert.strictEqual(noise.noiseByRelativeDispersion, true);
});
it('detects noise using coefficient of variation (CV)', () => {
const sample = { cv: 0.8 };
const noise = new Noice(sample);
assert.strictEqual(noise.noiseByCV, true);
});
it('detects noise using skewness', () => {
const sample = { skewness: 0.5 };
const noise = new Noice(sample);
assert.strictEqual(noise.noiseBySkewness, true);
});
it('detects noise using z-score outliers', () => {
const sample = {
zScores: [-0.5, 0.2, 0.3, 1.0, 2.6],
skewness: 0.5, // ✅ Добавляем skewness, как в реальном коде
zThreshold: 2.0,
n: 5,
relativeDispersion: 1
};
const noise = new Noice(sample);
assert.strictEqual(noise.noiseByZ(), false);
});
it('should detect noise using z-score with min parameter', () => {
const sample = {
zScores: [-1, 0, 1, 2, 3],
skewness: 1,
n: 5,
relativeDispersion: 0.5
};
const noise = new Noice(sample);
assert.strictEqual(noise.noiseByZ(0.5), true); // Ожидаем true, так как выбросов нет
});
it('should detect no noise with few outliers', () => {
const sample = {
zScores: [-1, 0, 1, 2, 2.5],
skewness: 1,
n: 5,
relativeDispersion: 0.5
};
const noise = new Noice(sample);
assert.strictEqual(noise.noiseByZ(0.1), true); // Нет выбросов > 3 → true
});
it('should detect noise with high min', () => {
const sample = {
zScores: [-4, 0, 1, 2, 4],
skewness: 1,
n: 5,
relativeDispersion: 0.5
};
const noise = new Noice(sample);
assert.strictEqual(noise.noiseByZ(0.5), true); // 0.4 < 0.5 → true
});
});