Math & Algorithms

This section covers the theory and Python implementation behind a wide range of math and algorithm topics, including recommender systems, graph theory, linear algebra, quantum computing, and marketing statistics models.

[2020-05-30] : Moved the blog posts to this site.

[2026-05-01] : Removed several outdated articles.

[2026-11-01] : Decided to rewrite and republish the removed articles.

Articles are grouped by their last update year, newest first.

2026

[Graph theory] Heat kernels and diffusion on graphs

Describe heat transfer along graph edges using a Laplacian and matrix exponential. Derive a heat-kernel solution for three vertices and use Python to check heat conservation, convergence to the mean, and eigenvalue-dependent decay. Vary the weight of an edge joining two groups and compare spectral gaps with diffusion rates.

[Graph theory] Graph diffusion and Personalized PageRank

Explain graph diffusion as a weighted sum of random walks of different lengths. Derive Personalized PageRank (PPR) from walks with restarts and compare a three-vertex hand calculation with a sparse Python implementation. Examine restart probabilities and starting distributions, then compare diffusion weighted by geometric and Poisson distributions.

[Across fields] Why does the Rayleigh quotient appear from PCA to quantum mechanics?

Derive the Rayleigh quotient as a weighted average of eigenvalues and find its maximum and minimum. Explain why maximizing projected variance in PCA and minimizing ground-state energy in quantum mechanics share the same form. Use Python with two-dimensional data and a two-level system to plot how direction and relative phase change the quotient.

[Across fields] Why is the exponential family important in statistics and machine learning?

Derive statistical and machine-learning calculations from the common exponential-family form. Use Bernoulli, Poisson, and normal distributions to connect log-partition derivatives, sufficient statistics, and maximum likelihood. Compute beta-prior updates and logistic regression in Python, and distinguish convexity of the loss from the existence of a finite estimate.

[Across fields] Why does the Poisson equation appear in semiconductors, heat, fluids, and gravity?

Derive the Poisson equation in semiconductor electrostatics, heat transfer, fluids, and gravity using gradients and divergence. Compare source signs and boundary conditions for electric potential, steady temperature, pressure, and gravitational potential. Use Python to compare one-dimensional finite-difference solutions and errors, then check that a two-dimensional pressure correction removes velocity divergence on a periodic domain.

[Across fields] Why do eigenvalue problems appear in PCA, vibrations, quantum mechanics, and graphs?

Derive why eigenvalue problems appear in PCA, vibration analysis, quantum mechanics, and graphs from optimization and time-evolution equations. Use small examples to show eigenvalues as variances, squared angular frequencies, energies, and variation across edges. Compute principal components, vibration modes, a two-state system, and graph partitions in Python, checking residuals and conservation laws.

[Across fields] What does least squares do in physics, statistics, and machine learning?

Derive the normal equations shared by least-squares methods and compare their roles in physics, statistics, and machine learning. Estimate a spring constant from artificial measurements, examine precision-weighted estimation and maximum likelihood with normal errors, then use Python polynomial regression to choose Ridge regularization on validation data and evaluate predictions on unseen data.

[Graph theory] The Fiedler vector and spectral clustering

Derive why Fiedler vectors help partition graphs using the Laplacian quadratic form and a continuous relaxation of RatioCut. Check eigenvalues and sign-based partitions on four vertices, then develop spectral clustering with a normalized Laplacian. Use Python to partition two-moons data and compare the result with ordinary K-means.

[Graph theory] What do graph Laplacian eigenvalues mean?

Explain the eigenvalues of an undirected graph Laplacian through squared differences across edges. Use a three-vertex hand calculation and Python to check that the number of zero eigenvalues equals the number of connected components. Vary the weight of an edge joining two vertex groups and compare the second eigenvalue, eigenvectors, and diffusion decay rates to show why weak connections slow heat transfer.

[Linear algebra] Understanding least squares as a projection

Explain least squares as the orthogonal projection of an observation vector onto a column space. Derive the normal equations from projection onto a line and check that the projection matrix is symmetric and idempotent. Compare a three-point regression by hand and in Python, plot residual orthogonality, and examine QR factorization and repeated columns with nonunique coefficients.

[Linear algebra] Deriving OLS from maximum likelihood

Derive ordinary least squares (OLS) from maximum likelihood under independent normal errors with equal variance. Obtain the normal equations from the log-likelihood and work through a four-point regression by hand. Use Python, plots, and repeated simulations to compare OLS with numerical optimization, relate residual sums of squares to likelihood, and distinguish maximum-likelihood and unbiased variance estimates.

[Generalized linear models] Deriving GLMs from the exponential family

Derive generalized linear models (GLMs) from the exponential family. Differentiate the normalization condition to obtain means and variances, and compare normal, Bernoulli, and Poisson distributions. Derive iteratively reweighted least squares (IRLS) from maximum likelihood with a canonical link, implement Poisson regression on artificial data in Python, and check the result against SciPy optimization.

