---
title: '21cmLSTM: Recurrent Emulator for 21 cm Signal'
url: https://www.emergentmind.com/topics/21cmlstm
type: topic
---

# 21cmLSTM: Recurrent Emulator for 21 cm Signal

21cmLSTM is a neural-network emulator for the global, sky-averaged 21 cm cosmology signal that uses long short-term memory recurrent layers to predict the full brightness-temperature sequence as a function of frequency or redshift from a low-dimensional set of astrophysical and cosmological parameters. It was introduced to replace computationally expensive semi-numerical and semi-analytical simulators inside Bayesian inference pipelines that may require \(10^4\)–\(10^6\) likelihood evaluations, while keeping emulation error well below observational noise so that posterior constraints remain unbiased. In the subsequent literature, 21cmLSTM functions as the principal accuracy benchmark for global-signal emulation and is described as the most accurate emulator in the community, with later work comparing faster alternatives such as 21cmKAN against it rather than against earlier feedforward baselines [2410.07619][2508.11752].

## 1. Scientific object and problem setting

The quantity emulated by 21cmLSTM is the global 21 cm differential brightness temperature, denoted \(\delta T_b(\nu)\), \(\delta T_b(z)\), \(T_{21}\), or similar notation depending on the source. This signal traces the thermal and ionization history of the intergalactic medium through the Dark Ages, Cosmic Dawn, and the Epoch of Reionization. In the formulation summarized for 21cmLSTM, a standard expression is
$$
T_{21}(z) \approx 27\,x_{\mathrm{HI}}(z)\sqrt{\frac{1+z}{10}}
\left[1-\frac{T_\gamma(z)}{T_s(z)}\right]\ \mathrm{mK},
$$
where \(x_{\mathrm{HI}}\) is the neutral hydrogen fraction, \(T_s\) the spin temperature, and \(T_\gamma\) the CMB temperature. The emulator does not derive these quantities from first principles; rather, it learns the mapping from model parameters \(\theta\) to the simulator-produced signal \(\theta \mapsto \delta T_b\) [2410.07619].

The methodological motivation is specific to global-signal inference. Semi-analytical and semi-numerical simulators are substantially cheaper than full hydrodynamical calculations, but they remain too slow for repeated evaluation in nested-sampling or MCMC analyses. The central requirement emphasized in the 21cmLSTM work is that emulator error must be much smaller than the observational noise, denoted \(\sigma_{21}\), otherwise Bayesian posteriors become biased. The paper reports that when emulator rms error is \(\lesssim 1\)–\(5\%\) of \(\sigma_{21}\), posterior constraints are unbiased; 21cmLSTM was designed to satisfy that condition even for optimistic noise levels such as \(\sigma_{21}=5\) mK [2410.07619].

This framing also explains the specific appeal of an LSTM. Earlier global 21 cm emulators treated the spectrum more like a static multivariate regression target, whereas 21cmLSTM treats it as a correlated sequence across adjacent redshift or frequency bins. That choice is physically motivated by the smooth, temporally correlated evolution of the absorption trough, heating transition, and reionization shoulder [2410.07619][2509.00976].

## 2. Signal representation and modeled parameter spaces

21cmLSTM maps a compact parameter vector to the full one-dimensional global-signal sequence over a fixed grid. The later comparative work summarizes the input dimensionality as typically \(7\)–\(8\) physical parameters, while the output is the global 21 cm brightness temperature sequence over \(z \approx 5\)–\(50\) or \(\nu \lesssim 235\) MHz, with \(\Delta z = 0.1\). The 21cmGEM dataset uses \(451\) bins and the ARES dataset \(449\) bins [2508.11752].

The primary benchmark dataset in the original 21cmLSTM paper is the public 21cmGEM set. It varies seven parameters:

- \(f_*\): star formation efficiency; log-uniform in \([10^{-4}, 5\times10^{-1}]\)
- \(V_c\): minimum circular velocity of star-forming halos; log-uniform in \([4.2, 100]\) km s\(^{-1}\)
- \(f_X\): X-ray efficiency; log-uniform in \([10^{-6}, 10^3]\)
- \(\tau\): CMB optical depth; uniform in \([0.04, 0.2]\)
- \(\alpha\): slope of the X-ray spectral energy distribution; uniform in \([1, 1.5]\)
- \(\nu_{\min}\): low-energy cutoff of the X-ray SED; uniform in \([0.1, 3]\) keV
- \(R_{\mathrm{mfp}}\): ionizing mean free path; uniform in \([10, 50]\) Mpc

