@nirs4all/methods 1.3.13 → 1.3.15

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.
Files changed (47) hide show
  1. package/LICENSE +235 -0
  2. package/LICENSE-CeCILL-2.1 +518 -0
  3. package/README.md +154 -2
  4. package/dist/LICENSES/AGPL-3.0-or-later.txt +235 -0
  5. package/dist/LICENSES/Apache-2.0.txt +73 -0
  6. package/dist/LICENSES/BSD-3-Clause.txt +11 -0
  7. package/dist/LICENSES/COMMERCIAL-LICENSE.md +14 -0
  8. package/dist/LICENSES/COMMERCIAL-LICENSE_FR.md +15 -0
  9. package/dist/LICENSES/CeCILL-2.1.txt +518 -0
  10. package/dist/LICENSES/MIT.txt +18 -0
  11. package/dist/LICENSES/mixeff-dependencies.txt +13459 -0
  12. package/dist/LICENSES/mixeff-rs.txt +21 -0
  13. package/dist/LICENSES/rfr-cereal.txt +24 -0
  14. package/dist/LICENSES/rfr-rapidjson.txt +57 -0
  15. package/dist/LICENSES/rfr.txt +33 -0
  16. package/dist/LICENSES/rust-standard-library.txt +8266 -0
  17. package/dist/THIRD_PARTY_LICENSES.md +140 -0
  18. package/dist/componentAnalysis.d.ts +61 -0
  19. package/dist/componentAnalysis.js +175 -0
  20. package/dist/config.js +1 -1
  21. package/dist/context.js +1 -1
  22. package/dist/estimatorRoles.js +18 -1
  23. package/dist/estimatorRolesGenerated.d.ts +48 -1
  24. package/dist/estimatorRolesGenerated.js +41 -2
  25. package/dist/ffi.js +1 -1
  26. package/dist/index.d.ts +2 -0
  27. package/dist/index.js +3 -1
  28. package/dist/methodResult.js +1 -1
  29. package/dist/model.js +1 -1
  30. package/dist/multimodalPipeline.js +1 -1
  31. package/dist/n4m.js +1 -1
  32. package/dist/n4m.wasm +0 -0
  33. package/dist/nativeAugmentation.js +1 -1
  34. package/dist/nativeModel.js +1 -1
  35. package/dist/nativePreprocessingPipeline.js +1 -1
  36. package/dist/nativeSplitter.js +1 -1
  37. package/dist/optimization.js +1 -1
  38. package/dist/preflightDiagnostics.js +1 -1
  39. package/dist/preprocessing.js +5 -1
  40. package/dist/ranking.d.ts +61 -0
  41. package/dist/ranking.js +110 -0
  42. package/dist/rolePipeline.js +1 -1
  43. package/dist/selection.js +1 -1
  44. package/dist/serialization.js +1 -1
  45. package/dist/spectralEncoding.js +1 -1
  46. package/dist/types.js +1 -1
  47. package/package.json +7 -5
package/dist/n4m.wasm CHANGED
Binary file
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: CECILL-2.1
1
+ // SPDX-License-Identifier: CECILL-2.1 OR AGPL-3.0-or-later
2
2
  // Train-only X->X augmentation facade. All numerical work remains in C++.
3
3
  import { checkStatus, getModule } from "./ffi.js";
