@tmlmobilidade/math 20251202.1817.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Calculates the coefficient of variation for an array of numbers.
3
+ * @param value An array of numbers.
4
+ * @returns The coefficient of variation.
5
+ */
6
+ export declare function coefficientOfVariation(values: number[]): number;
@@ -0,0 +1,14 @@
1
+ /* * */
2
+ /**
3
+ * Calculates the coefficient of variation for an array of numbers.
4
+ * @param value An array of numbers.
5
+ * @returns The coefficient of variation.
6
+ */
7
+ export function coefficientOfVariation(values) {
8
+ const mean = values.reduce((a, b) => a + b, 0) / values.length;
9
+ if (mean === 0)
10
+ return 0;
11
+ const variance = values.reduce((a, b) => a + (b - mean) ** 2, 0) / values.length;
12
+ const std = Math.sqrt(variance);
13
+ return std / mean;
14
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Calculates the entropy for an array of values.
3
+ * @param values An array of numbers representing values.
4
+ * @returns The entropy of the values.
5
+ */
6
+ export declare function entropy(values: number[]): number;
@@ -0,0 +1,20 @@
1
+ /* * */
2
+ /**
3
+ * Calculates the entropy for an array of values.
4
+ * @param values An array of numbers representing values.
5
+ * @returns The entropy of the values.
6
+ */
7
+ export function entropy(values) {
8
+ const counts = {};
9
+ for (const d of values) {
10
+ const bucket = Math.round(d); // 1-second bins
11
+ counts[bucket] = (counts[bucket] ?? 0) + 1;
12
+ }
13
+ const total = values.length;
14
+ let entropy = 0;
15
+ for (const count of Object.values(counts)) {
16
+ const p = count / total;
17
+ entropy -= p * Math.log2(p);
18
+ }
19
+ return entropy;
20
+ }
@@ -0,0 +1,3 @@
1
+ export * from './coefficient-of-variation.js';
2
+ export * from './entropy.js';
3
+ export * from './round-number-bias.js';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './coefficient-of-variation.js';
2
+ export * from './entropy.js';
3
+ export * from './round-number-bias.js';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Calculates the round number bias for an array of values.
3
+ * @param values An array of numbers representing values.
4
+ * @returns The round number bias of the values.
5
+ */
6
+ export declare function roundNumberBias(values: number[]): number;
@@ -0,0 +1,11 @@
1
+ /* * */
2
+ /**
3
+ * Calculates the round number bias for an array of values.
4
+ * @param values An array of numbers representing values.
5
+ * @returns The round number bias of the values.
6
+ */
7
+ export function roundNumberBias(values) {
8
+ // Fraction of values that are "round" (multiples of 5 or 10)
9
+ const rounded = values.filter(d => d % 5 === 0 || d % 10 === 0).length;
10
+ return rounded / values.length;
11
+ }
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@tmlmobilidade/math",
3
+ "version": "20251202.1817.5",
4
+ "author": {
5
+ "email": "iso@tmlmobilidade.pt",
6
+ "name": "TML-ISO"
7
+ },
8
+ "license": "AGPL-3.0-or-later",
9
+ "homepage": "https://github.com/tmlmobilidade/go#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/tmlmobilidade/go/issues"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/tmlmobilidade/go.git"
16
+ },
17
+ "keywords": [
18
+ "public transit",
19
+ "tml",
20
+ "transportes metropolitanos de lisboa",
21
+ "go"
22
+ ],
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "type": "module",
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "main": "./dist/index.js",
31
+ "types": "./dist/index.d.ts",
32
+ "scripts": {
33
+ "build": "tsc && resolve-tspaths",
34
+ "lint": "eslint ./src/ && tsc --noEmit",
35
+ "lint:fix": "eslint ./src/ --fix",
36
+ "watch": "tsc-watch --onSuccess 'resolve-tspaths'"
37
+ },
38
+ "devDependencies": {
39
+ "@tmlmobilidade/tsconfig": "*",
40
+ "@types/node": "24.10.1",
41
+ "resolve-tspaths": "0.8.23",
42
+ "tsc-watch": "7.2.0",
43
+ "typescript": "5.9.3"
44
+ }
45
+ }