Skip to main content
Back

Brookhaven's Tiny AI Scrubs Bad Shots From Ultrafast Electron Experiments

A convolutional autoencoder trained on just 100 unlabeled diffraction patterns filters out corrupted electron beam shots with a false positive rate near 0.3%.

Pro

Paper, Full Access
  • Unsupervised convolutional autoencoder detects corrupted diffraction patterns in MeV ultrafast electron diffraction experiments.
  • Trained on only 100 unlabeled images, tested on 1521, false positive rate between 0.2% and 0.4%.
  • Training takes about 10 seconds per image; inference runs at roughly 1 second per image.
  • Rice distribution mixture converts reconstruction MSE into a per-image probability of being normal.
  • Preprocessing tiles images into 80x80 patches and discards background-only regions before training.
  • Method generalizes to other diffraction techniques with instrumental instabilities like in-situ TEM.

Physicists studying how materials rearrange themselves on femtosecond timescales rely on a technique called MeV ultrafast electron diffraction (MUED), where a laser pulse kicks a sample and a relativistic electron beam snapshots the resulting structural changes. The catch: the signal from any single electron shot is buried in noise, so researchers average thousands of diffraction patterns together. When individual shots are corrupted by beam drift, they quietly poison the average and blur out exactly the subtle structural signatures the experiment was meant to see.

A team from Brookhaven National Laboratory, the University of Strathclyde, and the University of New Mexico has built an unsupervised deep learning pipeline that scrubs those bad shots out automatically, and it works after training on only 100 images.

Why averaging hurts when the beam wobbles

MUED uses a frequency-tripled Ti:Sapphire laser hitting a copper photocathode to produce femtosecond electron bunches, which get compressed in an RF cavity up to roughly 5 MeV before probing samples about 100 to 300 micrometers wide and under 100 nm thick. Shot-to-shot instabilities in the electron beam distort individual patterns, and those faulty frames get averaged into the dataset at an effective throughput of 25 Mb/s at 5 Hz. The result is lower spatial and temporal resolution, which is fatal when the whole point is to catch tiny pump-induced changes.

Manual triage is out of the question at that data rate, and supervised classifiers need labeled anomalies that nobody wants to hand-annotate. That framing pushed the authors toward an unsupervised approach where the model never sees a label at all.

A lightweight autoencoder that learns what normal looks like

The core idea is residual anomaly detection: train a convolutional autoencoder (CAE) to reconstruct normal diffraction patterns, then flag any image the network struggles to reproduce. Because anomalies are rare in the training set and drawn from a different distribution, the CAE effectively underfits them and produces a high mean squared error on faulty inputs.

Original diffraction pattern next to its tiled preprocessed version showing Bragg peaks

Preprocessing is doing a lot of the heavy lifting here. A single crystal diffraction pattern is mostly empty background with a few sharp Bragg peaks, so the authors chop each 512x512 image into overlapping 80x80 tiles and throw away tiles that contain only background noise. A tile is kept if it has enough connected pixels above three times the tile median, with the chosen values selecting all peak-containing tiles without error. This forces the network to spend its capacity modeling real signal.

The CAE itself is deliberately small: three convolution-plus-maxpool blocks compress each tile down to a bottleneck of 256 features, then three transpose convolutions expand it back. Trained with Adam and MSE loss, it converges in roughly two minutes.

Turning reconstruction error into a probability

Rather than picking a hard threshold, the authors fit the distribution of log-MSE values with a mixture of two Rice distributions, one for normal patterns and one for anomalies. Optimizing the negative log likelihood with L-BFGS-B plus simulated annealing recovers both the distribution parameters and the prior probability that any given image is normal. That mixture yields a posterior probability p(N|e) for each image, so users can auto-discard high-confidence anomalies and only eyeball the small pile of images sitting near p=0.5.

The numbers

The system was trained on 100 unlabeled images and evaluated on 1521 patterns of Ta2NiSe5, a candidate excitonic insulator. Roughly 40% of the test set was faulty. Highlights from the results:

  • Detection rate of 1.0 at the automatically chosen threshold, with a false positive rate of 4.4 x 10^-3 in the balanced setup.
  • When the anomaly fraction was reduced to 2% (closer to a well-tuned beamline), the false positive rate dropped to 0.22%.
  • Training time around 10 seconds per image; test time around 1 second per image, dominated by disk I/O.
  • The estimated prior weight w tracked the true normal fraction (0.6 vs 0.97) across both experiments.
ROC curve showing near-perfect true positive rate at very low false positive rate

Where it works, where it does not

The method is a drop-in cleaner for any diffraction technique that averages many noisy shots and occasionally suffers instrumental hiccups, including in-situ transmission electron diffraction. The authors specifically call out pump-probe MUED, where the changes being hunted are subtle enough that even a few bad frames in the average matter.

There are honest limits. The preprocessing is tuned to crystalline patterns dominated by localized Bragg peaks, and gas-phase diffraction would need a different tiling criterion. Aggregating errors as a global mean also blurs out small localized defects like hot pixels or partial dropout; the authors suggest switching to max-tile error or upper percentiles for those cases. And in pump-probe experiments, calibrating the error distribution per delay bin is necessary so real pump-induced structural changes are not mistaken for anomalies.

The paper does not release code, but the architecture is small enough to replicate from Table 2 of the manuscript in a few dozen lines of PyTorch. For teams running beamlines that generate faulty frames faster than a human can look at them, that is probably a weekend of engineering for a measurable jump in effective resolution.