FAU Erlangen-Nürnberg
Institute of Micro- and Nanostructure Research
By the end of this lecture you can:
notebooks/week13_ptychography.ipynb — forward model + ePIE with an overlap sweep; the same model reconstructed by autodiff gradient descent; a low-dose exercise with a TV prior in one line of the loss.

The four steps at scan position \(j\): (1) crop the object patch \(O_j(\mathbf{r})\); (2) multiply by the probe \(P(\mathbf{r})\) to form the exit wave; (3) FFT to the far field; (4) take \(|\cdot|^2\) to get the measured intensity. Steps 1–3 are reversible; step 4 is not — phase is lost.
\[I_j(\mathbf{k}) = \bigl|\mathcal{F}\bigl[P(\mathbf{r})\cdot O(\mathbf{r}-\mathbf{r}_j)\bigr]\bigr|^2\]
ePIE amplitude-consistency error vs iteration — output of week13_ptychography.ipynb (SEED=42, 40 iterations). Step 4 px (75 % overlap) → 0.0021; step 6 px (62 %) → 0.0067; step 8 px (50 %) → 0.0091. More overlap, lower error. Low error = self-consistent, not necessarily correct.
Left: the focused probe changes shape over tens of nm of defocus — comparable to the sample thickness (dashed box). Centre: the phase-object (SPA) model treats the whole specimen as one phase screen, \(\psi_{\text{exit}} = \psi_{\text{probe}}\,e^{i\sigma V}\). Right: multislice theory alternates transmission through thin slices \(V_n\) and Fresnel propagation \(p(\Delta z)\). Slide credit: D. Muller (M&M 2023), after Chen, Zhen et al. (2021), doi:10.1126/science.abg2533.

def forward(phi, probe, rows, cols):
O = torch.exp(1j * phi) # SPA: pure phase object (hard constraint |O| = 1)
exit_waves = probe * O[rows, cols] # probe x all object patches at once
return torch.abs(torch.fft.fft2(exit_waves)) # predicted diffraction amplitudes
phi = torch.zeros(N, N, requires_grad=True)
opt = torch.optim.Adam([phi], lr=0.02)
for it in range(200):
loss = ((forward(phi, probe, rows, cols) - meas_amps) ** 2).sum() # data fidelity
loss = loss + lam_tv * tv(phi) # prior: one extra line
opt.zero_grad(); loss.backward(); opt.step() # autograd does the calculusloss.backward() differentiates through the FFT and the modulus — no hand-derived update. Kandel, Saugat et al., (2019), doi:10.1364/OE.27.018653
week13_ptychography.ipynb.| after 200 passes | ePIE | autodiff GD |
|---|---|---|
| amplitude error | \(7.7\times10^{-4}\) | \(8.7\times10^{-5}\) |
| aligned phase RMS | \(1.7\times10^{-3}\) rad | \(2.9\times10^{-4}\) rad |
| wall time (CPU) | 4.5 s | 9.3 s |
| method | phase RMS [rad] |
|---|---|
| ePIE, 40 iterations | 0.094 |
| autodiff GD, \(\lambda_{TV}=0\) (200 it.) | 0.103 |
| autodiff GD, \(\lambda_{TV}=1\) | 0.080 |
| autodiff GD, \(\lambda_{TV}=8\) | 0.140 |

2-D toy with an exact prior (four Gaussian “structural variants”) and exact noised scores. We observe only \(x_1\) (a projection, \(H=[1\;0]\)); \(x_2\) lies in the null space of \(H\). Left: unconditional reverse diffusion reproduces the prior. Centre: exact posterior. Right: DPS samples. Generated by img/make_figures.py.
Low-dose HAADF image (centre) of four real atomic columns. A generative denoiser (right) recovers them but also invents a fifth (red arrow) — no basis in the ground truth (left). The prior places an atom where one “usually is”.
The WS 26/27 course arc: data, noise and honest learning (W1–4); representations and model families from trees to transformers (W5–10); knowing what we don’t know (W11); physics-based reconstruction (W12–13). Cross-cutting threads connect them.
The six levels of explainability Neuer, Michael et al., (2024), ordered from data to decision, with the weeks in which each level was taught. Explainability was not a separate topic: every model family came with its own explanation tool.
The four recurring trust failures: leakage (W4), shortcut learning (W7), miscalibration and out-of-distribution inputs (W11), hallucination (W13). All share one root cause: a statistical association or prior replaced the physical signal, and a single accuracy number could not reveal it.
_shared/exam_mustknow.md. For every week: core idea in one sentence, key equation, one EM application and one failure mode._shared/miniproject.md — options A–E.jupyter nbconvert --to notebook --execute your_notebook.ipynb must run end-to-end.notebooks/week13_ptychography.ipynb — exam_mustknow.md, miniproject.md, and the Ai4Mat companion notebooks.Material that did not fit the 90-minute lecture path — for self-study and questions.
Schematic dose–resolution trade-off for ADF-STEM (red) and ptychography (blue); y-axis inverted (higher = finer). In the low-dose regime both scale as \(d \propto 1/\sqrt{\text{dose}}\), but ptychography uses all scattered electrons and achieves better resolution at equal dose. At high dose ADF saturates at the probe-size limit; ptychography keeps improving because it deconvolves the probe. Chen, Zhen et al., (2021), doi:10.1126/science.abg2533
Decision table: classical regularisation (Tikhonov/TV) for well-understood physics and limited data; learned priors (GAN/diffusion) when a large dataset of similar specimens exists; physics-informed learning when governing equations are known and data are scarce. Combinations (physics + learned prior, e.g. DPS with a physical forward model) are the active research direction.
| Method | Question it answers | Works on | Week |
|---|---|---|---|
| Coefficients / partial dependence | How does the output change with a feature? | Linear / additive models | W4 |
| Permutation importance, SHAP Lundberg, Scott M. et al., (2017) | Which features matter, globally and per sample? | Any model | W5 |
| Saliency, Grad-CAM Selvaraju, Ramprasaath R. et al., (2017), occlusion | Which pixels drove this prediction? | CNNs (occlusion: any) | W7 |
| Latent-space maps, t-SNE/UMAP | What structure did the model find? (beware distances) | AEs / VAEs / embeddings | W9 |
| Attention maps | Where did the transformer look? (≠ why) | Transformers | W10 |
| Calibration, conformal, OOD gate | How sure — and is this input in-distribution? | Any predictor | W11 |
| Residuals, posterior ensembles, half-sets | Is this reconstruction supported by the data? | Inverse problems | W12–13 |

©Philipp Pelz - FAU Erlangen-Nürnberg - Data Science for Electron Microscopy