@nirs4all/methods 1.0.18 → 1.1.0

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/dist/index.d.ts CHANGED
@@ -4,6 +4,13 @@ export { Config } from "./config.js";
4
4
  export { Model, fitPls, predictPls, fitModel, predictModel, fitAom, fitAomChain, fitPop, fitAomRidge, fitAomStack, computeSplit, computeSplitIndices, type PlsModel, type FittedModel, type AomModel, type AomChainDescriptor, type AomChainModel, type PopModel, type AomRidgeOptions, type AomStackOptions, type SplitKind, type SplitOptions, type SplitIndices } from "./model.js";
5
5
  export { ppCreate, ppFit, ppTransform, ppGetState, ppSetState, ppDestroy, type PpOperator, } from "./preprocessing.js";
6
6
  export { MethodResult } from "./methodResult.js";
7
+ export { NativeModel } from "./nativeModel.js";
8
+ export { NativeEstimator, NativeMethod, NativeProcedure, manifest, methodClass, type Augmenter, type Classifier, type FitInputs, type Fold, type ParamType, type ParamValue, type ProbabilisticClassifier, type Procedure, type ProcedureOutput, type Regressor, type SampleFilter, type Selector, type Splitter, type TargetMixingAugmenter, type Transformer } from "./estimatorRoles.js";
9
+ export * from "./estimatorRolesGenerated.js";
10
+ export { splitNative, type NativeSplitterKind, type NativeSplitterOptions, type NativeSplitIndices } from "./nativeSplitter.js";
11
+ export { augmentNative, type NativeAugmentationKind } from "./nativeAugmentation.js";
12
+ export { NativePreprocessingPipeline, PipelineOperatorKind, type PipelineStep, } from "./nativePreprocessingPipeline.js";
13
+ export { selectSpa, selectVariables, selectorMethods } from "./selection.js";
7
14
  export { inspectN4mm, SERIALIZED_MODEL_INFO_SCHEMA_V1, SERIALIZED_MODEL_CAPABILITY_PREDICT, SERIALIZED_MODEL_CAPABILITY_TRANSFORM, SERIALIZED_MODEL_CAPABILITY_AFFINE, SERIALIZED_MODEL_CAPABILITY_PIPELINE, PipelineFingerprintAlgorithm, PipelineSemanticProfile, SerializedSavitzkyGolayMode, SerializedPipelineOperatorKind, type SerializedModelInfo, type SerializedPipelineInfo, } from "./serialization.js";
8
15
  export { Status, Dtype, Algorithm, Solver, Deflation, N4mError, type Matrix, } from "./types.js";
9
16
  /** ABI / project version reported by the loaded WASM module. */
package/dist/index.js CHANGED
@@ -16,6 +16,13 @@ export { Config } from "./config.js";
16
16
  export { Model, fitPls, predictPls, fitModel, predictModel, fitAom, fitAomChain, fitPop, fitAomRidge, fitAomStack, computeSplit, computeSplitIndices } from "./model.js";
17
17
  export { ppCreate, ppFit, ppTransform, ppGetState, ppSetState, ppDestroy, } from "./preprocessing.js";
18
18
  export { MethodResult } from "./methodResult.js";
19
+ export { NativeModel } from "./nativeModel.js";
20
+ export { NativeEstimator, NativeMethod, NativeProcedure, manifest, methodClass } from "./estimatorRoles.js";
21
+ export * from "./estimatorRolesGenerated.js";
22
+ export { splitNative } from "./nativeSplitter.js";
23
+ export { augmentNative } from "./nativeAugmentation.js";
24
+ export { NativePreprocessingPipeline, PipelineOperatorKind, } from "./nativePreprocessingPipeline.js";
25
+ export { selectSpa, selectVariables, selectorMethods } from "./selection.js";
19
26
  export { inspectN4mm, SERIALIZED_MODEL_INFO_SCHEMA_V1, SERIALIZED_MODEL_CAPABILITY_PREDICT, SERIALIZED_MODEL_CAPABILITY_TRANSFORM, SERIALIZED_MODEL_CAPABILITY_AFFINE, SERIALIZED_MODEL_CAPABILITY_PIPELINE, PipelineFingerprintAlgorithm, PipelineSemanticProfile, SerializedSavitzkyGolayMode, SerializedPipelineOperatorKind, } from "./serialization.js";
20
27
  export { Status, Dtype, Algorithm, Solver, Deflation, N4mError, } from "./types.js";
21
28
  /** ABI / project version reported by the loaded WASM module. */
