FAU Erlangen-Nürnberg
Institute of Micro- and Nanostructure Research
By the end of this lecture you can:
Supervised
Unsupervised
Self-supervised
This is CRISP-DM phases 3–6, mapped onto ML terminology.
(ny, nx). Heavy atoms bright.(ny, nx, ky, kx).(ny, nx, E).(n_tilt, ny, nx).
Every EM number passes through five links. Noise and systematic errors enter at each link (red); the last link — metadata — decides whether the number can be interpreted at all.

Scintillator + CCD/CMOS (indirect)
Direct electron detector (DED)
Gaussian noise (thermal / readout)
Poisson noise (shot / counting)

np.random.poisson(lam = dose_scale * phantom).Photon-transfer (variance–mean) plot of a simulated Poisson–Gaussian detector: the slope recovers the gain \(g\), the intercept the read-noise variance \(\sigma_r^2\); on log–log axes the read-noise floor and the shot-noise regime separate at \(\bar x = \sigma_r^2/g\).
Noise model: \(y_i = \mu_i + \varepsilon_i\), \(\varepsilon_i \sim \mathcal{N}(0, \sigma^2)\), with \(\mu_i = f_\theta(\mathbf{x}_i)\)
\[p(y_i \mid \mu_i) = \frac{1}{\sqrt{2\pi\sigma^2}} \exp\!\left(-\frac{(y_i - \mu_i)^2}{2\sigma^2}\right)\]
Negative log-likelihood: \[-\log p = \frac{(y_i - \mu_i)^2}{2\sigma^2} + \tfrac{1}{2}\log(2\pi\sigma^2)\]
Noise model: \(y_i \sim \text{Poisson}(\lambda_i)\), \(\lambda_i = f_\theta(\mathbf{x}_i) > 0\)
\[p(y_i \mid \lambda_i) = \frac{\lambda_i^{\,y_i}\, e^{-\lambda_i}}{y_i!}\]
Negative log-likelihood: \[-\log p = \lambda_i - y_i \log\lambda_i + \log(y_i!)\]
nn.PoissonNLLLoss(log_input=True); predict \(\log\lambda\) or use softplus to keep \(\lambda > 0\).Per-pixel loss as a function of the predicted rate \(\hat\lambda\) for three observed counts. MSE is a symmetric parabola everywhere; the Poisson NLL is asymmetric, linear in \(\hat\lambda\) where nothing was observed, and diverges if the model predicts \(\hat\lambda \to 0\) where counts arrived.

Gaussian peak + background, 300 Poisson realisations per dose, fitted with MSE, the classic “weighted χ²” (weights \(1/\max(y,1)\)), Anscombe + MSE, and Poisson NLL. Middle: bias of the integrated counts (MSE and Poisson curves overlap at ≈ 0). Right: relative scatter of the fitted peak width. Generated by img/make_figures.py; reproduced in the notebook.
| Data / noise model | Likelihood | Loss | PyTorch |
|---|---|---|---|
| Read-noise dominated, constant \(\sigma\) | Gaussian | MSE | nn.MSELoss |
| Known per-pixel \(\sigma_i\) | Gaussian, heteroscedastic | weighted MSE \(\sum (y-\mu)^2/\sigma_i^2\) | custom |
| Model predicts \(\mu\) and \(\sigma^2\) | Gaussian | Gaussian NLL | nn.GaussianNLLLoss |
| Electron counts (DED, counting mode) | Poisson | Poisson NLL | nn.PoissonNLLLoss |
| Counts + read noise | Poisson–Gaussian | VST + MSE, or mixed NLL | Anscombe + MSELoss |
| Outliers, hot pixels, cosmic rays | Laplace / heavy-tailed | MAE / Huber | nn.L1Loss, nn.HuberLoss |
| Class labels (phase, defect type) | Categorical | cross-entropy | nn.CrossEntropyLoss |
| Binary masks (segmentation) | Bernoulli | binary cross-entropy | nn.BCEWithLogitsLoss |
Note
Garbage in, garbage out: most of these are caught only by looking — histograms, per-frame sums, FFTs — before fitting.
Record with every dataset
.dm4, .emd, .mrc) + open readers (HyperSpy, RosettaSciIO); never “just the TIFF”.Aleatory (irreducible)
Epistemic (reducible)
notebooks/week02_poisson_noise.ipynb — “Poisson noise, SNR & the right loss.”
Material moved out of the 90-minute path; use for questions or self-study.

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