[Generalized linear models] What is a canonical link?

A canonical link makes the linear predictor of a generalized linear model equal to its natural parameter. Derive the identity, logit, and log links from normal, Bernoulli, and Poisson distributions, and plot their relations to the mean. Estimate regression coefficients by maximum likelihood in Python, explain why the gradient and Hessian simplify, and compare with a probit link.

[Linear algebra] Why does the condition number describe numerical difficulty?

Explain how a matrix condition number affects the accuracy of a linear-system solution. Keep the matrix fixed, perturb the right-hand side, and derive a bound on relative error amplification. Use Python to examine singular values, ellipses, error directions, and inaccurate solutions with small residuals, while distinguishing problem conditioning from algorithm stability.

[Linear algebra] Why are Hilbert matrices difficult for computers?

A Hilbert matrix has an inverse, yet small input errors can greatly change the solution of a linear system. Use an integral to prove invertibility and the condition number to explain error amplification. Compare residuals and solution errors in Python, and plot the difference between rebuilding inputs at high precision and reusing inputs rounded to double precision.

[Numerical computing] Examples of Newton’s method failing to converge in Python

Reproduce three failures of Newton’s method in Python: iterates that alternate between zero and one, iterates whose absolute values double, and an update blocked by a zero derivative. Explain each with update formulas and plots. Compare different starting points and Brent’s method, checking residuals and stopping reasons as well as final values.

[Numerical computing] Why does Newton’s method converge quadratically?

Derive why Newton’s method converges at least quadratically near a simple root using tangent lines and a Taylor expansion. Compute a square root in Python to check error reduction, error ratios, and convergence order. Compare slower convergence at a multiple root and failure to converge from some starting points, and use plots to show the accuracy limit caused by rounding errors.

2024

2023

[Marketing] RFM Analysis

Introduces RFM analysis and demonstrates generating dummy purchase data with Faker and Poisson/Gamma distributions, stored in SQLite via Python's sqlite3 module.

2022

[Linear Algebra] Neumann Series

Explains the Neumann series, its convergence condition, and how it approximates matrix inverses like (I - aA)^{-1}, with a Python implementation example.

[Linear Algebra] Spectral Decomposition

Derives the spectral decomposition of symmetric matrices from eigenvalues and eigenvectors, relates it to SVD, and gives a Python implementation example.

[Linear Algebra] Useful Formulas

Compiles useful matrix formulas from the Matrix Cookbook covering transpose, trace, determinant, differentiation, and the Woodbury inversion identity.

[Linear Algebra] Cofactor Expansion

Explains matrix cofactors and cofactor expansion with worked examples, and implements determinant calculation via cofactors in Python.

2021

[Linear Algebra] Rayleigh Quotient

Explains properties of the Rayleigh quotient for symmetric matrices, proves its max/min via Lagrange multipliers, with a Python example.

[qiskit] HHL Algorithm

Reviews the classical conjugate gradient method for solving linear equations, then studies qiskit's HHL algorithm for quantum linear system solving.

[qiskit] Grover's Algorithm

Explains Grover's algorithm, which searches unsorted data in O(√N) time, describing amplitude amplification theory as a rotation operation in vector space.

[qiskit] Shor's Algorithm

Reviews how RSA cryptography works, then explains Shor's algorithm, which could break RSA by using order-finding to perform prime factorization on a quantum computer.

[qiskit] Quantum Phase Estimation

Explains the theory of quantum phase estimation, combining phase kickback with the inverse quantum Fourier transform, then implements it in qiskit using a T-gate example.

[qiskit] Quantum Fourier Transform

Reviews the classical discrete Fourier transform and then applies the same idea to quantum states, explaining the theory of the quantum Fourier transform with qiskit.

[qiskit] Simon's Algorithm

Explains Simon's algorithm, which determines whether a function is one-to-one or two-to-one and finds the period of a two-to-one function, following the math step by step.

[qiskit] Deutsch–Jozsa Algorithm

Explains the Deutsch-Jozsa algorithm, which determines with a single query whether a function is constant or balanced, following the underlying math step by step.

[qiskit] Arithmetic on two qubits

Explains how to represent two-qubit and three-qubit states using the tensor product, and covers the basics of multi-qubit gate operations in qiskit.

2020

[Recommender Systems] Matrix Factorization

Explains the formulation and optimization problem of matrix factorization in recommender systems, with an SVD implementation using movielens-100k.

[Recommender Systems] On Evaluation Methods

Explains evaluation methods for recommender systems, from accuracy metrics like precision and recall to offline and online evaluation, with Python examples.

[Recommender Systems] How to Use Surprise

Introduces the Surprise Python library for building recommender systems, covering its features and a matrix-factorization implementation example.