FAU Erlangen-Nürnberg
Institute of Micro- and Nanostructure Research
Week 1: you loaded an EM image into NumPy and added np.random.poisson noise. Today: why Poisson — and what it does to your loss.
√2
SNR gain when you double the dose
→ Act 4 · Counting
6 Å
the lattice you see when you image a 2 Å lattice with 1.5 Å pixels
→ Act 3 · Sampling
−20 %
bias of a textbook χ² fit at 5 counts per pixel; the Poisson loss has none
→ Act 5 · Loss
Act 1 · Learn
What does it mean to learn from data?
Act 2 · Signal
What does an EM pixel measure?
The model sees only the end of the chain. What the chain destroys, no model can recover without a forward model or a prior.
Act 3 · Sampling
Is the pixel grid fine enough?
Act 4 · Counting
Why is every pixel noisy?
\(x = g\cdot\text{Poisson}(\lambda) + \mathcal N(0, \sigma_r^2)\): gain \(g\) in ADU/e⁻, read noise \(\sigma_r\). ADU = analogue-to-digital units, the raw detector numbers.
Act 5 · Loss
Which loss does the physics dictate?
\(\displaystyle \hat\theta = \arg\max_\theta \prod_i p\big(y_i \mid f_\theta(\mathbf{x}_i)\big) = \arg\min_\theta \sum_i \underbrace{-\log p\big(y_i \mid f_\theta(\mathbf{x}_i)\big)}_{\color{#f43f5e}{\text{loss } \ell}}\)
1 · noise model
\(y_i = \mu_i + \varepsilon_i,\;\; \varepsilon_i \sim \mathcal N(0, \sigma^2)\)
\(p(y_i\mid\mu_i) = \dfrac{1}{\sqrt{2\pi\sigma^2}}\, e^{-\frac{(y_i-\mu_i)^2}{2\sigma^2}}\)
2 · take −log
\(-\log p = \dfrac{(y_i-\mu_i)^2}{2\sigma^2} + \tfrac12 \log 2\pi\sigma^2\)
3 · drop terms without θ
\(\color{#94a3b8}{\tfrac{1}{2\sigma^2}}\,(y_i-\mu_i)^2\; \color{#94a3b8}{+\,\tfrac12\log 2\pi\sigma^2}\)
\(\Rightarrow\;\; \ell_\text{MSE} = (y_i - \mu_i)^2\)
Every nn.MSELoss() claims: Gaussian, independent, same σ for every pixel. True left of the crossover on the variance–mean plot; false for shot noise.
1 · noise model
\(y_i \sim \text{Poisson}(\lambda_i),\;\; \lambda_i = f_\theta(\mathbf x_i) > 0\)
\(p(y_i\mid\lambda_i) = \dfrac{\lambda_i^{\,y_i}\, e^{-\lambda_i}}{y_i!}\)
2 · take −log
\(-\log p = \lambda_i - y_i \log \lambda_i + \log(y_i!)\)
3 · drop terms without θ
\(\lambda_i - y_i\log\lambda_i\; \color{#94a3b8}{+\,\log(y_i!)}\)
\(\Rightarrow\;\; \ell_\text{Pois} = \lambda_i - y_i \log\lambda_i\)
Gradient: \(\;\partial\ell_\text{Pois}/\partial\lambda = (\lambda - y)/\lambda\;\) = MSE gradient ÷ variance. The Poisson loss weights each pixel by 1/variance — automatically.
\(\displaystyle \hat\theta_\text{MAP} = \arg\min_\theta \Big[\underbrace{-\log p(\mathcal D\mid\theta)}_{\text{data term: today's loss}}\;\underbrace{-\log p(\theta)}_{\color{#f43f5e}{\text{prior → regulariser}}}\Big]\)
Act 6 · Trust
Can I trust the data and the model?
F
Findable
DOI, rich metadata, indexed in a repository
A
Accessible
standard protocol; metadata stays open even if data are restricted
I
Interoperable
open formats (EMD, NeXus), shared units and vocabularies
R
Reusable
licence, provenance, acquisition parameters, processing script
Payoff for ML: reusable training data, reproducible splits, models you can re-validate on someone else’s microscope.
1 A loss is the negative log-likelihood of a noise model. MSE ⇔ Gaussian with constant variance.
2 Poisson counts: Var = mean, SNR = √λ. Twice the SNR needs 4× the dose.
3 Poisson loss ℓ = λ − y log λ weights each pixel by 1/variance.
4 At low counts, χ² with observed-count weights and naive Anscombe are biased; Poisson NLL is not.
5 Variance–mean plot: slope = gain, intercept = read-noise variance.
6 Sample at ≥ 2× (in practice 3–4×) the highest frequency. Aliasing does not average out.
7 Without dose, gain and pixel size in the metadata, EM data cannot be modelled quantitatively (FAIR).
Notebook (molab): notebooks/unit02_noise_and_loss.py — “Poisson noise, SNR & the right loss”
CPU only; the notebook runs in under a minute. Sign in to molab → Fork → your own copy.
PCA minimises a squared error → it assumes Gaussian noise. NMF with the KL divergence minimises the Poisson NLL. Week 3 is today’s loss, applied to matrix factorisation.
Material outside the 90-minute path, for questions and self-study.
| 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, X-ray hits | 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 |


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