šŸ

ML-Math

Open Source
PythonPYTHON

ML Math

No description provided on GitHub.

Created
Feb 2026
Last Updated
Feb 2026
Stars
0 ⭐
Status
Available

mlmath — Mathematics for Machine Learning, Interactively

A terminal-based interactive learning tool covering the complete mathematics of machine learning, inspired by Marc Peter Deisenroth's "Mathematics for Machine Learning" (Cambridge University Press, 2020).


Features

  • 20 curriculum blocks — theory, formulas, derivations, worked examples, and code
  • 3-layer visualizations — ASCII (always), plotext terminal plots, matplotlib windows
  • Interactive exercises — beginner / intermediate / advanced, with hints and solutions
  • Progress tracker — marks blocks as completed, shown as a progress bar
  • Topic search — find any block by keyword

Quick Start

image image

1. Install dependencies

pip install -r requirements.txt

2. Run

cd mlmath
python main.py

Requirements

PackagePurpose
numpyCore numerical computing
scipySpecial functions, statistics
sympySymbolic math, LaTeX rendering
scikit-learnReference implementations & data
richTerminal UI (tables, markdown)
plotextTerminal-native plots (Layer 2)
matplotlibGUI plots in separate window (L3)

Curriculum Overview

#BlockTopics
01Linear AlgebraVectors, matrices, norms, SVD, PCA
02Matrix DecompositionsLU, QR, Cholesky, eigendecomposition
03Calculus & AutodiffGradients, Jacobians, Taylor, dual numbers
04OptimizationGD, Newton, Lagrange multipliers, convexity
05Probability TheoryDistributions, Bayes, MLE, conjugate priors
06StatisticsEstimators, CI, hypothesis tests, p-values
07Information TheoryEntropy, KL divergence, mutual information
08BackpropagationComputational graphs, chain rule, autograd
09Activation FunctionsReLU, Sigmoid, GELU, Swish, Mish
10Supervised LearningLinear/logistic regression, SVM, decision trees
11Bias-Variance TradeoffDecomposition, regularization, cross-validation
12Unsupervised LearningK-means, PCA, DBSCAN, autoencoders
13EM AlgorithmLatent variables, E/M steps, GMM
14Probabilistic MLBayesian inference, GPs, variational inference
15RL MathematicsMDPs, Bellman equations, Q-learning, policy gradient
16MDP SolversValue/policy iteration, dynamic programming
17Deep Learning MathAttention, batch norm, transformers, residuals
18NLP MathematicsTF-IDF, word2vec, BERT, BPE, BLEU
19Kernel MethodsMercer's theorem, SVM dual, kernel PCA, GPs
20Model EvaluationROC/AUC, calibration, AIC/BIC, stat tests

Project Structure

mlmath/
ā”œā”€ā”€ main.py                # Entry point — run this
ā”œā”€ā”€ config.py              # Colors, themes, settings
ā”œā”€ā”€ requirements.txt
│
ā”œā”€ā”€ blocks/                # 20 curriculum blocks
│   ā”œā”€ā”€ __init__.py        # BLOCKS registry
│   ā”œā”€ā”€ b01_linear_algebra.py
│   ā”œā”€ā”€ b02_matrix_decomp.py
│   │   ...
│   └── b20_model_evaluation.py
│
ā”œā”€ā”€ exercises/             # Interactive exercises
│   ā”œā”€ā”€ __init__.py        # all_exercises dict
│   ā”œā”€ā”€ ex01_linear_algebra.py
│   ā”œā”€ā”€ ex03_calculus.py
│   ā”œā”€ā”€ ex05_probability.py
│   ā”œā”€ā”€ ex08_backprop.py
│   ā”œā”€ā”€ ex10_supervised.py
│   ā”œā”€ā”€ ex12_unsupervised.py
│   ā”œā”€ā”€ ex15_rl.py
│   └── ex17_deep_learning.py
│
ā”œā”€ā”€ core/                  # Math utility library
│   ā”œā”€ā”€ linalg.py
│   ā”œā”€ā”€ calculus.py
│   ā”œā”€ā”€ optimization.py
│   ā”œā”€ā”€ probability.py
│   └── stats.py
│
ā”œā”€ā”€ ui/                    # Terminal UI components
│   ā”œā”€ā”€ colors.py
│   ā”œā”€ā”€ widgets.py
│   └── menu.py
│
└── viz/                   # 3-layer visualization
    ā”œā”€ā”€ ascii_plots.py     # Layer 1: always available
    ā”œā”€ā”€ terminal_plots.py  # Layer 2: plotext
    └── matplotlib_plots.py # Layer 3: GUI window

Navigation

Main Menu
  [1] Browse Curriculum Blocks  →  select 1-20 → full topic menu → topics
  [2] Practice Exercises        →  pick exercise set → attempt / hint / run
  [3] Search Topics             →  keyword search across all 20 blocks
  [4] Mark Block Complete       →  update progress bar
  [q] Quit

Within each block:

  • Topics listed as a numbered menu — pick any topic for theory + example + viz
  • [0] goes back to the previous menu

Within each exercise:

  • [h] show hint
  • [c] show starter code
  • [s] reveal full solution
  • [r] run solution and print output
  • [b] go back

Adding a New Block

  1. Create blocks/b21_your_topic.py with a run() function:
def run():
    topics = [("Topic Name", topic_fn), ...]
    while True:
        # print menu
        # dispatch by number
  1. Register in blocks/__init__.py:
from blocks.b21_your_topic import run as b21
BLOCKS.append(("Your Topic", b21, "Short description"))
  1. Add to main.py's BLOCK_META list and block_modules list.

Adding a New Exercise Set

  1. Create exercises/exXX_topic.py following the Exercise class pattern:
class Exercise:
    def __init__(self, title, difficulty, description, hint, starter_code, solution_code): ...

exercises = [Exercise(...), Exercise(...), Exercise(...)]  # 3 per set

def run(): ...
def _run_exercise(ex): ...
  1. Register in exercises/__init__.py:
from exercises.exXX_topic import run as exXX
all_exercises["XX"] = exXX

Reference


License

MIT License. Educational use encouraged.

Other Projects