FAU Erlangen-Nürnberg
Institute of Micro- and Nanostructure Research
Week 2: the noise model decides the loss. Today: the same rule decides how we factorise a spectrum image, and every example is real data.
58

counts per pixel in a real EDS map: the Ce window gets only 0.4, yet PCA gives a clean map
→ Act 4 · PCA
0.96

correlation of a PCA “component” with the energy drift of the spectrometer
→ Act 4 · PCA
∞

unmixings that fit the data exactly equally well: A and B are two of them
→ Act 6 · Trust
Act 1 · Vector
When are two spectra alike?

Source study: Fe-L₂,₃ spectra of a lunar pyroxene and the Fe²⁺ / Fe³⁺ standards. Dashed lines: the two L₃ channels used here. Fig. 10 of Cymes, Brittany A. et al., (2023), doi:10.1111/maps.13941, CC BY 4.0.
Act 2 · Matrix
How does a datacube become a matrix?
X = cube.reshape(ny * nx, ne) — every method today factorises this X ≈ (maps) × (spectra).
Residual rᵢ = data − model. Least squares picks the parameters that make Σ rᵢ² as small as possible.
Act 3 · SVD
What does any matrix do to space?
Least squares finds the lattice in every pattern. The SVD splits its change into rotation and principal strains.
Act 4 · PCA
How many things vary?
Centre
\(\tilde{\mathbf X}=\mathbf X-\mathbf 1\bar{\mathbf x}^{T}\)
remove the mean spectrum
Decompose
\(\tilde{\mathbf X}=\mathbf U\boldsymbol\Sigma\mathbf V^{T}\)
\(\lambda_k=\dfrac{\sigma_k^2}{N-1}\)
Read off
loadings \(\mathbf v_k\) (spectra)
scores \(\mathbf t_k=\tilde{\mathbf X}\mathbf v_k\) (maps)
\(\hat{\mathbf X}_K=\bar{\mathbf x}+\textstyle\sum_{k\le K}\mathbf t_k\mathbf v_k^{T}\)
Act 5 · Unmix
What are the things?
\(\mathbf x_i \approx \sum_k a_{ik}\,\mathbf m_k\), \(a_{ik}\ge 0\), \(\sum_k a_{ik}=1\) → \(\mathbf X\approx\mathbf A\,\mathbf M\), both \(\ge 0\)
Model
\(\mathbf X\approx\mathbf W\mathbf H\)
\(\mathbf W\in\mathbb R_{\ge0}^{N\times K}\) maps, \(\mathbf H\in\mathbb R_{\ge0}^{K\times D}\) spectra
Loss = noise model
Gauss: \(\lVert\mathbf X-\mathbf{WH}\rVert_F^2\)
Poisson: \(\sum x\log\frac{x}{(\mathbf{WH})}-x+(\mathbf{WH})\)
Multiplicative update (KL)
\(\mathbf H\leftarrow\mathbf H\odot\dfrac{\mathbf W^{T}(\mathbf X/\mathbf{WH})}{\mathbf W^{T}\mathbf 1}\)
\(\mathbf W\leftarrow\mathbf W\odot\dfrac{(\mathbf X/\mathbf{WH})\,\mathbf H^{T}}{\mathbf 1\,\mathbf H^{T}}\)
No subtraction is possible, so the components can only add up: parts, peaks, phases Lee, Daniel D. et al., (1999), doi:10.1038/44565. KL-NMF is maximum-likelihood unmixing of counts.
\(\mathbf X=\mathbf C\mathbf S^{T}+\mathbf E\): alternate two constrained least-squares problems.
NMF = MCR with non-negativity only. Each extra true constraint shrinks the set of valid answers.

Act 6 · Trust
When is the phase map lying?
| Question | Method | Constraint | Unique? | Check |
|---|---|---|---|---|
| How many things vary? Denoise | PCA / SVD, Poisson-weighted | orthogonal, variance-ordered | yes (± sign) | scree after weighting, residual map |
| Which phases, references known | NNLS / FCLS (projection) | \(\mathbf a\ge 0\), \(\sum a=1\) | yes | structured residual → missing reference |
| Which phases, spectra unknown | NMF (KL for counts) | \(\mathbf W,\mathbf H\ge 0\) | no | restarts, pure pixels, feasible band |
| + physical knowledge | MCR-ALS, physics-guided NMF | + closure, known spectra, selectivity | ≈, if enough | the constraints must be true |
| Overlapping signals | any least-squares fit | — | yes, but unstable | condition number κ |
| Discrete phases / curved data | clustering, autoencoders (Week 9) | labels / learned non-linear | no | mixed pixels, validation |
1 Projection onto â: c = âᵀb. Least squares = projection: Xᵀ(y − Xŵ) = 0.
2 SVD: A = UΣVᵀ (rotate, stretch, rotate). ‖X − Xₖ‖²_F = Σⱼ>ₖ σⱼ² (Eckart–Young).
3 PCA = SVD of the centred data; λₖ = σₖ²/(N−1). Scores and loadings are signed.
4 PCA denoises: signal low-rank, noise full-rank. Poisson-weight counts before PCA.
5 A derivative-shaped loading signals an energy shift. Align before you decompose.
6 NMF: X ≈ WH, W, H ≥ 0. KL-NMF = Poisson maximum likelihood.
7 NMF / MCR are not unique: WH = (WT)(T⁻¹H). Constraints reduce the ambiguity.
8 Truncation removes low variance, not unimportant signal: read the residual map. κ = σ_max/σ_min.
Notebook (molab): notebooks/unit03_pca_unmixing.py — “PCA and spectral unmixing on real EM data”
Ten exercises with automatic checks; CPU only, NumPy and Matplotlib. Sign in to molab → Fork → your own copy.
Least squares was a projection today. Next week it becomes learning: gradient descent, ridge for ill-conditioning, and validation that does not leak.
Material outside the 90-minute path, for questions and self-study.

Synthetic 3-phase spectrum image (TiO₂-like, FeO-like, Ni) with Poisson noise. Top: truth. Middle: PCA (K = 3), signed difference spectra and maps; PC3 is noise because sum-to-one removes one dimension after centring. Bottom: NMF (K = 3), phase-like spectra and non-negative maps (img/make_figures.py).

np.linalg.cond(X) on the standardised design matrix. Above ~10³, coefficients are unstable.
©Philipp Pelz - FAU Erlangen-Nürnberg - Data Science for Electron Microscopy