@nirs4all/methods 1.2.1 → 1.3.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/n4m.wasm CHANGED
Binary file
@@ -0,0 +1,114 @@
1
+ import { MethodResult } from "./methodResult.js";
2
+ type ExactInteger = bigint | number;
3
+ export type SearchAxis = {
4
+ kind: "int" | "log_int";
5
+ low: ExactInteger;
6
+ high: ExactInteger;
7
+ step?: ExactInteger;
8
+ } | {
9
+ kind: "float" | "log_float";
10
+ low: number;
11
+ high: number;
12
+ step?: number;
13
+ } | {
14
+ kind: "categorical";
15
+ type: "string";
16
+ choices: readonly string[];
17
+ } | {
18
+ kind: "categorical";
19
+ type: "integer";
20
+ choices: readonly ExactInteger[];
21
+ } | {
22
+ kind: "categorical";
23
+ type: "float";
24
+ choices: readonly number[];
25
+ } | {
26
+ kind: "categorical";
27
+ type: "boolean";
28
+ choices: readonly boolean[];
29
+ } | {
30
+ kind: "ordinal";
31
+ choices: readonly number[];
32
+ } | {
33
+ kind: "sorted_tuple";
34
+ length: number;
35
+ low: number;
36
+ high: number;
37
+ integer?: boolean;
38
+ };
39
+ export interface SearchConstraint {
40
+ kind: "mutex_group" | "requires" | "exclude" | "condition_in" | "condition_not_in";
41
+ refs: readonly string[];
42
+ labels?: readonly (string | null)[];
43
+ }
44
+ export interface OptimizerOptions {
45
+ sampler?: "random" | "sobol" | "lhs" | "ternary" | "ga" | "pso" | "cmaes" | "tpe" | "gp_ei";
46
+ pruner?: "none" | "median" | "asha" | "hyperband" | "racing";
47
+ direction?: "auto" | "minimize" | "maximize";
48
+ evalMode?: "best" | "mean" | "robust_best";
49
+ metric?: "rmse" | "mse" | "mae" | "r2" | "accuracy" | "balanced_accuracy" | "f1" | "logloss";
50
+ liar?: "none" | "min" | "mean" | "max";
51
+ startupTrials?: number;
52
+ seed?: ExactInteger;
53
+ timeoutSeconds?: number;
54
+ maxResource?: number;
55
+ reductionFactor?: number;
56
+ }
57
+ export type TrialValue = number | bigint | string | boolean | readonly (number | bigint)[];
58
+ export interface OptimizerTrial {
59
+ id: bigint;
60
+ parameters: Readonly<Record<string, TrialValue>>;
61
+ rung: number;
62
+ status: "running" | "completed" | "pruned" | "failed" | "cancelled";
63
+ }
64
+ export interface BatchResult {
65
+ trials: readonly OptimizerTrial[];
66
+ /** Nonzero only when native ask_batch committed a prefix before an error. */
67
+ nativeStatus: number;
68
+ }
69
+ export interface OptimizerTrialRecord extends OptimizerTrial {
70
+ readonly active: Readonly<Record<string, boolean>>;
71
+ readonly score: number | null;
72
+ readonly askSequence: bigint;
73
+ readonly terminalSequence: bigint | null;
74
+ readonly intermediates: readonly {
75
+ sequence: bigint;
76
+ step: number;
77
+ score: number;
78
+ shouldPrune: boolean;
79
+ }[];
80
+ readonly error: {
81
+ code: string;
82
+ message: string;
83
+ retryable: boolean;
84
+ } | null;
85
+ }
86
+ /** Owns a native optimizer and its context. Dispose it after use. */
87
+ export declare class Optimizer {
88
+ private _ptr;
89
+ private readonly context;
90
+ readonly space: Readonly<Record<string, SearchAxis>>;
91
+ private constructor();
92
+ static create(space: Readonly<Record<string, SearchAxis>>, options?: OptimizerOptions, constraints?: readonly SearchConstraint[]): Optimizer;
93
+ static load(blob: Uint8Array, space: Readonly<Record<string, SearchAxis>>): Optimizer;
94
+ private get handle();
95
+ private decodeTrial;
96
+ ask(): OptimizerTrial;
97
+ askBatch(n: number): BatchResult;
98
+ /** Queue numeric values; categorical axes use zero-based choice indices. */
99
+ enqueue(parameters: Readonly<Record<string, ExactInteger>>): void;
100
+ tell(trial: OptimizerTrial | ExactInteger, status: "completed" | "pruned" | "failed" | "cancelled", score?: number, error?: string): void;
101
+ intermediate(trial: OptimizerTrial | ExactInteger, step: number, score: number): boolean;
102
+ best(): {
103
+ trial: OptimizerTrial;
104
+ score: number;
105
+ };
106
+ /** Owning native rich trace v1 snapshot. Caller must destroy the result. */
107
+ trials(sinceId?: ExactInteger): MethodResult;
108
+ /** Decode an owning rich-trace snapshot to typed JS values. */
109
+ trialRecords(sinceId?: ExactInteger): readonly OptimizerTrialRecord[];
110
+ /** Portable N4MOPT bytes, directly readable by Python/R/native bindings. */
111
+ save(): Uint8Array;
112
+ dispose(): void;
113
+ }
114
+ export {};