/** * Core estimator contract shared by every model in the library. * * Every estimator must: * - accept a single props object in its constructor (positional overloads may * be kept for backwards compatibility, but the props form is canonical); * - implement `getParams()` returning exactly the props-object shape; * - be registered via `registerEstimator()` so it can be revived by * `loadModel()`. * * `setParams`, `clone`, `toJSON` and `loadModel` are then provided generically * by `BaseEstimator`. * * Serialization format: a versioned, JSON-safe envelope. Values that plain * JSON cannot express are wrapped in single-key tag objects ("$num", "$map", * "$set", "$typed", "$cls", "$undef", "$obj"). Class instances held in fitted * state (tree nodes, KD-trees, nested estimators, ...) must be registered with * `registerSerializableClass()` (estimators are registered automatically). */ export type Params = Record; export declare const MODEL_FORMAT = "@kanaries/ml-model"; export declare const MODEL_FORMAT_VERSION = 1; export interface SerializedModel { format: typeof MODEL_FORMAT; formatVersion: number; estimator: string; params: unknown; state: unknown; } type AnyCtor = new (...args: never[]) => object; export declare function registerSerializableClass(name: string, ctor: AnyCtor): void; export declare function registerEstimator(name: string, ctor: AnyCtor): void; export declare function getRegisteredEstimators(): ReadonlyMap; export declare function encodeValue(value: unknown): unknown; export declare function decodeValue(value: unknown): unknown; export declare abstract class BaseEstimator { /** * Return the constructor parameters of this estimator, using exactly the * key names accepted by the props-object constructor. Must reflect current * values (after any setParams), not the values passed at construction. */ abstract getParams(): Params; /** * Merge `params` into the estimator's parameters and reset it to the * unfitted state (the estimator is rebuilt through its constructor so all * validation logic reruns). Unknown keys throw. */ setParams(params: Params): this; /** * A new unfitted estimator with identical parameters. Nested estimators * inside params (meta-estimators: pipelines, search, ensembles) are * themselves cloned, so the copy shares no mutable estimator state. */ clone(): this; /** * Serialize the estimator (parameters + fitted state) to a JSON-safe * object. `JSON.stringify(model)` therefore produces a portable model * file; revive it with `loadModel()`. */ toJSON(): SerializedModel; /** Typed convenience wrapper around `loadModel` for a known class. */ static fromJSON(this: new (...args: never[]) => T, json: SerializedModel | string): T; } /** Revive any serialized estimator produced by `estimator.toJSON()`. */ export declare function loadModel(json: SerializedModel | string): BaseEstimator; export {};