/** * Sequential Minimal Optimization solvers for kernel SVMs, following * libsvm's Solver / Solver_NU (Platt's SMO with Keerthi's maximal * violating pair working-set selection). * * Both solvers work on a binary problem with labels y in {+1, -1} and * return unsigned dual coefficients alpha plus an intercept b so that the * decision function is f(x) = sum_i alpha_i * y_i * K(x_i, x) + b. */ export type KernelType = 'linear' | 'rbf' | 'poly' | 'sigmoid'; export interface KernelConfig { kernel: KernelType; /** resolved numeric gamma ('scale'/'auto' must be resolved by the caller) */ gamma: number; degree: number; coef0: number; } /** * Resolve sklearn-style gamma: 'scale' = 1/(n_features * Var(X)) over ALL * entries of X, 'auto' = 1/n_features, numbers pass through. */ export declare function resolveGammaValue(gamma: number | 'scale' | 'auto', X: number[][]): number; export declare function kernelFunction(x1: number[], x2: number[], cfg: KernelConfig): number; /** * Row cache for the kernel matrix. Problems up to ~2000 samples keep the * full n^2 matrix in memory; larger ones fall back to a bounded FIFO row * cache so memory stays around 256MB worst case. */ export declare class KernelMatrix { readonly n: number; private X; private cfg; private rows; private maxRows; private diagonal; constructor(X: number[][], cfg: KernelConfig); diag(i: number): number; getRow(i: number): Float64Array; } export interface SMOSolution { /** unsigned dual coefficients (0 <= alpha_i); dual coef of sample i is alpha_i * y_i */ alpha: number[]; /** intercept: f(x) = sum_i alpha_i * y_i * K(x_i, x) + b */ b: number; iterations: number; converged: boolean; } /** * C-SVC dual: * min 1/2 a'Qa - e'a s.t. 0 <= a_i <= C, y'a = 0, Q_ij = y_i y_j K_ij */ export declare function solveCSVC(K: KernelMatrix, y: number[], C: number, tol: number, maxIter: number): SMOSolution; /** * nu-SVC dual (libsvm Solver_NU): * min 1/2 a'Qa s.t. 0 <= a_i <= 1, * sum_{y_i=+1} a_i = sum_{y_i=-1} a_i = nu * n / 2. * The working pair is always selected within one class so both equality * constraints stay satisfied. The returned alphas and b are already scaled * by 1/r (libsvm's post-solve normalization), matching sklearn's * dual_coef_ / intercept_ / decision_function conventions. */ export declare function solveNuSVC(K: KernelMatrix, y: number[], nu: number, tol: number, maxIter: number): SMOSolution; export interface SVRSolution { /** signed dual coefficients beta_i = alpha_i - alpha*_i; f(x) = sum_i beta_i K(x_i, x) + b */ coef: number[]; b: number; iterations: number; converged: boolean; } /** * epsilon-SVR dual (libsvm solve_epsilon_svr), as a 2n-variable C-problem: * variables z = [alpha; alpha*], labels y2 = [+1...; -1...], linear term * p_i = epsilon - y_i (alpha part) / epsilon + y_i (alpha* part), * bounds 0 <= z <= C, constraint sum(alpha) - sum(alpha*) = 0. */ export declare function solveEpsilonSVR(K: KernelMatrix, y: number[], C: number, epsilon: number, tol: number, maxIter: number): SVRSolution; /** * nu-SVR dual (libsvm solve_nu_svr): epsilon is replaced by the constraint * sum(alpha) + sum(alpha*) <= C * nu * n, handled by starting at * alpha_i = alpha*_i = min(remaining, C) with a total budget of C*nu*n/2 per * side and letting Solver_NU keep both per-class sums fixed. The linear term * is p_i = -y_i / +y_i. The effective tube width is epsilon = -r. */ export declare function solveNuSVR(K: KernelMatrix, y: number[], C: number, nu: number, tol: number, maxIter: number): SVRSolution & { epsilon: number; }; export interface OneClassSolution { /** unsigned dual coefficients; decision f(x) = sum_i alpha_i K(x_i, x) - rho */ alpha: number[]; rho: number; iterations: number; converged: boolean; } /** * One-class dual (Schölkopf, libsvm solve_one_class): * min 1/2 a'Ka s.t. 0 <= a_i <= 1, sum(a) = nu * n * (libsvm's scaling of the 0 <= a <= 1/(nu*n), sum(a) = 1 formulation by * nu*n — identical decision boundary, and matching sklearn's dual_coef_). * The equality constraint is fixed by the feasible starting point. */ export declare function solveOneClass(K: KernelMatrix, nu: number, tol: number, maxIter: number): OneClassSolution;