From atoms, compositions and heat treatments to a fixed list of numbers a model can learn from.
Undergraduate course · 16 weeks
Recap of lecture 2 · linear regression and regularization
Last week we learned the weights. Today: where do the features come from?
1
Normal equations from \(\nabla_{\mathbf w}\|X\mathbf w-\mathbf y\|^2 = 2X^{\mathsf T}(X\mathbf w-\mathbf y)=0\):\[ X^{\mathsf T}X\,\mathbf w = X^{\mathsf T}\mathbf y \]
Re-derived lecture 1's line \(\hat E_g = 0.5875 + 2.5675\,\Delta\chi\).
2
Ridge and lasso: \(\mathbf w = (X^{\mathsf T}X+\lambda I)^{-1}X^{\mathsf T}\mathbf y\) shrinks all weights; the lasso penalty \(\lambda\sum|w_j|\) sets some weights exactly to zero.
Regularization trades a little bias for less variance.
In every example someone handed us the features: Δχ for band gaps, the composition x for Vegard's law. A linear model can only combine what its inputs express. For a new property of a new compound, which numbers should we feed it?
Today's plan
composition → structure → processing and microstructure → scaling → selection. Two examples: formation enthalpies of 46 binary compounds (real data) and the yield strength of steels (simulated).
Why questions · answered at the end
Four puzzles for today
WHY 1
Rotate a crystal by 90°: every atomic coordinate changes, yet nothing physical does. Why must a good descriptor not notice?
WHY 2
Rutile and anatase are both TiO₂, with different properties. Why can no composition-only model ever tell them apart?
WHY 3
Why does a model of steel strength extrapolate to fine grains far better with d−1/2 than with the grain size d itself?
WHY 4
Why can simply changing the units of one feature change which materials a model calls "similar"?
The problem · why raw coordinates fail
One molecule, four different coordinate lists
What a good descriptor needs
Invariant to translation, rotation and the order of atoms (permutation).
Unique: different materials → different vectors.
Smooth: a small atomic move → a small change.
Fixed length, whatever the number of atoms.
NaCl: a crystal repeats forever, and its cell can be chosen in many ways. Benjah-bmm27, public domain
Math primer 1 · weighted statistics of a composition
A compound is a small distribution of elements
1
Atomic fractions from the formula \(A_{n_A}B_{n_B}\dots\):\[ f_i = \frac{n_i}{\sum_j n_j}, \qquad \sum_i f_i = 1 \]
The fractions act like probabilities of drawing each element.
2
Weighted mean of an elemental property p (e.g. electronegativity χ):\[ \bar p = \sum_i f_i\,p_i \]
The "typical" value of p in the compound.
3
Mean absolute deviation and range:\[ \text{MAD}_p = \sum_i f_i\,|p_i-\bar p|, \qquad \text{range}_p = \max_i p_i - \min_i p_i \]
Derivation of the binary formula: \(|p_A-\bar p| = f_B|\Delta|\), \(|p_B-\bar p| = f_A|\Delta|\), so MAD = \(f_A f_B|\Delta| + f_B f_A|\Delta|\).
Use \(f_A+f_B=1\) to simplify.
Sanity checks
Pure element (\(f_B=0\)): MAD = 0, as it must. Equal fractions: MAD = |Δ|/2, the largest possible. A dilute dopant (\(f_B\to0\)) barely changes the mean or the MAD, but the range jumps to |Δ|.
Composition descriptors · matminer and Magpie style
Elemental properties × statistics = a fingerprint
FormulaAl₂O₃ → fAl = 0.4, fO = 0.6
→
Look up propertiesχ, atomic number Z, group, radius, melting point, valence electrons …
Trends across the periodic table: ionic versus covalent bonding, size mismatch, electron count. Invariant by construction (no coordinates at all) and fixed length. But it is blind to structure: rutile and anatase TiO₂ get identical vectors, and a model will predict one value for both.
When it works
When the property is mainly set by chemistry (formation energy, many band gaps) or when the structure is not yet known, as in screening new compositions.
Try it (outside the video)
A × B ×
—
Pauling electronegativities; statistics as defined on the math primer slide.
Worked problem 1 · by hand
Composition features of Al₂O₃
element
n
f
χ (Pauling)
Z
Al
2
0.4
1.61
13
O
3
0.6
3.44
8
Check: FeO versus Fe₂O₃
mean χ
MAD χ
range χ
FeO
2.635
0.805
1.61
Fe₂O₃
2.796
0.773
1.61
Same elements, different fractions → different vectors. Same range: the range alone cannot separate them.
Materials example · real data, compared with a baseline
Formation enthalpy from composition alone
Data: standard formation enthalpies (298 K, per atom, handbook values) of 46 halides, oxides, sulfides, nitrides. Features: mean, MAD, range of χ, Z, group (9 numbers). Model: ridge, standardized features, leave-one-out (lecture 2).
model
MAE (eV/atom)
mean baseline
0.78
line in range of χ (= |Δχ|)
0.55
ridge, 9 composition features
0.47
What the model learned
Alkali and alkaline-earth chlorides, bromides, CaF₂, MgF₂: good (errors mostly ≤ 0.4 eV/atom). The most strongly bound oxides (MgO to BaO, Al₂O₃, SiO₂, TiO₂) come out too weakly bound, Ag₂O and CuO too strongly: nine numbers cannot see d electrons or covalency. λ was tuned on the same leave-one-out: 0.47 is slightly optimistic.
Structure descriptors 1 · the radial distribution function
Count neighbours at each distance
1
Use only distances \(r_{ij} = |\mathbf r_i - \mathbf r_j|\) between atoms, including periodic images.
A distance does not change under translation, rotation or relabelling.
2
Histogram and normalize by the volume of each shell, \(4\pi r^2\,dr\), and the density ρ:\[ g(r) = \frac{1}{4\pi r^2\rho N}\sum_{i}\sum_{j\ne i}\delta(r-r_{ij}) \]
The delta peaks are smoothed with narrow Gaussians, so g(r) is smooth.
3
Sample g(r) on a fixed grid of r.
A fixed-length vector for any number of atoms.
What the model learned
Coordination numbers and bond lengths: it separates polymorphs that composition cannot. But it drops bond angles, so different structures can share almost the same g(r).
Math primer 2 · eigenvalues and permutations
Relabelling atoms does not change eigenvalues
1
Eigenvalues μ of a symmetric matrix M solve\[ M\mathbf v = \mu\mathbf v \;\Leftrightarrow\; \det(M-\mu I) = 0 \]
An n×n symmetric matrix has n real eigenvalues. (We write μ: λ is our regularization strength.)
Sum of eigenvalues = trace \(a+d\); product = determinant \(ad-b^2\). Both are unchanged by the swap, so the eigenvalues must be too. Example: \(\begin{bmatrix}10&3\\3&2\end{bmatrix}\) → \(6\pm\sqrt{16+9}\) = 11 and 1.
Why we need this: a matrix built from atom pairs changes when we relabel the atoms, but its sorted eigenvalues do not. They are a permutation-invariant fingerprint.
For crystals the sum over infinitely many periodic images diverges, so periodic versions are used (the sine matrix, the Ewald-sum matrix).
What the model learned
Which heavy atoms sit close to each other. The eigenvalue list throws information away: different structures can share a spectrum, and the heavy atom dominates (74 against 0.3 here).
Worked problem 2 · by hand
Coulomb matrix and eigenvalues of carbon monoxide
Given: C (Z = 6) and O (Z = 8), bond length 1.128 Å = 1.128 / 0.5292 = 2.132 bohr.
Sum 110.37 = trace ✓. Product 2202.6 = \(36.86\times73.52 - 22.52^2\) ✓. Order O, C: diagonal swaps, same eigenvalues ✓. Stretching the bond changes them smoothly (table).
Structure descriptors 3 · the idea of SOAP
SOAP: a blurred picture of each neighbourhood
1
Neighbour density around atom i: a Gaussian of width \(\sigma_{\rm a}\) on each neighbour within \(r_c\):\[ \rho_i(\mathbf r) = \sum_{j} \exp\!\Big(\!-\frac{|\mathbf r-\mathbf r_{ij}|^2}{2\sigma_{\rm a}^2}\Big) \]
Blurring makes the descriptor smooth; relative positions make it translation-invariant.
2
Expand in radial functions × spherical harmonics, coefficients \(c_{nlm}\).
Like a Fourier series, on a sphere.
3
Power spectrum \(p_{nn'l} = \sum_m c_{nlm}\,c^{*}_{n'lm}\): rotations only mix the m's, so the sum over m is rotation-invariant.
4
Similarity kernel \(k(A,B) = \big(\hat{\mathbf p}_A\cdot\hat{\mathbf p}_B\big)^{\zeta}\), average over atoms for a whole structure.
A kernel, as in Gaussian processes next week.
Comparison · which descriptor when?
Descriptors side by side
descriptor
needs structure?
invariances
sees polymorphs?
typical use
composition statistics
no
all (no coordinates)
no
screening new chemistries; small data
radial distribution g(r)
yes
all
yes, without angles
amorphous and liquid structures, quick fingerprints
alloys, ceramics, devices: properties set by history
Pick the simplest descriptor that contains the physics of your property, and that you can compute for every material you will predict.
Processing and microstructure descriptors
Same composition, different history, different material
1
Processing: austenitizing and tempering temperature T and time t, cooling rate, amount of cold work. Easy to record, but act through the microstructure.
2
Microstructure: grain size d, phase fractions (ferrite, pearlite, martensite), precipitate size, texture. Measured from micrographs and maps.
3
Physics-informed transforms: Hall–Petch \(d^{-1/2}\); the tempering parameter \(P = T\,(20+\log_{10} t)\) with T in K and t in h, which merges T and t into one number; Arrhenius \(e^{-Q/RT}\) for diffusion. Put known physics into x, so a simple model can stay linear.
Ferrite (light) and pearlite (dark) in a 20Cr steel: phase fractions and grain size are features. Surface engineering, CC BY-SA 4.0EBSD orientation map of lath martensite: colours are crystal orientations. Tiberio, CC BY-SA 4.0
A physics-informed feature · simulated data
Both features fit the data. Only d−1/2 extrapolates.
Simulated: 14 "measurements" with d between about 18 and 98 µm, from \(\sigma_y = 100 + 600\,d^{-1/2}\) MPa (d in µm) plus 8 MPa noise.
feature
train RMSE
σy at d = 2 µm
d (line)
9.4 MPa
243 MPa
d−1/2 (line)
5.9 MPa
496 MPa
truth (simulation)
—
524 MPa
What the model learned
Inside about 18–100 µm both lines look fine. Outside, only the feature with the right physics follows the trend. Fitted: \(\sigma_y = 110 + 546\,d^{-1/2}\), close to the truth.
Worked problem 3 · by hand
A Hall–Petch line from two measurements
steel
d (µm)
x = d−1/2 (µm−1/2)
σy (MPa)
coarse
36
1/6 = 0.167
200
fine
9
1/3 = 0.333
300
What the model learned · and its limits
σ₀ is the strength of a very coarse-grained (d → ∞) steel; ky measures how strongly grain boundaries block dislocations. Below roughly 10–20 nm the law breaks down (grain-boundary sliding): no fit to coarse grains can know that.
Check: both predictions are above σ₀ = 100 MPa ✓; 100 µm grains (coarser than the 36 µm steel) give less than 200 MPa, and 4 µm grains (finer than 9 µm) give more than 300 MPa ✓.
Feature scaling · standardization derived
Standardize features, with training-set statistics only
1
Standardize each feature with the training mean μ and standard deviation s:\[ z_i = \frac{x_i-\mu}{s}, \quad \mu = \frac1n\sum_i x_i,\quad s^2 = \frac1n\sum_i (x_i-\mu)^2 \]
2
Mean is zero: \(\frac1n\sum_i z_i = \frac1s\big(\frac1n\sum_i x_i - \mu\big) = 0\). Variance is one: \(\frac1n\sum_i z_i^2 = \frac{1}{s^2}\cdot s^2 = 1\).
3
Test data: apply the same μ and s; never refit on test data.
Otherwise test information leaks into the model (lecture 1, missing values).
Why it matters
Distances (nearest neighbours, kernels) and penalties (ridge \(\lambda\sum w_j^2\), lasso) treat all features alike. Without scaling, the feature with the biggest units wins.
Which steel is most similar to the query?
temper T (°C)
C (wt%)
raw distance
scaled
query
650
0.20
steel P
652
0.60
2.04
2.45
steel Q
690
0.21
40.0
0.98
Training set: T = 600, 650, 700 °C (s = 40.8 °C); C = 0.2, 0.4, 0.6 wt% (s = 0.163 wt%).
Raw: \(\sqrt{2^2+0.4^2} = 2.04\) for P. Scaled: \(\sqrt{(2/40.8)^2+(0.4/0.163)^2} = 2.45\) for P and \(\sqrt{(40/40.8)^2+(0.01/0.163)^2} = 0.98\) for Q.
Feature selection · correlation and the lasso
Correlation is a quick filter; the lasso selects jointly
Mn and Cr have r ≈ 0 but do strengthen the steel: their effect is hidden by the much larger carbon and tempering effects. T and P carry the same information (r = 0.99 with each other); the lasso keeps one. Two pure-noise features were never selected.
Materials example · simulated data, compared with a baseline
Steel strength from composition and heat treatment
Simulated, labelled as such: 240 steels with C, Mn, Si, Cr, tempering T and t, grain size d. Strength from a made-up formula: solid solution + Hall–Petch + carbon strengthening that fades with tempering, plus 25 MPa noise. 180 train, 60 test; scaler fit on train only; least squares.
What the model learned
Raw features: the model must be linear in T and d, so it misses both curves. Adding P and d−1/2 helps a little. The big gain comes from C × P: carbon matters only until it is tempered away, an interaction a linear model cannot invent by itself.
Lab 3 · this week in Colab
Featurize materials with pymatgen and matminer
import pandas as pd
from pymatgen.core import Composition
from matminer.featurizers.composition import ElementProperty
df = pd.read_csv("binaries_dHf.csv") # formula, dHfdf["comp"] = df.formula.apply(Composition)
ep = ElementProperty.from_preset("magpie")
df = ep.featurize_dataframe(df, "comp")
X, y = df[ep.feature_labels()], df.dHffrom sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import RidgeCV
model = make_pipeline(StandardScaler(), RidgeCV())from sklearn.model_selection import cross_val_score
mae = -cross_val_score(model, X, y, cv=5,
scoring="neg_mean_absolute_error")
print(mae.mean()) # compare: predict the mean
Exercises
Compute mean, MAD and range of χ for Al₂O₃ by hand; check against matminer.
Compare the mean baseline, a line in |Δχ| and ridge on Magpie features.
Build rutile and anatase TiO₂ in pymatgen: compare their composition features and their g(r).
Steel data: add d−1/2, P and C × P; keep the scaler inside the pipeline.
Runs in Google Colab, no GPU needed; install with pip install pymatgen matminer. Data files and notebook are posted with this lecture.
Answers to the why questions
The four puzzles, solved
1 · Rotation
The energy and every property are unchanged by rotation, translation and relabelling. A descriptor that changes would force the model to learn the same material many times. Use distances, eigenvalues or power spectra.
2 · Rutile and anatase
Same formula → same fractions → identical composition vector. The model must predict one value for both. Only a structure descriptor (g(r), SOAP, graph) separates polymorphs.
3 · Hall–Petch feature
In d−1/2 the physics is a straight line, so a line extrapolates correctly (496 vs 524 MPa at 2 µm); a line in d predicts 243 MPa. Physics in the feature lets a simple model generalize.
4 · Units
Distances and penalties add up raw numbers. In °C and wt%, temperature dominated and the wrong steel looked closest. Standardize with training-set μ and s.
Check your understanding · click a card to reveal
Concept check
Q1. Compute the mean and MAD of χ for MgO (χMg = 1.31, χO = 3.44).
f = 0.5 each: mean = 2.375; MAD = 2 × 0.5 × 0.5 × 2.13 = 1.065 (= |Δχ|/2).
Q2. Eigenvalues of [[10, 3], [3, 2]]? And after swapping the two atoms?
6 ± √(16 + 9) = 11 and 1. After the swap, [[2, 3], [3, 10]]: same trace and determinant, so again 11 and 1.
Q3. You standardize with the mean and s of the whole dataset, then split. What is wrong?
Leakage: test values shaped μ and s. Split first, fit the scaler on the training set, put it inside a pipeline for cross-validation.
Q4. A colleague feeds sorted x, y, z coordinates of all atoms to a model. Name two problems.
Not rotation- or translation-invariant (and sorting is not smooth); the length changes with the number of atoms; periodic cells are not unique.
Wrap-up
Summary and next lecture
1
A descriptor turns a material into a fixed-length vector. It must be invariant to translation, rotation and atom order, and should be unique and smooth.
2
Composition: fraction-weighted mean, MAD = Σ fi|pi − p̄| and range of elemental properties. Cheap and general, blind to polymorphs.
3
Structure: g(r) from distances; Coulomb-matrix eigenvalues (permutation-invariant); SOAP power spectra (smooth, rotation-invariant).
4
Processing and microstructure, with physics-informed transforms (d−1/2, tempering parameter, interactions) that keep models simple and extrapolating.
5
Standardize with training-set μ and s only; select with correlation (quick) and the lasso (joint).
This week
Lab 3: matminer composition features, polymorph fingerprints, engineered steel features. Problem set 1 (weeks 1–3) is out this week, due in week 4.
Next lecture · Probability, uncertainty and Gaussian processes
How sure is a prediction? We show that least squares is maximum likelihood, that ridge is a Gaussian prior, and build Gaussian process regression, whose kernel compares materials the way SOAP compares environments and whose error bars grow away from the data.
References and image credits
Further reading
Reading for this week
S. Sandfeld, Materials Data Science, Springer (2024): chapters on features and data preparation.
G. James, D. Witten, T. Hastie, R. Tibshirani, J. Taylor, An Introduction to Statistical Learning with Applications in Python, Springer (2023), Ch. 6 (feature selection, lasso).
L. Ward, A. Agrawal, A. Choudhary, C. Wolverton, "A general-purpose machine learning framework for predicting properties of inorganic materials," npj Comput. Mater. 2, 16028 (2016) (Magpie features).
L. Ward et al., "Matminer: An open source toolkit for materials data mining," Comput. Mater. Sci. 152, 60 (2018); S. P. Ong et al., pymatgen, Comput. Mater. Sci. 68, 314 (2013).
M. Rupp, A. Tkatchenko, K.-R. Müller, O. A. von Lilienfeld, Phys. Rev. Lett. 108, 058301 (2012) (Coulomb matrix).
A. P. Bartók, R. Kondor, G. Csányi, "On representing chemical environments," Phys. Rev. B 87, 184115 (2013) (SOAP).
E. O. Hall, Proc. Phys. Soc. B 64, 747 (1951); N. J. Petch, J. Iron Steel Inst. 174, 25 (1953). J. H. Hollomon, L. D. Jaffe, Trans. AIME 162, 223 (1945) (tempering parameter).
Formation enthalpies: standard thermodynamic tables (CRC Handbook of Chemistry and Physics, NIST), 298 K.
Image credits (Wikimedia Commons)
Sodium chloride crystal structure: Benjah-bmm27, public domain — File page
Ferrite–pearlite microstructure of 20Cr steel: Surface engineering, CC BY-SA 4.0 — File page
EBSD orientation map of ferrous lath martensite: Tiberio, CC BY-SA 4.0 — File page
All schematics and plots were drawn for this course. The Hall–Petch and steel data are simulated from stated formulas; the formation enthalpies are rounded handbook values; the radial distribution functions and Coulomb matrices are computed from standard lattice constants and bond lengths.