# MCMC proposal scales / MCMC 三种步长练习

Entirely simulated 30-observation data: y=1+2x+error, x/error independent standard normals, seed 42. The inference model fixes intercept 1 and error SD 1, with slope prior N(0,5²). It is a one-parameter normal posterior with an analytic reference; neither intercept nor variance is estimated. This deliberately simple target is not general Bayesian regression.

## Offline rerun / 离线复做

Extract into a fresh directory, retaining a reference copy of results/. From the package root:

```sh
python -m venv .venv
# macOS/Linux
source .venv/bin/activate
# Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python analyze.py
```

Dependency installation accesses a software repository; analysis itself is offline. Default output overwrites named files only under this package's results/. Python 3.11.11/macOS tested; Windows hardware untested.

The symmetric random-walk Metropolis proposals use SD .01, .35 and 3, start 0, same seed 42 in each setting. Each run has 5000 post-transition states; first 1000 discarded for the teaching comparison, leaving 4000 per setting. These settings are NOT independent multiple chains for convergence diagnosis; do not pool them as one posterior sample or compute a convergence claim from them.

chain-states.csv contains 15000 rows, with step_sd, iteration, state, accepted and retained. Rejected proposals repeat the previous state; they are retained, not deleted. Acceptance rate covers all 5000 transitions; summaries use the 4000 retained states and sample SD ddof=1. Their empirical quantiles need not approximate the posterior reliably when exploration is poor.

Check MCMC_SCALES_COMPLETED. Compare result.json and numeric CSVs, not SVG/PNG bytes. results/summary.csv contains each setting's estimates; result.json also gives the analytic posterior mean/SD/quantiles and fixed model parameters.

```sh
python analyze.py --seed 7 --output-dir exercise-seed-7
python analyze.py --iterations 10000 --discard 2000 --output-dir exercise-longer
```

The --seed option changes BOTH simulated data and proposal RNG. Longer runs with an unchanged seed preserve the same data and target. Require 0<=discard<iterations; a longer run or discarded prefix is not a convergence guarantee.

## Interpretation / 解释

Small steps can accept frequently while moving slowly; large steps can be rejected frequently. Compare trace, mean, spread and empirical quantiles against the analytic target. A mean near the analytic value does not establish correct spread or convergence. This package does not report R-hat/ESS as though these three correlated settings were independent diagnostic chains. Formal work needs appropriately initialized independent chains and diagnostics.

三种设置使用相同seed，不是独立收敛诊断链；不要拼接。拒绝后的重复状态必须保留。改变seed同时改变数据和提议随机数；固定seed只增加迭代次数，数据与后验目标不变。舍前1000仅为本次教学比较，不是warmup/收敛证明。所有数字是实际独立程序输出，不是模型自动完成或真人课堂效果证据。

Files: analyze.py, requirements.txt, this README, results/simulated-data.csv, chain-states.csv, summary.csv, result.json, analysis.log and SVG/PNG. No external paper, research data, software binary or account is bundled.
