UNPKG

@astermind/astermind-elm

Version:

JavaScript Extreme Learning Machine (ELM) library for browser and Node.js.

105 lines (104 loc) 3.72 kB
export type Activation = 'tanh' | 'relu' | 'leakyrelu' | 'sigmoid' | 'linear' | 'gelu'; export type WeightInit = 'uniform' | 'xavier' | 'he'; export interface BaseConfig { /** Random feature width (hidden units) */ hiddenUnits: number; /** Activation function for hidden layer */ activation?: Activation; /** Ridge regularization factor λ (for (HᵀH + λI)) */ ridgeLambda?: number; /** Optional seed for deterministic initialization */ seed?: number; /** Logging options */ log?: { modelName?: string; verbose?: boolean; toFile?: boolean; level?: 'info' | 'debug'; }; logFileName?: string; /** Regularization */ dropout?: number; /** Weight initialization scheme */ weightInit?: WeightInit; /** Optional export file name for saved model */ exportFileName?: string; /** Optional metrics thresholds (if provided, training saves only when all pass) */ metrics?: { rmse?: number; mae?: number; accuracy?: number; f1?: number; crossEntropy?: number; r2?: number; [key: string]: number | undefined; }; /** (Optional) future toggle: 'classification' | 'regression' */ task?: 'classification' | 'regression'; } /** Numeric (vector) input configuration */ export interface NumericConfig extends BaseConfig { /** Input vector size (required for pure numeric workflows outside text mode) */ inputSize: number; /** Explicitly disable tokenizer for numeric mode */ useTokenizer?: false; /** Output categories (labels) */ categories: string[]; } /** Text input configuration */ export interface TextConfig extends BaseConfig { /** Enable tokenizer-based text mode */ useTokenizer: true; /** Output categories (labels) */ categories: string[]; /** Max sequence/token length for encoder */ maxLen: number; /** Allowed characters for char-mode encoders (if applicable) */ charSet?: string; /** Delimiter regex for tokenization */ tokenizerDelimiter?: RegExp; /** Optional prebuilt encoder instance */ encoder?: any; } /** Union config consumed by ELM */ export type ELMConfig = NumericConfig | TextConfig; export interface TrainOptions { task?: 'classification' | 'regression'; onProgress?: (phase: 'encode' | 'formH' | 'solve' | 'done', pct: number) => void; } export interface TrainResult { epochs: number; loss?: number; metrics?: { rmse?: number; mae?: number; accuracy?: number; [key: string]: number | undefined; }; } /** * Serialized form for save/load. * Note: tokenizerDelimiter is stored as a string (source) to be JSON-safe. */ export interface SerializedELM { config: (Omit<NumericConfig, 'seed' | 'log'> & Partial<Omit<TextConfig, 'encoder' | 'tokenizerDelimiter'>> & { tokenizerDelimiter?: string; }); W: number[][]; b: number[][]; B: number[][]; } export declare const defaultNumericConfig: Partial<NumericConfig>; export declare const defaultTextConfig: Partial<TextConfig>; export declare function isTextConfig(cfg: ELMConfig): cfg is TextConfig; export declare function isNumericConfig(cfg: ELMConfig): cfg is NumericConfig; /** * Normalize a user config with sensible defaults depending on mode. * (Keeps the original structural type, only fills in missing optional fields.) */ export declare function normalizeConfig<T extends ELMConfig>(cfg: T): T; /** * Rehydrate text-specific fields from a JSON-safe config * (e.g., convert tokenizerDelimiter source string → RegExp). */ export declare function deserializeTextBits(config: SerializedELM['config']): ELMConfig;