@@ -22,6 +22,8 @@ export declare class MethodResult {
22
22
  matrix(name: string): Matrix;
23
23
  /** Read a named int32 vector. */
24
24
  vectorInt(name: string): Int32Array;
25
+ /** Read a named int64 vector without narrowing its elements to JS numbers. */
26
+ vectorInt64(name: string): BigInt64Array;
25
27
  /** Read a named scalar (returns NaN if not present). */
26
28
  scalar(name: string): number;
27
29
  destroy(): void;
@@ -73,7 +73,7 @@ export class MethodResult {
73
73
  m.stringToUTF8(name, namePtr, nameBytes + 1);
74
74
  const status = m.ccall("n4m_method_result_get_double_matrix", "number", ["number", "number", "number", "number", "number"], [this._ptr, namePtr, dataPtrPtr, rowsPtr, colsPtr]);
75
75
  checkStatus(status);
76
- const dataPtr = m.getValue(dataPtrPtr, "i32");
76
+ const dataPtr = m.getValue(dataPtrPtr, "i32") >>> 0;
77
77
  // i64 lo/hi pair — WASM_BIGINT=1 returns BigInt; use HEAP32 instead.
78
78
  const rows = m.getValue(rowsPtr, "i64");
79
79
  const cols = m.getValue(colsPtr, "i64");
@@ -116,6 +116,38 @@ export class MethodResult {
116
116
  m._free(sizePtr);
117
117
  }
118
118
  }
119
+ /** Read a named int64 vector without narrowing its elements to JS numbers. */
120
+ vectorInt64(name) {
121
+ const m = getModule();
122
+ const nameBytes = m.lengthBytesUTF8(name);
123
+ const namePtr = m._malloc(nameBytes + 1);
124
+ const dataPtrPtr = m._malloc(4);
125
+ const sizePtr = m._malloc(8);
126
+ try {
127
+ m.stringToUTF8(name, namePtr, nameBytes + 1);
128
+ const status = m.ccall("n4m_method_result_get_int64_vector", "number", ["number", "number", "number", "number"], [this._ptr, namePtr, dataPtrPtr, sizePtr]);
129
+ checkStatus(status);
130
+ const dataPtr = m.getValue(dataPtrPtr, "i32") >>> 0;
131
+ const size64 = BigInt(m.getValue(sizePtr, "i64"));
132
+ if (size64 < 0n || size64 > BigInt(Number.MAX_SAFE_INTEGER)) {
133
+ throw new RangeError(`Invalid int64 vector length for '${name}'.`);
134
+ }
135
+ const size = Number(size64);
136
+ if (dataPtr < 0 || size > Math.floor((m.HEAPU8.byteLength - dataPtr) / 8)) {
137
+ throw new RangeError(`Invalid int64 vector buffer for '${name}'.`);
138
+ }
139
+ const out = new BigInt64Array(size);
140
+ const view = new DataView(m.HEAPU8.buffer, m.HEAPU8.byteOffset + dataPtr, size * 8);
141
+ for (let i = 0; i < size; i += 1)
142
+ out[i] = view.getBigInt64(i * 8, true);
143
+ return out;
144
+ }
145
+ finally {
146
+ m._free(namePtr);
147
+ m._free(dataPtrPtr);
148
+ m._free(sizePtr);
149
+ }
150
+ }
119
151
  /** Read a named scalar (returns NaN if not present). */
120
152
  scalar(name) {
121
153
  const m = getModule();
package/dist/model.d.ts CHANGED
@@ -44,7 +44,10 @@ export interface FittedModel {
44
44
  * @param X row-major (n × p) input matrix.
45
45
  * @param Y row-major (n × q) target matrix.
46
46
  * @param n_components number of latent components (used by the PLS family).
47
- * @param params positional hyper-parameter vector for the model.
47
+ * @param params positional hyper-parameter vector for the model. For
48
+ * GroupSparsePLS this is `[group_lambda, ...group_assignment]`, with exactly
49
+ * one non-negative integer group ID per input feature; no implicit grouping
50
+ * is applied.
48
51
  */
49
52
  export declare function fitModel(model: string, X: Matrix, Y: Matrix, n_components: number, params?: number[]): FittedModel;
50
53
  /** Predict from a fitted {@link FittedModel} for new X (row-major n_new × p). */
package/dist/model.js CHANGED
@@ -106,7 +106,10 @@ export function predictPls(model, X_new) {
106
106
  * @param X row-major (n × p) input matrix.
107
107
  * @param Y row-major (n × q) target matrix.
108
108
  * @param n_components number of latent components (used by the PLS family).
109
- * @param params positional hyper-parameter vector for the model.
109
+ * @param params positional hyper-parameter vector for the model. For
110
+ * GroupSparsePLS this is `[group_lambda, ...group_assignment]`, with exactly
111
+ * one non-negative integer group ID per input feature; no implicit grouping
112
+ * is applied.
110
113
  */
111
114
  export function fitModel(model, X, Y, n_components, params = []) {
112
115
  if (X.rows !== Y.rows) {
@@ -134,7 +137,7 @@ export function fitModel(model, X, Y, n_components, params = []) {
134
137
  coefsBuf.ptr, xmBuf.ptr, ymBuf.ptr, interBuf.ptr,
135
138
  hasInterBuf, 0]);
136
139
  checkStatus(status);
137
- // Only models with a genuine affine intercept (currently Ridge) report
140
+ // Only models with a genuine affine intercept (Ridge and MBPLS) report
138
141
  // has_intercept=1; the PLS/PCR family and the PLS-based Tier-B fits
139
142
  // predict via the centred form and carry no intercept (kept null so a
140
143
  // caller never adds a misleading zero/y_mean term to x.B).
@@ -176,7 +179,7 @@ export function predictModel(model, X_new) {
176
179
  // AOM-PLS (and any future affine model) carries input-space coefficients +
177
180
  // a genuine intercept and zero means — it predicts on RAW X via the
178
181
  // explicit-intercept form pred = intercept + x.B. Every centred model
179
- // (PLS family + the Tier-B fits, including Ridge) carries intercept = null
182
+ // (PLS family + centred Tier-B fits) carries intercept = null
180
183
  // and predicts via pred = y_mean + (x - x_mean).B. The C helper picks the
181
184
  // form from whether the intercept pointer is non-NULL.
182
185
  const useIntercept = model.intercept !== null;