PyramidDiff (WPP 2024)
A small conditional diffusion model (1D UNet, ~7.3M parameters) of single-age, sex-specific population structure. A pyramid is a (2 x 101) array of population shares, ages 0-100+.
Training run
quick run: 3000 optimisation steps.
What it can do
- Generate plausible pyramids from summary conditions (median age, % under 15, % 65+, sex ratio, year), with sampling-based uncertainty.
- Repair age heaping (digit preference at 0/5): start from a classical window-total-preserving smoothing (PCHIP), partially noise it, and denoise with the model while re-imposing the observed totals of 5-year windows (centred on the heaping digits) at every denoising step. The model therefore only decides the within-window shape.
- Inpaint missing ages (evaluated for one hidden 20-year span, below).
- Flag implausible pyramids via denoising error.
Training data
UN World Population Prospects 2024 (Medium variant), single-age population by sex, countries/areas, 1950-2023. WPP pyramids are modelled estimates, not raw census counts. Split by country: 80/10/10 train/validation/test. Projections for 2024-2100 were also used (training countries only); validation and test are purely historical. Source: United Nations, Department of Economic and Social Affairs, Population Division (2024). World Population Prospects 2024. https://population.un.org/wpp/ Check the UN terms of use for the data before reuse.
Evaluation: age-heaping repair (held-out test countries, 1702 pyramids; heaping is SIMULATED)
Mean absolute error of single-age shares, per mille of total population (lower is better):
| Method | MAE |
|---|---|
| Heaped input (no repair) | 1.687 |
| 5-point moving average + window projection (classical) | 0.128 |
| PCHIP window-total interpolation (classical) | 0.102 |
| PyramidDiff, raw-input start, one final projection | 0.119 |
| PyramidDiff, raw-input start, per-step projection | 0.099 |
| PyramidDiff, PCHIP start, per-step projection (default) | 0.096 |
On held-out countries the default PyramidDiff variant improves on the best classical baseline (0.096 vs 0.102 per mille). Mean Whipple index: truth 100, heaped 193, PCHIP 100, PyramidDiff default 100. Anomaly score AUROC (clean vs simulated-heaped): 1.000.
Evaluation: inpainting (held-out test countries, 1702 pyramids, ages 30-49 hidden in both sexes)
MAE on the hidden ages only, per mille of total population:
| Method | MAE |
|---|---|
| Hidden ages filled with the mean share | 1.486 |
| Linear interpolation of log-share across the gap | 0.341 |
| PyramidDiff inpainting | 0.752 |
PyramidDiff does not improve on linear interpolation for this hidden span. Other spans, and the conditioning used when ages are missing, were not tested.
Limitations
- Heaping was evaluated against a synthetic heaping process; real survey heaping differs (and varies by country, sex and age).
- Trained on smooth modelled estimates, so it will under-represent real-world irregularities (migration shocks, war, small populations).
- Repair assumes heaping moves people by at most 2 years; it cannot fix large age misreporting, or sex-specific selective omission.
- Research prototype. Not for official statistics or individual-level decisions.
Usage
from huggingface_hub import snapshot_download
import importlib.util, os
p = snapshot_download("SallySims/pyramiddiff-wpp2024")
spec = importlib.util.spec_from_file_location("pyramiddiff", os.path.join(p, "pyramiddiff.py"))
P = importlib.util.module_from_spec(spec); spec.loader.exec_module(P)
model, diff, norm = P.load_pretrained(p)
samples = P.generate(model, diff, norm, median_age=20, u15=0.42, p65=0.03, sex_ratio=99, year=2005)
- Downloads last month
- -