Javascript mathematics
May 25, 2016 — August 2, 2022
Libraries for browser-based mathematics, e.g. for browser-based machine learning.
I am no longer active in this area, and my information is definitely somewhat stale. You might want to check Google for the latest. In particular, I suspect that hardcore use cases for math in the browser now use WebAssembly or other faster technologies, rather than attempting to use this horrible language to do numerics as many of the below options do.
1 Probabilistic Calculators
Guestimate and Squiggle are two probabilistic calculators that can be used to estimate the uncertainty in a calculation, and are implemented in JavaScript.
2 Arquero
uwdata/arquero: Query processing and transformation of array-backed data tables.
3 Simple Statistics
See simple-statistics.
4 ml-matrix
ml-matrix (source) is used in some recent things. The API looks clean and sufficient for many classic ML tasks.
5 math.js
math.js supports some useful matrix operations, and seems popular.
6 math.gl
Welcome to math.gl! math.gl is a JavaScript math library focused on geospatial and 3D use cases, designed as a composable, modular toolbox. math.gl provides a core module with classic vector and matrix classes, and a suite of optional modules implementing various aspects of geospatial and 3D math.
While the math.gl is highly optimized for use with the WebGL and WebGPU APIs, math.gl itself has no WebGL dependencies.
Backed by Uber, this may survive longer than some other options.
7 glMatrix
8 ML.js
The LORIA ML.js tools lalolib/ mlweb (source).
MLweb is an open-source project that aims at bringing machine learning capabilities to web pages and web applications. See the official website for more information.
MLweb includes the following three components:
- ML.js: a JavaScript library for machine learning
- LALOLib: a JavaScript library for scientific computing (linear algebra, statistics, optimization)
- LALOLab: an online Matlab-like development environment (try it at http://mlweb.loria.fr/lalolab/)
They implement impressive functionality and even include native support for worker threads and concurrency. However… it is lacking modern web wrappings such as npm packaging etc., so is not convenient to use from e.g. webpack. The source code repository is not anywhere obvious so I’m not sure how current the code is.
9 Pyodide
Python from the browser, including mathematical libraries.
HT Emma Krantz.
10 jStat
jStat is a statistical library written in JavaScript that allows you to perform advanced statistical operations without the need for a dedicated statistical language (e.g. MATLAB or R). Includes a tidy linear algebra library, but could be better optimised.
11 lmfit
lmfit is a JavaScript (emscripten) port of lmfit, a “self-contained C library for Levenberg-Marquardt least-squares minimization and curve fitting.”
Currently, only linear curve fitting is implemented.
12 linalg
linalg uses native arrays because of their speed.
I needed a performance-focused linear algebra module for visualising data in 10+ dimensions, and implementing machine learning algorithms. I quickly learned that naive solutions to linear algebra operations can produce numerical errors so significant they are utterly useless for anything other than casual playtime. After that, I prioritized correctness over performance.
Untouched since released and small community, which is sad because the code looks solid.
13 Incoming
numeric looks polished but has been untouched for 2 yearsjmat a complex and quaternion matrix library.random variables can be simulated easily using the probability distributions library- nerdamer is a symbolic math library for JavaScript (!)
weblas does GPU-accelerated mathematics and is used in hip projects such as keras-js.ndarray also used in keras-js.linear-algebra (blog post)sylvester the original, but predates much modern optimisation such as native arrays and WebAssembly