@astermind/astermind-elm
Version:
JavaScript Extreme Learning Machine (ELM) library for browser and Node.js.
58 lines (57 loc) • 2.32 kB
TypeScript
import { ELM } from '../core/ELM';
import { ELMConfig, Activation } from '../core/ELMConfig';
export type ConfidenceLabel = 'low' | 'high';
export interface ConfidenceClassifierOptions {
/** Class names to use (default: ['low','high']) */
categories?: [ConfidenceLabel, ConfidenceLabel] | string[];
/** Activation for hidden units (default: 'relu') */
activation?: Activation;
/** Verbose console logs */
verbose?: boolean;
/** Export filename for saved JSON (optional) */
exportFileName?: string;
}
/**
* ConfidenceClassifierELM is a lightweight wrapper that classifies whether
* an upstream model’s prediction is "low" or "high" confidence based on
* (embedding, metadata) numeric features.
*/
export declare class ConfidenceClassifierELM {
private baseConfig;
private elm;
private categories;
private activation;
constructor(baseConfig: ELMConfig, opts?: ConfidenceClassifierOptions);
/** One-hot helper */
private oneHot;
/**
* Train from numeric (vector, meta) → combined features + labels.
* `vectors[i]` and `metas[i]` must be aligned with `labels[i]`.
*/
train(vectors: number[][], metas: number[][], labels: string[]): void;
/** Predict full distribution for a single (vec, meta). */
predict(vec: number[], meta: number[], topK?: number): Array<{
label: string;
prob: number;
}>;
/** Probability the label is "high" (or the second category by default). */
predictScore(vec: number[], meta: number[], positive?: string): number;
/** Predicted top-1 label. */
predictLabel(vec: number[], meta: number[]): string;
/** Batch prediction (distributions). */
predictBatch(vectors: number[][], metas: number[][], topK?: number): Array<Array<{
label: string;
prob: number;
}>>;
/** Compute accuracy and confusion counts for a labeled set. */
evaluate(vectors: number[][], metas: number[][], labels: string[]): {
accuracy: number;
confusion: Record<string, Record<string, number>>;
};
loadModelFromJSON(json: string): void;
saveModelAsJSONFile(filename?: string): void;
/** Access underlying ELM if needed */
getELM(): ELM;
/** Current category ordering used by the model */
getCategories(): string[];
}