UNPKG

svd.ts

Version:

A lightweight, isomorphic TypeScript implementation for computing Singular Value Decomposition (SVD) of matrix in Node.js and browsers.

25 lines (24 loc) 768 B
/** Result of SVD computation */ export type SVDResult = { /** (m, k) left singular vectors */ U: number[][]; /** (k) singular values */ S: number[]; /** (k, n) right singular vectors */ V: number[][]; }; /** Power iteration to find top k singular vectors/values */ export declare function computeSVD(options: { /** (m, n) input matrix */ A: number[][]; /** number of singular values/vectors to compute */ k: number; /** default: 100 */ maxIterations?: number; /** default: 1e-6 */ convergenceThreshold?: number; /** default: 'one' */ initialVector?: 'one' | 'random'; }): SVDResult; /** A ≈ U * S * V^T (rank-k truncated SVD) */ export declare function reconstructFromSVD(svd: SVDResult): number[][];