For this dataset, the redshift range is \(z \in [5,50]\) with \(\Delta z = 0.1\), corresponding to \(\nu \simeq 27.8\)–\(236.7\) MHz, and the physically motivated sampling constraint \(x_{\mathrm{HI}}<16\%\) at \(z=5.9\) is imposed. The split used in the original work is train \(=24{,}562\), validation \(=2{,}730\), test \(=1{,}704\) [2410.07619].

A second benchmark family uses ARES, a semianalytical model with one-dimensional radiative transfer and no 3D volumes. In the comparative literature, the varied parameters are \(f_{*,0}\), \(T_{\min}\), \(c_X\), \(\log N_{\mathrm{HI}}\), \(M_p\), \(\gamma_{\mathrm{lo}}\), \(\gamma_{\mathrm{hi}}\), and \(f_{\mathrm{esc}}\), with ranges given by the ARES training set; the signal coverage is \(z=5.1\)–\(49.9\), \(\Delta z=0.1\), with \(449\) bins and the condition \(x_{\mathrm{HI}}<5\%\) at \(z=5.3\). The explicit split reported in the 21cmLSTM paper is train \(=23{,}896\), validation \(=2{,}656\), test \(=1{,}704\) [2508.11752][2410.07619].

These parameterizations encode the main astrophysical drivers of the global signal. In the 21cmGEM interpretation given by the original paper, \(f_*\) and \(V_c\) regulate when and how efficiently galaxies form, \(f_X\), \(\alpha\), and \(\nu_{\min}\) regulate the timing and spectrum of X-ray heating, \(\tau\) constrains the integrated ionizing history, and \(R_{\mathrm{mfp}}\) affects the morphology and percolation of H II regions during reionization [2410.07619].

## 3. Recurrent architecture, sequence modeling, and preprocessing

21cmLSTM is explicitly a recurrent, memory-based architecture. The later summaries characterize it as a network chosen for sequential modeling of \(\delta T_b\) across redshift or frequency, using gated memory and backpropagation through time to capture temporal dependencies. In the original implementation, the core architecture consists of two stacked LSTM layers operating in many-to-many mode, followed by a final dense layer with linear activation that produces \(\delta T_b(\nu)\) for each channel. The implementation is in Python with Keras/TensorFlow, and the optimizer is Adam [2508.11752][2410.07619].

The LSTM recurrence is described in the later lunar-far-side overview by the standard gate equations
$$
i_t = \sigma(W_i x_t + U_i h_{t-1} + b_i),\qquad
f_t = \sigma(W_f x_t + U_f h_{t-1} + b_f),
$$
$$
\tilde{c}_t = \tanh(W_c x_t + U_c h_{t-1} + b_c),\qquad
c_t = f_t \odot c_{t-1} + i_t \odot \tilde{c}_t,
$$
$$
o_t = \sigma(W_o x_t + U_o h_{t-1} + b_o),\qquad
h_t = o_t \odot \tanh(c_t).
$$
This formulation is central to why 21cmLSTM differs from feedforward emulators: the hidden and cell states propagate information across the full sequence, so adjacent and widely separated bins are not predicted independently [2509.00976].

The input representation is also sequence-aware. The original paper states that the network input is a three-dimensional array of shape \((N,n,p)\), where \(N\) is the batch size, \(n\) the sequence length, and \(p\) the number of physical parameters plus one for the frequency value itself. For the 21cmGEM set, \((N,n,p)=(24{,}562,451,8)\); for ARES, \((23{,}896,449,9)\). Including frequency as a feature is intended to help the network learn the global trend [2410.07619].

Preprocessing is uniform across the emulator comparisons. Parameters sampled log-uniformly are transformed with \(\log_{10}\) before training: \(f_X\), \(V_c\), and \(f_*\) for 21cmGEM; \(c_X\), \(T_{\min}\), \(f_{*,0}\), and \(M_p\) for ARES. Features and labels are then globally min–max normalized according to
$$
\tilde{x}=\frac{x-x_{\min}}{x_{\max}-x_{\min}}.
$$
The signal labels are flipped to run from high \(z\) to low \(z\) during training, i.e. descending redshift and ascending frequency [2410.07619][2508.11752].

The training protocol reported in the original paper uses a batch-size schedule rather than learning-rate decay: \(75\) epochs with batch size \(10\), then \(25\) epochs with batch size \(1\), then \(75\) epochs with batch size \(10\). Total training time is reported as \(\simeq 12.4\) hr per trial on one NVIDIA A100 GPU with \(\simeq 6\) GB memory usage. Early stopping was not used in that work; the number of epochs was chosen empirically. A later overview notes that standard deep-learning stacks such as TensorFlow/Keras or PyTorch are supported in the public implementation, with validation splits and early stopping available in repository configurations [2410.07619][2509.00976].

