Skip to main content
$$ % Define your custom commands here \newcommand{\bmat}[1]{\begin{bmatrix}#1\end{bmatrix}} \newcommand{\E}{\mathbb{E}} \newcommand{\P}{\mathbb{P}} \newcommand{\S}{\mathbb{S}} \newcommand{\R}{\mathbb{R}} \newcommand{\S}{\mathbb{S}} \newcommand{\norm}[2]{\|{#1}\|_{{}_{#2}}} \newcommand{\pd}[2]{\frac{\partial #1}{\partial #2}} \newcommand{\pdd}[2]{\frac{\partial^2 #1}{\partial #2^2}} \newcommand{\vectornorm}[1]{\left|\left|#1\right|\right|} \newcommand{\abs}[1]{\left|{#1}\right|} \newcommand{\mbf}[1]{\mathbf{#1}} \newcommand{\mc}[1]{\mathcal{#1}} \newcommand{\bm}[1]{\boldsymbol{#1}} \newcommand{\nicefrac}[2]{{}^{#1}\!/_{\!#2}} \newcommand{\argmin}{\operatorname*{arg\,min}} \newcommand{\argmax}{\operatorname*{arg\,max}} \newcommand{\dd}{\operatorname{d}\!} $$

Walkthrough

Eight short scripts that take the package apart one layer at a time, on synthetic data with a known answer.

This section runs wdm one layer at a time on synthetic data with a known answer: the model alone, a synthetic record with a hidden truth, the two estimation phases, the tape measure, the backtest, and the controller, first losing and then holding. Everything uses the package’s Python API, so it also serves as a guide to using wdm as a library. The theory behind each layer is in The model, Estimation and Control.

How to use it. From weight-dynamics/code, after Getting started:

cd weight-dynamics/code && uv run python walkthrough/01_model.py

The steps

Step What it shows Script CLI equivalent Runtime
1. The model A diet simulated at the prior: the early drop in water and gut content, slower tissue loss, adaptation 01_model.py none 1.6 s
2. Synthetic data Weigh-ins with noise, food logs, weekly waist readings, and the hidden truth 02_synthetic.py wdm demo 1.2 s
3. Phase 1: the scale’s noise Reading noise, steady-state gain and effective window, against the true noise 03_phase1.py wdm fit-noise 5.7 s
4. Phase 2: state and metabolism The joint fit: parameter recovery against the truth, what “shift” means, maintenance 04_phase2.py wdm filter 5.6 s
5. The waist tape The same fit with and without waist readings: the fat-mass interval and bias 05_waist.py wdm filter 7.6 s
6. The backtest 1- and 7-day forecasts against persistence, and their calibration 06_backtest.py wdm backtest 7.2 s
7. Planning Deadline and sustainable plans, the constraint check, an impossible deadline 07_plan.py wdm plan 14 s
8. Maintain Holding today’s tissue and a weight 3 lb below: intake near maintenance, a gentle correction 08_maintain.py wdm plan --mode maintain 8.5 s

Runtimes are wall-clock on a 20-thread desktop CPU, including Python and JAX start-up.