Bayesian Analysis Display (bumps-dream): LBCO, HRPT¶
This tutorial shows how to reopen the Bayesian project created in
ed-21.py and inspect the saved fit results without rerunning DREAM.
The project already contains posterior samples together with cached posterior density, pair, and predictive data, so the plots below are restored directly from disk.
🛠️ Import Library¶
import easydiffraction as ed
📂 Load Project¶
Download Project¶
The returned path points directly to the saved project directory with the completed Bayesian fit and persisted posterior samples and plot caches.
project_dir = ed.download_data(id=39, destination='projects')
Getting data...
Data #39: Bayesian Analysis (bumps-dream): LBCO, HRPT
✅ Data #39 downloaded and extracted to '../../../projects/ed-39/lbco_hrpt_bumps-dream'
Load Project¶
Loading restores the persisted fit state, posterior samples, and plot caches. No new fit is launched in this tutorial.
project = ed.Project.load(project_dir)
⚠️ Switching minimizer type removes these settings: • max_iterations
⚠️ Switching minimizer type adds these settings with defaults: • burn_in_steps=600 • initialization_method='latin_hypercube' • parallel_workers=0 • population_size=4 • random_seed=None • sampling_steps=3000 • thinning_interval=1
📊 Inspect Results¶
Display Structure¶
Render the La0.5Ba0.5CoO3 structure restored from the saved project.
project.display.structure(struct_name='lbco')
Structure 🧩 'lbco' (Atom view type: 'covalent')
wheel = zoom
right-drag = pan
Display Fit Results¶
The fit summary reports the committed point estimate, sampler settings, convergence diagnostics, and posterior parameter summaries from the saved Bayesian run.
project.display.fit.results()
⚙️ Settings used:
| Name | Value | Description | |
|---|---|---|---|
| 1 | sampling_steps | 10000 | Total sampler iterations per chain. |
| 2 | burn_in_steps | 2000 | Sampler iterations discarded as warm-up. |
| 3 | thinning_interval | 1 | Sampler thinning interval. |
| 4 | population_size | 4 | Number of chains or walkers. |
| 5 | parallel_workers | 0 | Worker count; 0 uses all available CPUs. |
| 6 | initialization_method | latin_hypercube | Sampler initialization method. |
| 7 | random_seed | None | Random seed; None uses a system-derived seed. |
📋 Bayesian fit results:
| Metric | Value | |
|---|---|---|
| 1 | 🧪 Sampler | dream |
| 2 | ✅ Overall status | success |
| 3 | 💬 Engine message | DREAM sampling completed |
| 4 | ⏱️ Fitting time (seconds) | 1637.83 |
| 5 | 📏 Goodness-of-fit (reduced χ²) | 1.29 |
| 6 | 📏 R-factor (Rf, %) | 5.65 |
| 7 | 📏 R-factor squared (Rf², %) | 4.91 |
| 8 | 📏 Weighted R-factor (wR, %) | 4.08 |
| 9 | 📉 Best log-posterior | -1157.00 |
| 10 | 📊 Convergence status | passed |
| 11 | 📊 Max r-hat | 1.004 |
| 12 | 📊 Min ess bulk | 7391.625 |
| 13 | 📊 Draws per chain | 10000 |
| 14 | 📊 Chains | 20 |
📈 Committed parameters:
| datablock | category | entry | parameter | units | start | value | s.u. | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | lbco | cell | length_a | Å | 3.8913 | 3.8913 | 0.0001 | 0.00 % ↓ | |
| 2 | hrpt | linked_phases | lbco | scale | 9.1329 | 9.1360 | 0.0291 | 0.03 % ↑ | |
| 3 | hrpt | peak | broad_gauss_u | deg² | 0.0817 | 0.0811 | 0.0066 | 0.70 % ↓ | |
| 4 | hrpt | peak | broad_gauss_v | deg² | -0.1169 | -0.1165 | 0.0048 | 0.35 % ↓ | |
| 5 | hrpt | instrument | twotheta_offset | deg | 0.6306 | 0.6304 | 0.0017 | 0.03 % ↓ |
• value = estimate written back to the project (best posterior sample)
• s.u. = standard uncertainty (one sigma), posterior standard deviation
• change = relative change from start, in %; ↑ = increase, ↓ = decrease
📊 Posterior distribution:
| datablock | category | entry | parameter | units | median | 95% CI | r-hat | ess bulk | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | lbco | cell | length_a | Å | 3.8913 | [3.8911, 3.8915] | 1.004 | 7458.0 | |
| 2 | hrpt | linked_phases | lbco | scale | 9.1329 | [9.0759, 9.1903] | 1.003 | 8472.0 | |
| 3 | hrpt | peak | broad_gauss_u | deg² | 0.0815 | [0.0687, 0.0945] | 1.004 | 7537.0 | |
| 4 | hrpt | peak | broad_gauss_v | deg² | -0.1168 | [-0.1261, -0.1075] | 1.004 | 7582.8 | |
| 5 | hrpt | instrument | twotheta_offset | deg | 0.6303 | [0.6269, 0.6336] | 1.004 | 7391.6 |
• 95% CI = 95% credible interval (2.5%-97.5%, asymmetric)
• r-hat = Gelman-Rubin diagnostic (good convergence: r-hat <= 1.01)
• ess bulk = bulk effective sample size (typically >= 400)
Display Correlations¶
The correlation matrix is restored from the saved project state.
project.display.fit.correlations()
Display Posterior Densities¶
The pair plot and one-dimensional posterior distributions now load from the persisted caches generated when the Bayesian fit was saved.
project.display.posterior.pairs()
project.display.posterior.distribution()
Display Posterior Predictive¶
The posterior predictive view reuses the cached predictive summary stored in the project rather than recalculating it on first display. It overlays the 95% credible interval propagated from the posterior samples.
project.display.posterior.predictive(expt_name='hrpt')
A zoomed view is useful for checking the propagated uncertainty in a narrow region of the diffraction pattern.
project.display.posterior.predictive(expt_name='hrpt', x_min=92, x_max=93)
💾 Save Project¶
project.save_as(dir_path='projects/ed_24_lbco_hrpt_bumps_dream')
Saving project 📦 'lbco_hrpt_bumps-dream' to '../../../projects/ed_24_lbco_hrpt_bumps_dream'
├── 📄 project.cif
├── 📁 structures/
│ └── 📄 lbco.cif
├── 📁 experiments/
│ └── 📄 hrpt.cif
├── 📁 analysis/
│ ├── 📄 analysis.cif
│ └── 📄 results.h5
└── 📁 reports/
└── 📄 lbco_hrpt_bumps-dream.html