## 4. Accuracy, error metrics, and benchmark performance

The principal training objective for 21cmLSTM is mean squared error,
$$
\mathrm{MSE}=\left\langle \left(\delta T_{b,\mathrm{true}}(\nu)-\delta T_{b,\mathrm{emulated}}(\nu)\right)^2 \right\rangle.
$$
For test evaluation, the main metric is a relative rms error across the full frequency range,
$$
\mathrm{Error}=\frac{\sqrt{\mathrm{MSE}}}{\max(|\delta T_b(\nu)|)}.
$$
The paper also notes an alternative relative rms definition,
$$
\epsilon_{\mathrm{rel}}=\sqrt{\frac{\sum_i(\hat T_{21}(\nu_i)-T_{21}(\nu_i))^2}{\sum_i T_{21}(\nu_i)^2}}\times 100\%,
$$
but emphasizes the ratio of rms residual to signal amplitude for stability across diverse signals [2410.07619].

On the held-out 21cmGEM test set of \(1{,}704\) signals, aggregated over \(20\) independent training trials, 21cmLSTM achieves:

- average mean relative rms error \(=0.223\%\pm 0.031\%\)
- average median error \(=0.197\%\pm 0.025\%\)
- average maximum error \(=0.824\%\pm 0.183\%\)

These correspond to \(0.389\) mK \(\pm 0.047\) mK in absolute units for the average mean error. The best trial reaches mean \(0.18\%\) (\(0.30\) mK), median \(0.16\%\) (\(0.26\) mK), and max \(0.75\%\) (\(1.34\) mK) [2410.07619].

The same work reports a single-signal wall-clock evaluation time of \(46\) ms, averaged across \(20\) trials on the same hardware used for training, including preprocessing and de-normalization. Relative to earlier feedforward emulators on the same dataset, the reported comparisons are:

- 21cmLSTM: \(46\) ms, mean error \(\simeq 0.22\%\), max \(\simeq 0.82\%\)
- 21cmVAE: \(74\) ms measured in that work, mean error \(\simeq 0.35\%\), max \(\simeq 1.84\%\)
- globalemu: \(\simeq 3\) ms, mean error \(\simeq 1.12\%\), max \(\simeq 6.32\%\)
- 21cmGEM: \(\simeq 160\) ms, mean error \(\simeq 1.59\%\), max \(\simeq 10.55\%\)

The original paper therefore reports that 21cmLSTM reduces average mean error by \(\simeq 1.6\times\) and maximum error by \(\simeq 2\times\) relative to 21cmVAE, while remaining practically fast for inference [2410.07619].

Subsequent comparisons with 21cmKAN sharpen the interpretation of these results. On the 21cmGEM test set, 21cmLSTM remains slightly more accurate than 21cmKAN, with average mean relative rms error \(0.22\%\) versus \(0.25\%\) and average maximum error \(0.82\%\) versus \(1.09\%\). However, 21cmKAN evaluates in \(3.7\) ms per signal and trains about \(75\times\) faster than 21cmLSTM on the same A100 GPU. This later work therefore positions 21cmLSTM as the accuracy leader and 21cmKAN as the speed leader for low-dimensional global-signal emulation [2508.11752].

## 5. Bayesian parameter estimation and pipeline integration

A primary purpose of 21cmLSTM is direct insertion into Bayesian inference pipelines. The original validation uses seven-dimensional nested-sampling analyses with MultiNest, \(1{,}200\) live points, default evidence tolerance and sampling efficiency, and priors matched to the 21cmGEM training ranges. Mock data are drawn from the test set and perturbed with white Gaussian noise at \(\sigma_{21}=25\) mK, \(10\) mK, and \(5\) mK [2410.07619].

The likelihood used in the comparative papers is Gaussian with diagonal covariance:
$$
\ln \mathcal{L}(\theta)= -\frac{1}{2}\sum_i \frac{[d(\nu_i)-m(\nu_i;\theta)]^2}{\sigma_{21}^2}+\mathrm{const},
$$
or, equivalently in matrix form,
$$
\mathcal{L}(\mathbf d\mid \boldsymbol\theta)\propto
\exp\!\left[-\tfrac12(\mathbf d-\mathbf m(\boldsymbol\theta))^\top
C^{-1}(\mathbf d-\mathbf m(\boldsymbol\theta))\right].
$$
Here \(d\) is the observed spectrum, \(m(\theta)\) the emulator prediction or the full mean model, and \(C\) the noise covariance, often taken as diagonal in the validation studies. The posterior is written as
$$
P(\theta\mid D,m)=\frac{\mathcal{L}(\theta)\pi(\theta)}{Z}.
$$
This establishes 21cmLSTM as a surrogate forward model rather than a standalone inference engine [2410.07619][2508.11752].

