Skip to content

Commit 6354641

Browse files
committed
expose hampel method. bump version
1 parent 93f32c0 commit 6354641

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
{
22
"name": "labkar-algorithms",
3-
"version": "1.0.2",
3+
"version": "2.0.0",
44
"description": "Labkar Algorithms",
55
"main": "dist/lib.js",
66
"scripts": {
77
"test": "jest",
88
"test:watch": "jest --watchAll",
99
"build": "tsc"
1010
},
11-
"files": ["dist/*.js", "dist/**/*.js"],
11+
"files": [
12+
"dist/*.js",
13+
"dist/**/*.js"
14+
],
1215
"dependencies": {
1316
"average": "^1.0.0",
1417
"compute-stdev": "^1.0.0",

src/algorithms/q-hampel.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { jStat } = require('jstat');
22
import { median } from 'simple-statistics';
33
import { get, sortBy, sumBy, round, sortedUniq, findIndex } from 'lodash';
44

5-
import { QHampelResult } from '../types';
5+
import { Result } from '../types';
66

77
interface Q_Options {
88
precision: number;
@@ -16,10 +16,10 @@ interface Q_Calculation {
1616
g: number;
1717
}
1818

19-
export function QHampel(
19+
export function Q(
2020
results: number[],
2121
options: Q_Options = { precision: 8 }
22-
): QHampelResult {
22+
): Result {
2323
const { precision } = options;
2424

2525
const values: number[] = ([] as number[]).concat(results).sort();
@@ -76,7 +76,6 @@ export function QHampel(
7676

7777
return {
7878
value,
79-
hampel: hampel(results, value),
8079
};
8180
}
8281

@@ -90,7 +89,7 @@ function calculateG(i: number, h: number, hPrevious: number) {
9089
}
9190
}
9291

93-
function hampel(results: number[], q: number) {
92+
export function Hampel(results: number[], q: number): Result {
9493
if (q === 0) {
9594
return { value: 0 };
9695
}
@@ -135,5 +134,7 @@ function hampel(results: number[], q: number) {
135134

136135
let x = median(values);
137136

138-
return calculateRecursive(values, x);
137+
return {
138+
value: calculateRecursive(values, x),
139+
};
139140
}

src/types.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
export type Result = {
22
value: number;
3-
uncertainty?: number;
4-
};
5-
export type QHampelResult = {
6-
value: number;
7-
hampel: number;
3+
uncertainty?: number;
84
};

tests/algorithms.test.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MADe, M_Estimator, QHampel } from '../src/lib';
1+
import { MADe, M_Estimator, Q, Hampel } from '../src/lib';
22

33
describe('Algorithms', () => {
44
it('MADe Method', () => {
@@ -17,7 +17,7 @@ describe('Algorithms', () => {
1717
expect(output.uncertainty).toBeCloseTo(1.118405, 3);
1818
});
1919

20-
it('Q-Hampel Method', () => {
20+
it('Q Method', () => {
2121
const samples = [
2222
41.41, 39.22, 47.29, 82.46, 45.24, 49.96, 38.2, 45.41, 39.82, 48.17,
2323
39.67, 47.55, 35.75, 46.13, 52.18, 45.15, 41.57, 43.39, 49.38, 45.67,
@@ -28,10 +28,25 @@ describe('Algorithms', () => {
2828
48.61, 44.18,
2929
];
3030

31-
const output = QHampel(samples);
31+
const output = Q(samples);
3232

3333
expect(output.value).toBeCloseTo(5.5457, 3);
34-
expect(output.hampel).toBeCloseTo(44.722, 3);
35-
34+
// expect(output.hampel).toBeCloseTo(44.722, 3);
35+
});
36+
37+
it('Hampel Method', () => {
38+
const samples = [
39+
41.41, 39.22, 47.29, 82.46, 45.24, 49.96, 38.2, 45.41, 39.82, 48.17,
40+
39.67, 47.55, 35.75, 46.13, 52.18, 45.15, 41.57, 43.39, 49.38, 45.67,
41+
41.08, 49.28, 49.48, 48.37, 33.96, 49.4, 24.4, 41.55, 37.43, 40.63, 49.92,
42+
47.88, 43.73, 38.1, 38.1, 46.82, 90.11, 45.74, 53.4, 42.65, 47.92, 42.02,
43+
49.47, 43.89, 50.05, 37.41, 53.64, 56.3, 47.13, 39.08, 44.73, 47, 50.53,
44+
44.22, 47.83, 46.04, 47, 36.3, 46.44, 24.79, 46.26, 39.88, 38.64, 50.19,
45+
48.61, 44.18,
46+
];
47+
48+
const output = Hampel(samples, Q(samples).value);
49+
50+
expect(output.value).toBeCloseTo(44.722, 3);
3651
});
3752
});

0 commit comments

Comments
 (0)