@nirs4all/methods 1.3.19 → 1.4.1
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.
- package/README.md +32 -2
- package/dist/estimatorRoles.d.ts +46 -0
- package/dist/estimatorRoles.js +106 -1
- package/dist/estimatorRolesGenerated.d.ts +26 -0
- package/dist/estimatorRolesGenerated.js +20 -1
- package/dist/explain.d.ts +46 -2
- package/dist/explain.js +173 -8
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/n4m.js +1 -1
- package/dist/n4m.wasm +0 -0
- package/dist/rolePipeline.d.ts +17 -2
- package/dist/rolePipeline.js +46 -3
- package/package.json +2 -2
package/dist/n4m.wasm
CHANGED
|
Binary file
|
package/dist/rolePipeline.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type FitInputs, type ParamValue } from "./estimatorRoles.js";
|
|
1
|
+
import { type AffineCoefficients, type FitInputs, type ParamValue } from "./estimatorRoles.js";
|
|
2
2
|
import type { Matrix } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* A recipe step: a method id ("models.pls.cppls" or "n4m:models.pls.cppls"),
|
|
@@ -23,6 +23,10 @@ export interface RolePipelineStepInfo {
|
|
|
23
23
|
containsTrainingRows: boolean;
|
|
24
24
|
nFeaturesIn: number;
|
|
25
25
|
nFeaturesOut: number;
|
|
26
|
+
/** ABI 2.24: exact-affine at predict time (affine transform, affine terminal model, sample filter). */
|
|
27
|
+
affine: boolean;
|
|
28
|
+
/** ABI 2.24: output column j is the spectral position of input column j (transformers; same fitted width). */
|
|
29
|
+
columnAligned: boolean;
|
|
26
30
|
}
|
|
27
31
|
export interface RolePipelineState {
|
|
28
32
|
methodId: string;
|
|
@@ -84,8 +88,19 @@ export declare class RolePipeline {
|
|
|
84
88
|
classes(): ClassLabel[];
|
|
85
89
|
/** Native class ids of the final classifier (n4m_role_pipeline_classes). */
|
|
86
90
|
private static classIds;
|
|
87
|
-
/** Per step: method, role played, state index, fitted widths, training rows. */
|
|
91
|
+
/** Per step: method, role played, state index, fitted widths, training rows, affine / column-aligned traits. */
|
|
88
92
|
stepsInfo(): RolePipelineStepInfo[];
|
|
93
|
+
/** One step of stepsInfo(). */
|
|
94
|
+
stepInfo(step: number): RolePipelineStepInfo;
|
|
95
|
+
/**
|
|
96
|
+
* Exact raw-input affine map predict(X) = X B_raw + b_raw of a fitted
|
|
97
|
+
* pipeline whose transformers / selectors are all affine and whose final
|
|
98
|
+
* model is affine (B_raw = A' B composed natively). The native refusal
|
|
99
|
+
* names the first non-affine step ("step <i> (<method id>): ...").
|
|
100
|
+
*/
|
|
101
|
+
inputAffineCoefficients(): AffineCoefficients & {
|
|
102
|
+
nFeaturesIn: number;
|
|
103
|
+
};
|
|
89
104
|
/**
|
|
90
105
|
* One N4ME state per stateful step. A state that embeds training rows is
|
|
91
106
|
* refused unless allowTrainingRows is set.
|
package/dist/rolePipeline.js
CHANGED
|
@@ -11,8 +11,9 @@ const ROLES = {
|
|
|
11
11
|
1: "transformer", 2: "regressor", 4: "classifier", 8: "selector", 16: "sample_filter",
|
|
12
12
|
};
|
|
13
13
|
const EXPORT_ALLOW_TRAINING_ROWS = 1;
|
|
14
|
-
// n4m_role_pipeline_step_info_v1_t on wasm32 (pointers 4 bytes, int64 8-aligned)
|
|
15
|
-
|
|
14
|
+
// n4m_role_pipeline_step_info_v1_t on wasm32 (pointers 4 bytes, int64 8-aligned),
|
|
15
|
+
// with the ABI 2.24 affine / column_aligned fields at 40 / 44.
|
|
16
|
+
const STEP_INFO_SIZE = 48;
|
|
16
17
|
function parseStep(step) {
|
|
17
18
|
const id = (s) => (s.startsWith("n4m:") ? s.slice(4) : s);
|
|
18
19
|
if (typeof step === "string")
|
|
@@ -287,11 +288,51 @@ export class RolePipeline {
|
|
|
287
288
|
m._free(countPtr);
|
|
288
289
|
}
|
|
289
290
|
}
|
|
290
|
-
/** Per step: method, role played, state index, fitted widths, training rows. */
|
|
291
|
+
/** Per step: method, role played, state index, fitted widths, training rows, affine / column-aligned traits. */
|
|
291
292
|
stepsInfo() {
|
|
292
293
|
const handle = this.handle();
|
|
293
294
|
return this.steps.map((_, i) => RolePipeline.stepInfo(handle, i));
|
|
294
295
|
}
|
|
296
|
+
/** One step of stepsInfo(). */
|
|
297
|
+
stepInfo(step) {
|
|
298
|
+
if (!Number.isSafeInteger(step) || step < 0 || step >= this.steps.length) {
|
|
299
|
+
throw new RangeError(`step ${step} is outside [0, ${this.steps.length})`);
|
|
300
|
+
}
|
|
301
|
+
return RolePipeline.stepInfo(this.handle(), step);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Exact raw-input affine map predict(X) = X B_raw + b_raw of a fitted
|
|
305
|
+
* pipeline whose transformers / selectors are all affine and whose final
|
|
306
|
+
* model is affine (B_raw = A' B composed natively). The native refusal
|
|
307
|
+
* names the first non-affine step ("step <i> (<method id>): ...").
|
|
308
|
+
*/
|
|
309
|
+
inputAffineCoefficients() {
|
|
310
|
+
const m = getModule();
|
|
311
|
+
const handle = this.handle();
|
|
312
|
+
const dims = m._malloc(16);
|
|
313
|
+
try {
|
|
314
|
+
checkStatus(m.ccall("n4m_role_pipeline_n_features_in", "number", ["number", "number"], [handle, dims]));
|
|
315
|
+
checkStatus(m.ccall("n4m_role_pipeline_n_outputs", "number", ["number", "number"], [handle, dims + 8]));
|
|
316
|
+
const p = readI64(dims), q = readI64(dims + 8);
|
|
317
|
+
const coef = m._malloc(Math.max(1, p * q) * 8);
|
|
318
|
+
const icpt = m._malloc(Math.max(1, q) * 8);
|
|
319
|
+
try {
|
|
320
|
+
withContext((ctx) => checkStatus(m.ccall("n4m_role_pipeline_input_affine_coefficients_v1", "number", ["number", "number", "number", "i64", "number", "i64"], [ctx, handle, coef, BigInt(p * q), icpt, BigInt(q)]), ctx));
|
|
321
|
+
return {
|
|
322
|
+
coefficients: { data: m.HEAPF64.slice(coef / 8, coef / 8 + p * q), rows: p, cols: q },
|
|
323
|
+
intercept: m.HEAPF64.slice(icpt / 8, icpt / 8 + q),
|
|
324
|
+
nFeaturesIn: p,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
finally {
|
|
328
|
+
m._free(coef);
|
|
329
|
+
m._free(icpt);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
finally {
|
|
333
|
+
m._free(dims);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
295
336
|
/**
|
|
296
337
|
* One N4ME state per stateful step. A state that embeds training rows is
|
|
297
338
|
* refused unless allowTrainingRows is set.
|
|
@@ -408,6 +449,8 @@ export class RolePipeline {
|
|
|
408
449
|
containsTrainingRows: m.getValue(info + 20, "i32") !== 0,
|
|
409
450
|
nFeaturesIn: readI64(info + 24),
|
|
410
451
|
nFeaturesOut: readI64(info + 32),
|
|
452
|
+
affine: m.getValue(info + 40, "i32") !== 0,
|
|
453
|
+
columnAligned: m.getValue(info + 44, "i32") !== 0,
|
|
411
454
|
};
|
|
412
455
|
}
|
|
413
456
|
finally {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nirs4all/methods",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
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",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"build": "npm run clean && tsc -p .",
|
|
22
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/')\"",
|
|
23
23
|
"prepack": "npm run build && npm run stage:wasm",
|
|
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 && node test/run_multimodal_teaching.mjs && node test/run_explain.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 && node test/run_multimodal_teaching.mjs && node test/run_explain.mjs && node test/run_importance.mjs",
|
|
25
25
|
"test:shared-scoring": "node test/run_shared_scoring.mjs"
|
|
26
26
|
},
|
|
27
27
|
"license": "CECILL-2.1 OR AGPL-3.0-or-later",
|