The reported posterior behavior is a central result. Across the three adopted noise levels, the posterior \(1\sigma\) rms error on the recovered signals is consistently about three times smaller than \(\sigma_{21}\):

- \(\sigma_{21}=25\) mK \(\rightarrow\) posterior \(1\sigma\) rms \(\simeq 7.9\) mK
- \(\sigma_{21}=10\) mK \(\rightarrow\) posterior \(1\sigma\) rms \(\simeq 2.9\) mK
- \(\sigma_{21}=5\) mK \(\rightarrow\) posterior \(1\sigma\) rms \(\simeq 1.6\) mK

As \(\sigma_{21}\) decreases, the posterior mean residual approaches the emulator rms error, reported as \(\simeq 0.33\) mK in one example. Parameter posteriors are described as unbiased, with especially clear constraints for \(f_*\), \(V_c\), and \(\tau\) at \(\sigma_{21}=25\) mK and improved constraints for \(f_X\) and \(\nu_{\min}\) at \(5\)–\(10\) mK [2410.07619].

Later work broadens the pipeline context. It states that 21cmLSTM and 21cmKAN can be used with nested samplers such as MultiNest, PolyChord, UltraNest, and Dynesty, and that the emulator provides only the cosmological signal. Foreground and instrument terms must be added in the full likelihood, with nuisance parameters for beam chromaticity, bandpass structure, gain drifts, and related systematics. This is especially relevant for lunar far-side observational concepts such as LuSEE-Night and FarView, which benefit from the Moon’s radio-quiet environment but still require internal instrument modeling [2509.00976].

## 6. Comparative position, limitations, and reproducibility

Within the global 21 cm emulator literature, 21cmLSTM occupies a specific niche. It is the memory-based model that explicitly exploits temporal correlations across frequency or redshift bins and, in the cited comparisons, remains the most accurate emulator for the task. The later KAN paper is explicit that 21cmLSTM is the best choice when maximizing emulation accuracy is paramount and training or inference resources are available. By contrast, 21cmKAN is presented as preferable when emulator training would otherwise become the bottleneck, because it maintains similar accuracy while training about \(75\times\) faster and predicting about \(5\times\) faster [2508.11752].

Its limitations are correspondingly well defined. Because it is recurrent and trained with backpropagation through time, 21cmLSTM is slower to train and more memory intensive than fully parallel feedforward alternatives. The comparative papers also note a larger trainable-parameter count and heavier memory footprint than KAN, even though exact counts are not provided there. In the original validation, inference tests assume diagonal, frequency-independent Gaussian noise, and they do not include foregrounds, beam chromaticity, or instrument systematics in the likelihood; these omissions are identified as validation assumptions rather than claims about realistic end-to-end analysis [2410.07619][2508.11752].

Another limitation is domain specificity. As with all emulators, 21cmLSTM is guaranteed to be accurate only within the parameter domain represented by its training data. The later overview makes this explicit: extrapolation to unseen regimes or substantially different physics can degrade performance, so retraining is recommended when the forward model or parameterization changes. A related point is that emulator fidelity does not remove the need for careful treatment of foreground and instrumental degeneracies; the emulator supplies \(\delta T_b(\nu)\), not a complete observational forward model [2509.00976].

The software and datasets were released for reproducibility and reuse. The public repository is listed as `https://github.com/jdorigojones/21cmLSTM`, and the associated Zenodo datasets are given as DOI `10.5281/zenodo.5084113` and DOI `10.5281/zenodo.13840725`. The original paper emphasizes that the emulator, code, and datasets are publicly available so that 21cmLSTM can be independently tested, retrained, and applied to other 21 cm model families [2410.07619].

In that sense, 21cmLSTM is both a specific emulator architecture and a reference point in the methodological evolution of global-signal analysis. It established recurrent sequence modeling as a high-accuracy strategy for \(\theta \mapsto \delta T_b\) emulation, demonstrated that sub-mK average rms error is compatible with practical evaluation times, and provided a benchmark against which newer architectures such as 21cmKAN are now assessed [2410.07619][2508.11752].

Source: https://www.emergentmind.com/topics/21cmlstm