FAU Erlangen-Nürnberg
Institute of Micro- and Nanostructure Research
By the end of this lecture you can:
Synthetic examples. Left: a linear classifier learned from labelled diffraction features. Middle: k-means groups unlabelled EELS spectra. Right: Noise2Noise uses one noisy frame as the target for another.
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)
The same intensity ramp with Gaussian read noise (σ = 5) and with Poisson shot noise. Right: the noise measured from the two images, column by column.
Gaussian (read / thermal): many small independent effects → Central Limit Theorem. Variance \(\sigma_r^2\) is independent of the signal.
Poisson (shot): electrons arrive at random. \(\text{Var}(N) = \lambda\), so SNR \(= \sqrt{\lambda}\): 2× the SNR needs 4× the dose. It is the quantum limit; no detector removes it.
np.random.poisson(lam = dose_scale * phantom).Histograms of \(x = g\cdot\text{Poisson}(\lambda) + \mathcal{N}(0,\sigma_r^2)\) with \(g = 20\) ADU/e⁻ (200 000 synthetic pixels each). Left: counting detector, single electrons are separate peaks. Middle and right: integrating detector, the peaks merge.
Variance of each noise contribution against the mean signal, for example detector values (read noise σ_r = 3 e⁻, dark current 0.5 e⁻, 2 % pixel gain spread, 14-bit ADC).
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\).
| 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 |
Six synthetic artefacts (top) and the quick check that finds each one (bottom).
Record with every dataset
.dm4, .emd, .mrc) + open readers (HyperSpy, RosettaSciIO); never “just the TIFF”.
Aleatory (irreducible): randomness of the process itself, e.g. shot noise, thermal vibrations. More data does not reduce it.
Epistemic (reducible): lack of knowledge, e.g. unknown gain or PSF, too little training data, a wrong model. More data or better calibration does reduce it.
notebooks/unit02_noise_and_loss.py — “Poisson noise, SNR & the right loss”, with sliders for dose, observed count, gain and read noise.
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