Portfolio

The core finding

301 χ²/dof before
WASP-39b ⚠
0.06 χ²/dof after
radius inferred
7/7 Parameters inside the
credible interval (was 2/7)

The sim-to-real gap on real JWST spectra was not forward-model fidelity — the usual suspect. It was a radius/baseline degeneracy: inferring planet radius instead of fixing it turned an unusable importance-sampling ESS of 1 into a physical retrieval.

scroll to expand

Python PyTorch Flow Matching (fm4ar) Transformer Encoder TauREx3 Optimal Transport Nested Sampling exoTEDRF batman JWST / MAST
GitHub
301 → 0.06 Best-fit χ²/dof on WASP-39b
2/7 → 7/7 Parameters covered vs nested sampling
3 Targets — planet class, instrument, provenance
5.8σ Water feature, from raw MAST data reduced end to end
The core finding

The gap was a degeneracy, not a bad simulator

Simulation-trained posteriors collapse on real JWST spectra, and the field's default explanation is forward-model error. Controlled ablations ruled that out here. The actual culprit was a radius/baseline degeneracy: with planet radius held fixed, the transit baseline had nowhere to go, importance-sampling ESS sat at 1, and best-fit χ²/dof was 301. Inferring radius as a parameter and calibrating against an independent nested-sampling reference brought χ²/dof to 0.06 and coverage from 2/7 to 7/7.

MIRAGE attacks the sim-to-real gap from both ends. On the domain-adaptation side, TauREx3 forward models are trained with correlated-noise injection so the encoder never sees a clean spectrum. On the inference side, an optimal-transport calibration step aligns the amortised posterior to a nested-sampling reference computed independently for each target. Neither half is enough on its own — the calibration is what converts a fast posterior into a trustworthy one.

Pipeline

Simulation → amortised posterior → calibrated retrieval

STAGE 1 — SIMULATION TauREx3 FORWARD Rp · T · 5 log-abundances transmission spectra correlated-noise injection STAGE 2 — TRAINING SPECTRA ENCODER per-bin tokens + wavelength PE 4-layer transformer · d=128 instrument embedding · σ · cov replaces fm4ar's DenseResidualNet FLOW-MATCHING POSTERIOR fm4ar FMPE backbone noise-conditioned q(θ | spectrum) IMPORTANCE SAMPLING + optimal-transport align vs nested-sampling ref coverage 2/7 → 7/7 STAGE 3 — REAL DATA PUBLISHED SPECTRA WASP-39b — NIRSpec PRISM K2-18b — NIRISS hot Saturn and cold sub-Neptune SELF-REDUCED FROM RAW MAST WASP-96b — NIRISS SOSS · ERO 2734 exoTEDRF → batman light-curve fit water feature recovered at 5.8σ CALIBRATED POSTERIOR radius inferred, not fixed χ²/dof 0.06 · 0.079 · 0.20 method unchanged across targets
Core implementation

One token per wavelength bin

The context encoder treats a spectrum as a sequence, not a vector. Each wavelength bin becomes a token carrying its flux, optionally its per-wavelength uncertainty σ, and an instrument embedding — so NIRSpec PRISM and NIRISS SOSS spectra can be fused in one model rather than one model per mode.

Tokens are projected to d_model and augmented with a sinusoidal wavelength positional encoding, so the transformer knows where in the band each bin sits regardless of how the instrument grid is sampled. Self-attention runs over all bins; mean-pooling and a linear head produce the context vector the flow-matching posterior conditions on.

It is registered into fm4ar's block registry as a SpectraEncoder block, replacing the stock DenseResidualNet context encoder — fm4ar itself stays unmodified, so upstream fixes keep applying. The method follows SpectraFM (Koblischke & Bovy 2024) and is independently reimplemented in PyTorch.

An optional covariance branch embeds out-of-transit residual frames, conditioning the posterior on the structure of correlated noise rather than only its scale.

python mirage/nn/spectra_encoder.py
def forward(self, context: Mapping[str, Tensor]) -> Tensor:
    wlen = context["wlen"]     # (batch, seq) μm
    flux = context["flux"]     # (batch, seq)

    # Multi-instrument fusion: one embedding per mode
    inst_emb = self.instrument_embedding(
        context["instrument_id"].long()
    )

    # Token = [flux, (σ,) instrument embedding]
    feats = [flux.unsqueeze(-1)]
    if self.use_error_bars:
        feats.append(context["error_bars"].unsqueeze(-1))
    feats.append(inst_emb)

    tokens = self.token_proj(torch.cat(feats, dim=-1))
    tokens = tokens + self._wavelength_pe(wlen)  # SpectraFM Eq. 2

    encoded = self.transformer(tokens)
    return self.output_proj(encoded.mean(dim=1))
Results

Three targets, one unchanged method

Coverage — parameters whose true value falls inside the credible interval, against an independent nested-sampling reference. Seven parameters per target.

WASP-39b (raw)
2 / 7 ⚠
WASP-39b (calib.)
7 / 7
WASP-96b (calib.)
7 / 7
K2-18b (calib.)
6 / 7

The honest negative: noise-conditioning improved calibration on the synthetic benchmark but did not transfer to real data. Neither did CycleGAN domain translation over structured randomisation, nor higher-resolution opacity grids. All three ablations are reported rather than dropped.

The three targets span planet class, instrument, and data provenance — the method was not retuned between them.

TargetInstrumentχ²/dofRadius (truth)
WASP-39bNIRSpec PRISM0.061.23 (1.28) RJ
WASP-96bNIRISS SOSS0.0791.196 (1.20) RJ
K2-18bNIRISS0.200.233 (0.235) RJ
WASP-96b provenanceself-reduced, raw MAST

WASP-96b is the strongest test: its spectrum was reduced end to end from raw ERO 2734 exposures with exoTEDRF and batman light-curve fitting, so no published reduction sits between the telescope and the retrieval. Its water feature comes back at 5.8σ.

K2-18b — a cold sub-Neptune observed with a different instrument — is the out-of-class case, and the only one that misses full coverage, at 6/7.

Forward models · training · reduction · figures

Run the retrieval on all three targets