4
4
  const KINDS = {
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: CECILL-2.1
1
+ // SPDX-License-Identifier: CECILL-2.1 OR AGPL-3.0-or-later
2
2
  // Native predict-only model promoted from an affine MethodResult.
3
3
  import { checkStatus, getModule, makeMatrixView, readArrayView } from "./ffi.js";
4
4
  import { ModelArray } from "./types.js";
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: CECILL-2.1
1
+ // SPDX-License-Identifier: CECILL-2.1 OR AGPL-3.0-or-later
2
2
  // Fitted preprocessing and N4MP portability; all numerics remain in libn4m.
3
3
  import { checkStatus, getModule, makeMatrixView } from "./ffi.js";
4
4
  /** The 15 pipeline kinds currently implemented by the native core. */
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: CECILL-2.1
1
+ // SPDX-License-Identifier: CECILL-2.1 OR AGPL-3.0-or-later
2
2
  // One typed marshalling path to the nine native sample splitters.
3
3
  import { checkStatus, getModule } from "./ffi.js";
4
4
  const KINDS = {
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: CECILL-2.1
1
+ // SPDX-License-Identifier: CECILL-2.1 OR AGPL-3.0-or-later
2
2
  // Thin, owning WASM facade for the native n4m optimizer. Sampling, pruning,
3
3
  // trace and checkpoint semantics stay exclusively in libn4m.
4
4
  import { Context } from "./context.js";
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: CECILL-2.1
1
+ // SPDX-License-Identifier: CECILL-2.1 OR AGPL-3.0-or-later
2
2
  // Thin, caller-buffer wrappers for the public Methods Preflight diagnostics.
3
3
  import { checkStatus, getModule, makeMatrixView } from "./ffi.js";
4
4
  import { Context } from "./context.js";
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: CECILL-2.1
1
+ // SPDX-License-Identifier: CECILL-2.1 OR AGPL-3.0-or-later
2
2
  //
3
3
  // Generic preprocessing surface over libn4m. One opaque handle wraps any
4
4
  // supported preprocessing operator; the numerics live entirely in libn4m
@@ -38,6 +38,10 @@ function checkDims(X, n, p) {
38
38
  }
39
39
  /** Create a preprocessing operator by catalog type token + numeric params. */
40
40
  export function ppCreate(op, params = []) {
41
+ if (op === "StandardNormalVariate" && !(params === undefined ||
42
+ (Array.isArray(params) && params.length === 0))) {
43
+ throw new TypeError("SNV accepts only an empty parameter Array; use SNV/RolePipeline for options");
44
+ }
41
45
  const m = getModule();
42
46
  let pPtr = 0;
43
47
  let ptr = 0;
@@ -0,0 +1,61 @@
1
+ import type { Matrix } from "./types.js";
2
+ export type RankingMethod = "average_rank" | "elo" | "bradley_terry" | "trueskill" | "trueskill_1v1" | "openskill" | "weng_lin_bradley_terry";
3
+ export interface RankingOptions {
4
+ method?: RankingMethod;
5
+ higher_is_better?: boolean;
6
+ tie_tolerance?: number;
7
+ initial_mean?: number;
8
+ k_factor?: number;
9
+ elo_scale?: number;
10
+ prior_sigma?: number;
11
+ beta?: number;
12
+ dynamics?: number;
13
+ draw_margin?: number;
14
+ regularization?: number;
15
+ convergence_tolerance?: number;
16
+ max_iterations?: number;
17
+ }
18
+ export interface RankingCandidate {
19
+ index: number;
20
+ score: number | null;
21
+ uncertainty: number | null;
22
+ average_rank: number | null;
23
+ observations: number;
24
+ matches: number;
25
+ component: number;
26
+ wins: number;
27
+ ties: number;
28
+ losses: number;
29
+ rank: number | null;
30
+ }
31
+ export interface RankingResult {
32
+ schema_version: "n4m.ranking/1";
33
+ method: RankingMethod;
34
+ variant: string;
35
+ options: Required<Omit<RankingOptions, "method">>;
36
+ score_direction: "lower_is_better" | "higher_is_better";
37
+ uncertainty_kind: "approximate_posterior_sd" | null;
38
+ candidates: RankingCandidate[];
39
+ coverage: {
40
+ blocks: number;
41
+ complete_blocks: number;
42
+ paired_comparisons: number;
43
+ connected_components: number;
44
+ };
45
+ inference: {
46
+ friedman_statistic: number | null;
47
+ degrees_of_freedom: number | null;
48
+ friedman_p_value: number | null;
49
+ p_value_method: "chi_square_approximation";
50
+ reason: string;
51
+ };
52
+ warnings: string[];
53
+ convergence: {
54
+ converged: boolean;
55
+ iterations: number;
56
+ };
57
+ }
58
+ /** Rank candidates in columns across comparable blocks in rows. The required
59
+ * row-major presence mask contains 0 or 1; masked scores may be nonfinite.
60
+ * Bayesian uncertainty is an approximate posterior SD, not a standard error. */
61
+ export declare function rank(scores: Matrix, present: Uint8Array, options?: RankingOptions): RankingResult;
@@ -0,0 +1,110 @@
1
+ // SPDX-License-Identifier: CECILL-2.1 OR AGPL-3.0-or-later
2
+ import { checkStatus, getModule, makeMatrixView } from "./ffi.js";
3
+ const METHODS = {
4
+ average_rank: { code: 0, variant: "average_rank" }, elo: { code: 1, variant: "elo" },
5
+ bradley_terry: { code: 2, variant: "bradley_terry" },
6
+ trueskill: { code: 3, variant: "trueskill_1v1" },
7
+ trueskill_1v1: { code: 3, variant: "trueskill_1v1" },
8
+ openskill: { code: 4, variant: "weng_lin_bradley_terry" },
9
+ weng_lin_bradley_terry: { code: 4, variant: "weng_lin_bradley_terry" },
10
+ };
11
+ const DOUBLE_KEYS = ["tie_tolerance", "initial_mean", "k_factor", "elo_scale", "prior_sigma",
12
+ "beta", "dynamics", "draw_margin", "regularization", "convergence_tolerance"];
13
+ const nullable = (value) => Number.isFinite(value) ? value : null;
14
+ /** Rank candidates in columns across comparable blocks in rows. The required
15
+ * row-major presence mask contains 0 or 1; masked scores may be nonfinite.
16
+ * Bayesian uncertainty is an approximate posterior SD, not a standard error. */
17
+ export function rank(scores, present, options = {}) {
18
+ const allowed = new Set(["method", "higher_is_better", "max_iterations", ...DOUBLE_KEYS]);
19
+ for (const key of Object.keys(options)) {
20
+ if (!allowed.has(key))
21
+ throw new Error(`unknown ranking option ${key}`);
22
+ }
23
+ const method = options.method ?? "average_rank";
24
+ if (!Object.prototype.hasOwnProperty.call(METHODS, method))
25
+ throw new Error(`unknown ranking method ${method}`);
26
+ const size = scores.rows * scores.cols;
27
+ if (!Number.isSafeInteger(scores.rows) || !Number.isSafeInteger(scores.cols) ||
28
+ scores.rows < 1 || scores.cols < 1 || !Number.isSafeInteger(size) ||
29
+ size > 0x7fffffff || scores.cols > Math.floor(0x7fffffff / 80) ||
30
+ scores.data.length !== size || !(present instanceof Uint8Array) || present.length !== size ||
31
+ !present.every(value => value === 0 || value === 1)) {
32
+ throw new Error("scores and 0/1 presence mask must have matching nonempty dimensions");
33
+ }
34
+ if (options.higher_is_better !== undefined && typeof options.higher_is_better !== "boolean") {
35
+ throw new Error("higher_is_better must be boolean");
36
+ }
37
+ if (options.max_iterations !== undefined && !Number.isSafeInteger(options.max_iterations)) {
38
+ throw new Error("max_iterations must be a safe integer");
39
+ }
40
+ for (const key of DOUBLE_KEYS) {
41
+ if (options[key] !== undefined && !Number.isFinite(options[key]))
42
+ throw new Error(`${key} must be finite`);
43
+ }
44
+ const m = getModule();
45
+ const view = makeMatrixView(scores.data, scores.rows, scores.cols);
46
+ const allocations = [];
47
+ const alloc = (bytes) => {
48
+ const ptr = m._malloc(bytes);
49
+ if (!ptr)
50
+ throw new Error("ranking allocation failed");
51
+ allocations.push(ptr);
52
+ return ptr;
53
+ };
54
+ try {
55
+ const opt = alloc(104), mask = alloc(size), output = alloc(scores.cols * 10 * 8), summary = alloc(72);
56
+ checkStatus(m.ccall("n4m_ranking_options_init_v1", "number", ["number"], [opt]));
57
+ m.HEAPU8.set(present, mask);
58
+ const data = new DataView(m.HEAPU8.buffer);
59
+ data.setInt32(opt + 8, METHODS[method].code, true);
60
+ if (options.higher_is_better !== undefined)
61
+ data.setInt32(opt + 12, options.higher_is_better ? 1 : 0, true);
62
+ DOUBLE_KEYS.forEach((key, i) => {
63
+ const value = options[key];
64
+ if (value !== undefined)
65
+ data.setFloat64(opt + 16 + 8 * i, value, true);
66
+ });
67
+ if (options.max_iterations !== undefined)
68
+ data.setBigInt64(opt + 96, BigInt(options.max_iterations), true);
69
+ const resolved = { higher_is_better: data.getInt32(opt + 12, true) !== 0,
70
+ ...Object.fromEntries(DOUBLE_KEYS.map((key, i) => [key, data.getFloat64(opt + 16 + 8 * i, true)])),
71
+ max_iterations: Number(data.getBigInt64(opt + 96, true)) };
72
+ checkStatus(m.ccall("n4m_ranking_compute_v1", "number", ["number", "number", "number", "number", "i64", "number", "i64"], [view.viewPtr, mask, opt, output, BigInt(scores.cols * 10), summary, 9n]));
73
+ const values = m.HEAPF64;
74
+ const candidates = Array.from({ length: scores.cols }, (_, i) => {
75
+ const p = output / 8 + i * 10;
76
+ return { index: i, score: nullable(values[p]), uncertainty: nullable(values[p + 1]),
77
+ average_rank: nullable(values[p + 2]), observations: values[p + 3], matches: values[p + 4],
78
+ component: values[p + 5], wins: values[p + 6], ties: values[p + 7], losses: values[p + 8],
79
+ rank: nullable(values[p + 9]) };
80
+ });
81
+ const s = summary / 8;
82
+ const warnings = [
83
+ "Mean ranks use all observed blocks; Friedman uses complete blocks only.",
84
+ "Friedman p-value uses a chi-square approximation and assumes independent blocks.",
85
+ ];
86
+ if (METHODS[method].code >= 3)
87
+ warnings.push("Pairwise replay within each block is a composite approximation; posterior SD does not account for dependence between comparisons or repeated folds.");
88
+ if (METHODS[method].code === 0 && values[s + 1] < values[s])
89
+ warnings.push("Incomplete design: mean ranks are descriptive and average_rank global ranks are unavailable; use bradley_terry or trueskill for incomplete comparisons.");
90
+ if (values[s + 3] > 1)
91
+ warnings.push("Disconnected comparison graph: global ranks are unavailable.");
92
+ if (values[s + 6] === 0)
93
+ warnings.push("Bradley-Terry did not converge; global ranks are unavailable.");
94
+ return { schema_version: "n4m.ranking/1", method, variant: METHODS[method].variant, options: resolved,
95
+ score_direction: method === "average_rank" ? "lower_is_better" : "higher_is_better",
96
+ uncertainty_kind: METHODS[method].code >= 3 ? "approximate_posterior_sd" : null,
97
+ candidates, coverage: { blocks: values[s], complete_blocks: values[s + 1],
98
+ paired_comparisons: values[s + 2], connected_components: values[s + 3] },
99
+ inference: { friedman_statistic: nullable(values[s + 4]), degrees_of_freedom: nullable(values[s + 5]),
100
+ friedman_p_value: nullable(values[s + 8]),
101
+ p_value_method: "chi_square_approximation",
102
+ reason: "chi_square_approximation_on_complete_blocks; host_must_assess_independence" },
103
+ warnings,
104
+ convergence: { converged: values[s + 6] !== 0, iterations: values[s + 7] } };
105
+ }
106
+ finally {
107
+ allocations.forEach(ptr => m._free(ptr));
108
+ view.free();
109
+ }
110
+ }
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: CECILL-2.1
1
+ // SPDX-License-Identifier: CECILL-2.1 OR AGPL-3.0-or-later
2
2
  // Native role pipeline (ABI 2.14): a trained linear recipe of catalog
3
3
  // estimators (sample filters, transformers / selectors, one regressor or
4
4
  // classifier). Recipe validation, fit-input routing, the feature-name check
package/dist/selection.js CHANGED
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: CECILL-2.1
1
+ // SPDX-License-Identifier: CECILL-2.1 OR AGPL-3.0-or-later
2
2
  import { Config } from "./config.js";
3
3
  import { Context } from "./context.js";
4
4
  import { checkStatus, getModule, makeMatrixView } from "./ffi.js";
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: CECILL-2.1
1
+ // SPDX-License-Identifier: CECILL-2.1 OR AGPL-3.0-or-later
2
2
  //
3
3
  // Authoritative inspection of complete N4MM fitted-model payloads.
4
4
  import { checkStatus, getModule } from "./ffi.js";
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: CECILL-2.1
1
+ // SPDX-License-Identifier: CECILL-2.1 OR AGPL-3.0-or-later
2
2
  import { checkStatus, getModule } from "./ffi.js";
3
3
  /** Fitted native LVSE/GCU. Call dispose() to release its WASM handle. */
4
4
  export class SpectralEncoder {
package/dist/types.js CHANGED
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: CECILL-2.1
1
+ // SPDX-License-Identifier: CECILL-2.1 OR AGPL-3.0-or-later
2
2
  /** Mirror of the C enum n4m_status_t (cpp/include/n4m/n4m.h). */
3
3
  export var Status;
4
4
  (function (Status) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nirs4all/methods",
3
- "version": "1.3.13",
3
+ "version": "1.3.15",
4
4
  "description": "WebAssembly build of libn4m (nirs4all-methods) — portable PLS/NIRS engine and native method bindings.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -13,16 +13,18 @@
13
13
  "./n4m.wasm": "./dist/n4m.wasm"
14
14
  },
15
15
  "files": [
16
- "dist/"
16
+ "dist/",
17
+ "LICENSE-CeCILL-2.1"
17
18
  ],
18
19
  "scripts": {
19
20
  "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
20
21
  "build": "npm run clean && tsc -p .",
21
- "stage:wasm": "node -e \"const fs=require('fs'),p='../../build/emscripten/bindings/js/';fs.mkdirSync('dist',{recursive:true});for(const f of ['n4m.js','n4m.wasm']){if(!fs.existsSync(p+f))throw new Error('missing WASM artifact '+p+f+' — run: cmake --preset emscripten && cmake --build --preset emscripten --target n4m_wasm');fs.copyFileSync(p+f,'dist/'+f)}console.log('staged n4m.js + n4m.wasm into dist/')\"",
22
+ "stage:wasm": "node -e \"const fs=require('fs'),p='../../build/'+(process.env.N4M_WASM_PRESET||'emscripten')+'/bindings/js/';fs.mkdirSync('dist',{recursive:true});for(const f of ['n4m.js','n4m.wasm']){if(!fs.existsSync(p+f))throw new Error('missing WASM artifact '+p+f+' — run: cmake --preset emscripten && cmake --build --preset emscripten --target n4m_wasm');fs.copyFileSync(p+f,'dist/'+f)}fs.copyFileSync('../../THIRD_PARTY_LICENSES.md','dist/THIRD_PARTY_LICENSES.md');fs.cpSync('../../LICENSES','dist/LICENSES',{recursive:true});console.log('staged n4m.js + n4m.wasm + THIRD_PARTY_LICENSES.md into dist/')\"",
22
23
  "prepack": "npm run build && npm run stage:wasm",
23
- "test": "node --experimental-vm-modules test/run_smoke.mjs && node --experimental-vm-modules test/run_api.mjs && node --experimental-vm-modules test/run_generic_method.mjs && node --experimental-vm-modules test/run_pop_aom.mjs && node --experimental-vm-modules test/run_new_pack.mjs && node --experimental-vm-modules test/run_serialization_inspect.mjs && node --experimental-vm-modules test/run_method_result_model.mjs && node --experimental-vm-modules test/run_native_preprocessing_pipeline.mjs && node --experimental-vm-modules test/run_native_splitter.mjs && node --experimental-vm-modules test/run_native_augmentation.mjs && node --experimental-vm-modules test/run_estimator_roles.mjs && node --experimental-vm-modules test/run_estimator_roles_negative.mjs && node --experimental-vm-modules test/run_role_pipeline.mjs && node --experimental-vm-modules test/run_spectral_encoding.mjs && node --experimental-vm-modules test/run_optimization.mjs && node --experimental-vm-modules test/run_preflight_diagnostics.mjs && node --experimental-vm-modules test/run_pls_scale_equivariance.mjs && node --experimental-vm-modules test/run_pls_small_covariance.mjs && node --experimental-vm-modules test/run_pls_null_consumers.mjs && node --experimental-vm-modules test/run_pls_scale_consumers.mjs && node test/run_intrinsic_diagnostics.mjs"
24
+ "test": "node --experimental-vm-modules test/run_smoke.mjs && node --experimental-vm-modules test/run_api.mjs && node --experimental-vm-modules test/run_generic_method.mjs && node --experimental-vm-modules test/run_pop_aom.mjs && node --experimental-vm-modules test/run_new_pack.mjs && node --experimental-vm-modules test/run_serialization_inspect.mjs && node --experimental-vm-modules test/run_method_result_model.mjs && node --experimental-vm-modules test/run_native_preprocessing_pipeline.mjs && node --experimental-vm-modules test/run_native_splitter.mjs && node --experimental-vm-modules test/run_native_augmentation.mjs && node --experimental-vm-modules test/run_estimator_roles.mjs && node --experimental-vm-modules test/run_estimator_roles_negative.mjs && node --experimental-vm-modules test/run_role_pipeline.mjs && node --experimental-vm-modules test/run_spectral_encoding.mjs && node --experimental-vm-modules test/run_optimization.mjs && node --experimental-vm-modules test/run_preflight_diagnostics.mjs && node --experimental-vm-modules test/run_pls_scale_equivariance.mjs && node --experimental-vm-modules test/run_pls_small_covariance.mjs && node --experimental-vm-modules test/run_pls_null_consumers.mjs && node --experimental-vm-modules test/run_pls_scale_consumers.mjs && node test/run_intrinsic_diagnostics.mjs && npm run test:shared-scoring && node test/run_snv_parameter_contract.mjs && node test/run_raw_i32_status.mjs && node --experimental-vm-modules test/ranking_mock.mjs && node test/run_ranking.mjs && node test/run_component_analysis.mjs",
25
+ "test:shared-scoring": "node test/run_shared_scoring.mjs"
24
26
  },
25
- "license": "CECILL-2.1",
27
+ "license": "CECILL-2.1 OR AGPL-3.0-or-later",
26
28
  "publishConfig": {
27
29
  "access": "public",
28
30
  "provenance": true