@nirs4all/methods 1.3.16 → 1.3.17

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.
@@ -102,6 +102,12 @@ export declare abstract class NativeEstimator extends NativeMethod {
102
102
  fit(X: Matrix, y?: Matrix | Float64Array | ArrayLike<number>, inputs?: FitInputs): this;
103
103
  /** True when the fitted state embeds training rows (kernel PLS, GPR-PLS, LW-PLS, ...). */
104
104
  containsTrainingRows(): boolean;
105
+ /**
106
+ * Named diagnostics of the last fit (n4m_estimator_fit_result), for
107
+ * example the training loss history of a neural regressor; null when the
108
+ * method keeps none, including after fromN4me (diagnostics are not state).
109
+ */
110
+ fitResult(): Record<string, ProcedureOutput> | null;
105
111
  /**
106
112
  * Portable fitted state (N4ME bytes), readable by every n4m binding. A
107
113
  * state that embeds training rows (containsTrainingRows()) is refused
@@ -340,6 +340,36 @@ export class NativeEstimator extends NativeMethod {
340
340
  m._free(out);
341
341
  }
342
342
  }
343
+ /**
344
+ * Named diagnostics of the last fit (n4m_estimator_fit_result), for
345
+ * example the training loss history of a neural regressor; null when the
346
+ * method keeps none, including after fromN4me (diagnostics are not state).
347
+ */
348
+ fitResult() {
349
+ const m = getModule();
350
+ const handle = this.handle();
351
+ const out = m._malloc(8);
352
+ try {
353
+ m.setValue(out, 0, "i32");
354
+ const status = m.ccall("n4m_estimator_fit_result", "number", ["number", "number"], [handle, out]);
355
+ if (status === 10)
356
+ return null; // N4M_ERR_UNSUPPORTED: no fit diagnostics
357
+ checkStatus(status);
358
+ const result = m.getValue(out, "i32");
359
+ checkStatus(m.ccall("n4m_method_result_entry_count", "number", ["number", "number"], [result, out]));
360
+ const count = m.getValue(out, "i32");
361
+ const entries = {};
362
+ for (let i = 0; i < count; ++i) {
363
+ checkStatus(m.ccall("n4m_method_result_entry", "number", ["number", "number", "number", "number"], [result, i, out, out + 4]));
364
+ const name = m.UTF8ToString(m.getValue(out, "i32"));
365
+ entries[name] = readEntry(result, name, m.getValue(out + 4, "i32"));
366
+ }
367
+ return entries;
368
+ }
369
+ finally {
370
+ m._free(out);
371
+ }
372
+ }
343
373
  /**
344
374
  * Portable fitted state (N4ME bytes), readable by every n4m binding. A
345
375
  * state that embeds training rows (containsTrainingRows()) is refused
@@ -2257,6 +2257,54 @@ export declare class SOPLS extends NativeEstimator implements Regressor {
2257
2257
  constructor(params?: SOPLSParams);
2258
2258
  predict(X: Matrix): Matrix;
2259
2259
  }
2260
+ /** Parameters of MultibranchRegressor; unset values take the native defaults. */
2261
+ export interface MultibranchRegressorParams {
2262
+ /** Default []. */
2263
+ branch_kinds?: number[];
2264
+ /** Default []. */
2265
+ branch_shapes?: number[];
2266
+ /** Default 4. */
2267
+ filters?: number;
2268
+ /** Default 5. */
2269
+ kernel_size?: number;
2270
+ /** Default 2. */
2271
+ pool_size?: number;
2272
+ /** Default 8. */
2273
+ embedding_dim?: number;
2274
+ /** Default 8. */
2275
+ head_hidden?: number;
2276
+ /** Default 100. */
2277
+ epochs?: number;
2278
+ /** Default 16. */
2279
+ batch_size?: number;
2280
+ /** Default 0.01. */
2281
+ learning_rate?: number;
2282
+ /** Default 0.0001. */
2283
+ weight_decay?: number;
2284
+ /** Optional: unset by default. */
2285
+ seed?: number;
2286
+ }
2287
+ /** Native `models.neural.multibranch_regressor` (transformer, regressor). */
2288
+ export declare class MultibranchRegressor extends NativeEstimator implements Regressor, Transformer {
2289
+ readonly methodId = "models.neural.multibranch_regressor";
2290
+ readonly paramTypes: {
2291
+ readonly branch_kinds: "int_array";
2292
+ readonly branch_shapes: "int_array";
2293
+ readonly filters: "int";
2294
+ readonly kernel_size: "int";
2295
+ readonly pool_size: "int";
2296
+ readonly embedding_dim: "int";
2297
+ readonly head_hidden: "int";
2298
+ readonly epochs: "int";
2299
+ readonly batch_size: "int";
2300
+ readonly learning_rate: "double";
2301
+ readonly weight_decay: "double";
2302
+ readonly seed: "int";
2303
+ };
2304
+ constructor(params?: MultibranchRegressorParams);
2305
+ predict(X: Matrix): Matrix;
2306
+ transform(X: Matrix): Matrix;
2307
+ }
2260
2308
  /** Parameters of CPPLS; unset values take the native defaults. */
2261
2309
  export interface CPPLSParams {
2262
2310
  /** Default 2. */
@@ -3308,6 +3356,16 @@ export declare class BaselineCenter extends NativeEstimator implements Transform
3308
3356
  constructor(params?: BaselineCenterParams);
3309
3357
  transform(X: Matrix): Matrix;
3310
3358
  }
3359
+ /** Parameters of BlockRms; unset values take the native defaults. */
3360
+ export interface BlockRmsParams {
3361
+ }
3362
+ /** Native `preprocessing.scaling.block_rms` (transformer). */
3363
+ export declare class BlockRms extends NativeEstimator implements Transformer {
3364
+ readonly methodId = "preprocessing.scaling.block_rms";
3365
+ readonly paramTypes: {};
3366
+ constructor(params?: BlockRmsParams);
3367
+ transform(X: Matrix): Matrix;
3368
+ }
3311
3369
  /** Parameters of LogTransform; unset values take the native defaults. */
3312
3370
  export interface LogTransformParams {
3313
3371
  /** Default 0. */
@@ -1689,6 +1689,35 @@ export class SOPLS extends NativeEstimator {
1689
1689
  }
1690
1690
  }
1691
1691
  NativeMethod.register("models.multiblock.so_pls", SOPLS);
1692
+ /** Native `models.neural.multibranch_regressor` (transformer, regressor). */
1693
+ export class MultibranchRegressor extends NativeEstimator {
1694
+ methodId = "models.neural.multibranch_regressor";
1695
+ paramTypes = {
1696
+ branch_kinds: "int_array",
1697
+ branch_shapes: "int_array",
1698
+ filters: "int",
1699
+ kernel_size: "int",
1700
+ pool_size: "int",
1701
+ embedding_dim: "int",
1702
+ head_hidden: "int",
1703
+ epochs: "int",
1704
+ batch_size: "int",
1705
+ learning_rate: "double",
1706
+ weight_decay: "double",
1707
+ seed: "int",
1708
+ };
1709
+ constructor(params = {}) {
1710
+ super();
1711
+ this.params = { ...params };
1712
+ }
1713
+ predict(X) {
1714
+ return this.predictMatrix(X);
1715
+ }
1716
+ transform(X) {
1717
+ return this.transformMatrix(X);
1718
+ }
1719
+ }
1720
+ NativeMethod.register("models.neural.multibranch_regressor", MultibranchRegressor);
1692
1721
  /** Native `models.pls.cppls` (regressor). */
1693
1722
  export class CPPLS extends NativeEstimator {
1694
1723
  methodId = "models.pls.cppls";
@@ -2605,6 +2634,19 @@ export class BaselineCenter extends NativeEstimator {
2605
2634
  }
2606
2635
  }
2607
2636
  NativeMethod.register("preprocessing.scaling.baseline", BaselineCenter);
2637
+ /** Native `preprocessing.scaling.block_rms` (transformer). */
2638
+ export class BlockRms extends NativeEstimator {
2639
+ methodId = "preprocessing.scaling.block_rms";
2640
+ paramTypes = {};
2641
+ constructor(params = {}) {
2642
+ super();
2643
+ this.params = { ...params };
2644
+ }
2645
+ transform(X) {
2646
+ return this.transformMatrix(X);
2647
+ }
2648
+ }
2649
+ NativeMethod.register("preprocessing.scaling.block_rms", BlockRms);
2608
2650
  /** Native `preprocessing.scaling.log_transform` (transformer). */
2609
2651
  export class LogTransform extends NativeEstimator {
2610
2652
  methodId = "preprocessing.scaling.log_transform";
package/dist/n4m.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nirs4all/methods",
3
- "version": "1.3.16",
3
+ "version": "1.3.17",
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",
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",
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",