Preprint
Article

This version is not peer-reviewed.

CosmoTok: Adversarial Finite-Scalar Quantization for High-Fidelity Reconstruction of Cosmological Convergence Maps

Submitted:

24 November 2026

Posted:

26 November 2026

You are already at the latest version

Abstract
High-fidelity reconstruction of cosmological convergence maps is a prerequisite for building generative surrogate models that can replace expensive N-body simulations in simulation-based inference (SBI). We present CosmoTok, a MagViT-based autoencoder with Finite Scalar Quantization (FSQ) and adversarial training that achieves high-quality reconstruction of CosmoGridV1 weak-lensing convergence maps. Starting from a baseline FSQ autoencoder with log-normal preprocessing, we systematically introduce a PatchGAN discriminator with adaptive weight balancing, an LPIPS perceptual loss with a learnable ChannelAdapter for single-channel cosmological data, learnable log-variance NLL weighting, and FSQ quantization annealing. On the CosmoGridV1 dataset, the adversarial model achieves SSIM of 0.94 and PSNR exceeding 35 dB, significantly improving structural and statistical fidelity over the baseline. The reconstructed maps preserve power spectra, peak counts, and morphological features critical for downstream cosmological parameter constraints. Our reconstruction framework provides the foundational tokenization stage for future generative surrogate models and SBI pipelines, enabling fast generation of cosmological fields for scientific applications.
Keywords: 
;  ;  ;  

1. Introduction

Modern cosmology has entered an era of data abundance. Large-scale spectroscopic and imaging surveys— the Dark Energy Spectroscopic Instrument (DESI) [1,2,3,4], the Rubin Observatory Legacy Survey of Space and Time (LSST) [5,6,7], the Chinese Space Station Telescope (CSST) [8], the ESA Euclid [9] —are poised to deliver petabyte-scale datasets that demand inference methods capable of exploiting the full field-level information content of cosmological observations [10,11]. Weak gravitational lensing, which measures the coherent distortion of galaxy shapes induced by the projected matter distribution along the line of sight, stands as one of the most powerful probes for constraining the dark energy equation-of-state parameters w 0 and w a  [12,13,14,15]. The standard analysis pipeline compresses lensing convergence maps into two-point statistics—angular power spectra C ℓ —and evaluates a Gaussian likelihood via Markov chain Monte Carlo (MCMC) sampling [16,17]. While this approach has yielded competitive constraints from Stage-III surveys, it suffers from an inherent information loss: two-point compression discards the non-Gaussian statistical content—peak counts, void distributions, filamentary connectivity, and higher-order correlations—that is known to carry substantial cosmological information on nonlinear scales [18,19].
SBI has emerged as a principled framework that circumvents these limitations by learning the posterior p ( θ | x ) or the likelihood p ( x | θ ) directly from large number of forward-simulated pairs ( θ ( n ) , x ( n ) ) using advanced density estimation techniques. Neural likelihood estimation [20] (NLE) and Neural posterior estimation (NPE) [19], which parameterize the conditional distribution with a normalizing flow conditioned, has demonstrated state-of-the-art cosmological constraints from galaxy clustering, weak lensing, and CMB data. Yet the practical deployment of SBI encounters a formidable computational bottleneck: the forward model that generates the simulated observations is an N-body or hydrodynamical cosmological simulation, and each such simulation is extraordinarily expensive [21,22,23].
State-of-the-art hydrodynamical cosmological simulations [24,25,26,27]—such as the IllustrisTNG suite—achieve remarkable physical fidelity by resolving galaxy formation, AGN feedback, and radiative processes within a cosmological volume [26,28]. However, this fidelity comes at a steep computational price: a single TNG300 run consumes O ( 10 5 - - 10 6 ) CPU-hours on dedicated supercomputing facilities, demanding substantial storage for particle snapshots and halo catalogs. For pure N-body simulations of Stage-IV survey volumes, the cost is O ( 10 4 - - 10 5 ) CPU-hours per realization [6,29]. SBI training further amplifies this cost: the posterior estimator requires O ( 10 3 - - 10 4 ) distinct parameter–data pairs drawn from across the prior, each necessitating an independent simulation run. Consequently, the total computational budget for a single SBI experiment can reach O ( 10 7 - - 10 9 ) CPU-hours—a scale that is practically unattainable even on the largest available high-performance computing platforms [21]. This computational bottleneck not only limits the number of available training simulations but also constrains parameter space exploration, preventing the systematic investigation of extended cosmological models (e.g., dynamical dark energy, modified gravity, or varying neutrino mass) that next-generation surveys are specifically designed to test.
It is against this backdrop that cosmological emulators—AI-driven surrogate models that replace expensive forward simulations with fast, data-driven approximations—have emerged as a compelling and increasingly viable alternative [29,30]. Rather than running a full N-body or hydrodynamical simulation for each desired set of cosmological parameters, an emulator learns the mapping θ ↦ x from a pre-computed training set and generates simulated observations at a fraction of the computational cost, reducing the wall-clock time from hours or days to seconds or even milliseconds [31,32]. This reduction by orders of magnitude in generation cost enables on-the-fly training data production for SBI, liberating the inference pipeline from dependence on fixed, pre-computed simulation suites and opening the possibility of adaptive sampling strategies that concentrate computational effort in the regions of parameter space most informative for a given observation [33].
The central design challenge for a cosmological emulator is ensuring that its outputs preserve the statistical fidelity of the underlying simulations—not merely visual similarity, but accurate reproduction of those statistical features that carry cosmological information: angular power spectra C ℓ , peak count distributions, bispectra, and morphological descriptors such as Minkowski functionals. Any systematic distortion introduced at the emulation stage propagates directly into the posterior estimates, potentially yielding biased parameter constraints or miscalibrated credible intervals.
A promising route to building such an emulator proceeds through latent tokenization: first, an autoencoder compresses N-body convergence maps into compact quantized latent representations that faithfully represent the original field; then, a generative model (e.g., diffusion or flow-based) learns the conditional prior p ( z ^ | θ ) over these latent representations, generating maps given cosmological parameters. The fidelity of the entire emulator chain hinges on the quality of the first stage—the tokenization. If the latent representation systematically distorts power spectra, underestimates peak counts, or corrupts higher-order correlations, these errors propagate through the surrogate and into biased cosmological parameter estimates.
This paper addresses the foundational stage of this pipeline: the reconstruction of CosmoGridV1 convergence maps via a physics-aware autoencoder with adversarial training. Building on the MagViT architecture with FSQ, we systematically introduce a PatchGAN discriminator with adaptive weight balancing, an LPIPS perceptual loss adapted for single-channel astronomical data via a learnable ChannelAdapter, learnable log-variance NLL weighting, and FSQ quantization annealing. We demonstrate that the adversarial model achieves significantly higher reconstruction fidelity than the baseline—preserving per-patch flat-sky power spectra to 1.5% relative error, peak count correlations above 0.97, and Minkowski functional accuracy within 2%—establishing the latent tokenization as a reliable foundation for downstream surrogate modeling and SBI.
The remainder of this paper is organized as follows. Section 2 describes the CosmoGridV1 dataset. Section 3 presents the baseline and adversarial reconstruction methods. Section 4 analyzes reconstruction fidelity using SSIM, PSNR, and power spectrum metrics. Section 5 concludes with a discussion of how this reconstruction stage serves future surrogate modeling and SBI applications.

2. Dataset: CosmoGridV1

2.1. CosmoGridV1 Simulation Suite

CosmoGridV1 [34] is a large lightcone simulation suite designed specifically for map-level, simulation-based cosmological inference with probes of large-scale structure. It was created at the Swiss National Supercomputing Center (CSCS) using the PkdGrav3 N-body code [35] with GPU acceleration on the Piz Daint cluster, consuming approximately 750,000 GPU node-hours. The suite is publicly available 1 and has been used in KiDS-1000 deep learning cosmological analyses and DES combined probe measurements [36].
CosmoGridV1 spans the wCDM cosmological model by varying six parameters: matter density Ω m , matter clustering amplitude σ 8 , dark energy equation of state w 0 , spectral index n s , baryon density Ω b , and Hubble constant H 0 (with fixed neutrino mass ∑ m ν = 0.06 eV, three degenerate species). The parameter space is covered by 2500 grid points sampled on a Sobol low-discrepancy sequence, divided evenly into “wide” and “narrow” prior regions. The narrow prior concentrates sampling in the region favored by existing CMB and LSS observations. An additional restriction removes combinations of Ω m and w 0 that cause the relativistic field treatment to diverge, and Ω m – σ 8 corner combinations outside the observed S 8 degeneracy are excluded.
The fiducial cosmology ( Ω m = 0.26 , σ 8 = 0.84 , w 0 = − 1.0 , n s = 0.9649 , Ω b = 0.0493 , H 0 = 67.3 ) has 200 independent simulations from unique initial conditions, each with ± Δ stencil derivative steps for all six parameters, enabling finite-difference gradient computation for inference methods that require it.
Each grid point has 7 independent N-body simulations with unique initial conditions, yielding a total of 17,500 grid runs plus 2,600 fiducial and derivative runs, for a grand total of 20,128 simulations. The main configuration uses box size L box = 900 Mpc / h with 832 3 particles per simulation (particle mass M ∼ 9.08 × 10 10 h − 1 M ⊙ at the fiducial cosmology). A novel shell permutation scheme combines shells from the 7 independent simulations to construct lightcones where no line of sight passes through the same structure across replicated boxes, eliminating the box replication artifact that would otherwise bias map-level statistics.
The lightcone consists of 69 particle count shells stored at HEALPix n side = 2048 resolution up to z = 3.5 , with shell thickness increasing with redshift ( Δ shell ≈ 40 , 55, 90 Mpc/h at z = 0 , 0.5, 1.5 respectively). Friends-of-friends halo catalogs with NFW profile fits are stored at each timestep. From these raw shells, projected maps of weak lensing convergence κ , intrinsic alignment, and galaxy density are created using the UFalcon code with the Born approximation, integrating the shell particle density against the relevant probe kernel for a given source redshift distribution n ( z ) . A set of 28 benchmark simulations with increased box size ( L box = 2250 Mpc / h ), increased particle count ( 2048 3 ), and increased redshift resolution (500 timesteps) allows systematic testing of whether analysis choices (feature vectors, summary statistics, machine learning architectures) are robust against the main simulation configuration. Baryonic feedback effects are incorporated via a shell baryonification method [37], which displaces particles in the raw shell maps according to halo-level profiles parameterized by a gas ejection mass scale M c 0 and its redshift evolution ν . This enables on-the-fly inclusion of baryon corrections for different feedback models without re-running the simulations.
For our reconstruction experiments, we extract single-channel convergence maps from the projected weak lensing output. Each full-sky convergence map κ ( θ ) is stored as a HEALPix all-sky map at resolution N side = 512 , which sets the maximum recoverable multipole at ℓ max < 1535 . The dataset is split into N train = 5000 and N test = 500 cosmological realizations spanning the full 6-dimensional parameter space. We note that for our experiments we use a 5-dimensional subspace ( Ω m , σ 8 , w 0 , w a , h ) , consistent with the cosmological parameters most relevant for weak lensing constraints.

2.2. Data Preprocessing: Spherical Patch Segmentation

The autoencoder requires planar image patches as input, but the raw CosmoGridV1 data are HEALPix all-sky maps [38]. We therefore partition each full-sky map into a set of non-overlapping patches using the hierarchical structure of the HEALPix pixelization [39,40,41].
HEALPix organizes pixels on the sphere in a nested hierarchy: each pixel at resolution N side can be subdivided into four child pixels at resolution 2 N side . We exploit this property by using the N side base = 4 pixelization as our segmentation grid. At this base resolution, the sphere is partitioned into N patch = 12 × ( N side base ) 2 = 192 equal-area pixels. Each base pixel encompasses a subtree of ( N side / N side base ) 2 = ( 512 / 4 ) 2 = 16 , 384 HEALPix pixels at the native N side = 512 resolution, which we reshape into a 128 × 128 planar image patch. Formally, for the p-th base pixel ( p = 1 , … , 192 ), we extract:
κ p = E p κ ( θ ) ∈ R 1 × 128 × 128 ,
where E p is the HEALPix-to-patch extraction operator that maps the subtree of N side = 512 pixels nested under base pixel p to a 128 × 128 raster following the HEALPix nested ordering. Each cosmological realization thus yields 192 patches, producing a total training set of N train × N patch = 5000 × 192 = 960 , 000 patches and a test set of 500 × 192 = 96 , 000 patches.
At any observational scale, cosmological fields contain physically correlated structures that span multiple patches. Partitioning the all-sky map into independent regions necessarily discards cross-patch correlations—large-scale modes ( ℓ ≲ 30 ) whose coherence length exceeds the angular extent of a single N side base = 4 pixel ( ∼ 15 ∘ ) are partially lost. However, this information loss is acceptable for the present reconstruction stage for two reasons. First, the autoencoder is trained to learn a per-patch representation; its objective is to faithfully encode the local structure within each patch, not to model global correlations. Second, the cross-patch information is recovered in the downstream multimodal model, where the patch sequence is processed jointly with explicit spherical positional encodings. Specifically, for patches belonging to the same all-sky map, we introduce a spherical relative position bias into the global self-attention mechanism. Let u i and u j denote the unit direction vectors of the centers of patches i and j on the sphere, with angular separation γ i j satisfying cos γ i j = u i · u j . A learnable mapping f ( · ) converts the angular distance into an attention bias:
b i j = f ( cos γ i j ) ,
which is added to the scaled dot-product attention logits. This enables the downstream model to explicitly exploit the spherical geometric relationships among patches when learning cross-patch correlations, recovering the large-scale information that the spatial partitioning alone would discard.
The convergence patches exhibit a strongly non-Gaussian distribution due to nonlinear gravitational evolution. The pixel values span several orders of magnitude with a heavy right tail from high-density clusters and a long left tail from underdense voids. The complex morphological structure—a cosmic web of halos, filaments, sheets, and voids—carries cosmological information beyond what is captured by two-point statistics alone. Peak counts, Minkowski functionals, and bispectra provide complementary constraints on σ 8 and w 0 that are inaccessible to power spectrum analyses [42,43].
We adopt a log-normal preprocessing pipeline: κ ^ = ( log κ − μ log ) / σ log , where μ log = − 4.9179 and σ log = 0.4947 are computed from the training set. This transformation approximately normalizes the pixel distribution and stabilizes the reconstruction loss, ensuring that the autoencoder devotes equal attention to the bulk of the density field and the rare high-density regions. The inverse transformation κ = exp ( σ log κ ^ + μ log ) recovers the original convergence values after decoding.

3. Method

3.1. Shared Architecture

Both models use the same encoder–quantizer–decoder pipeline, built on the AION (Anything Tokenizer) framework with a MagViT autoencoder backbone and FSQ [44,45]. The baseline and adversarial models share the architecture hyperparameters listed in Table 1, allowing reconstruction quality to be compared at fixed model architecture. Their training objectives and optimization settings are described separately below.
The encoder processes a log-normalized convergence patch κ ^ ∈ R 1 × 128 × 128 through three stages. First, a strided Conv2d ( 2 × 2 , stride 2) downsamples the single-channel input to c down = 128 channels at 64 × 64 resolution. Second, a MagViT encoder with n compress = 2 spatial compression stages and n consecutive = 4 residual units per stage progressively reduces the spatial resolution to 16 × 16 with hidden dimension d = 768 . Each residual unit consists of two 3 × 3 convolutions with group normalization, GELU activation, and a Squeeze-and-Excite (SE) block for global context aggregation. The spatial downsampling uses strided convolutions, while the decoder uses pixel-shuffle upsampling. Third, a 1 × 1 Conv2d projects the 768-dimensional feature map to the FSQ embedding dimension d e = 8 .
FSQ maps each eight-dimensional latent vector onto a Cartesian grid by independently quantizing its scalar components. Unlike vector quantization in VQ-VAE, it does not require nearest-neighbor lookup in a learned embedding table. For the odd-valued levels used in all configurations considered here, the implemented quantization rule is
m i = ( L i − 1 ) / 2 , b i ( z i ) = m i ( 1 + ϵ ) tanh ( z i ) , z ^ i = round STE b i ( z i ) m i ,
where z i is the encoder output in dimension i, L i is the number of scalar levels, and ϵ = 10 − 3 is the small expansion factor used in the bounding function. The straight-through rounding operator is defined as round STE ( x ) = x + sg [ round ( x ) − x ] , where sg denotes stop-gradient. Its forward value is the rounded integer, while its derivative with respect to x is taken to be unity during backpropagation. For the levels used here, rounding produces integers from − m i to m i ; division by m i therefore gives exactly L i possible values in [ − 1 , 1 ] , with spacing 1 / m i . Our main configuration uses L = ( 17 , 17 , 17 , 17 , 13 , 13 , 13 , 13 ) , giving spacings of 1 / 8 and 1 / 6 in the first and last four dimensions, respectively. The effective codebook size is the number of Cartesian-product combinations, N code = ∏ i = 1 d e L i = 17 4 × 13 4 ≈ 2.4 × 10 9 . This implicit grid requires neither a learned codebook nor commitment losses or exponential moving average updates. It avoids the need to maintain unused embedding entries, although uniform or complete use of the available combinations is not guaranteed.
The FSQ levels are chosen to preserve the reconstruction fidelity required for cosmological applications. Weak-lensing convergence maps contain non-Gaussian information associated with cluster peaks, peak counts, filamentary structures, and void boundaries, motivating a sufficiently fine quantization grid. The large effective codebook is an implicit Cartesian product of scalar levels and does not require storing billions of learned embeddings. We therefore prioritize quantization resolution over compatibility with a small categorical vocabulary. Section 4.3 evaluates this choice experimentally, while Section 4.4 discusses its implications for downstream generative modeling. The decoder mirrors the encoder: a 1 × 1 Conv2d projects the quantized 8-dimensional tokens back to 768 dimensions, the MagViT decoder reconstructs the 128-channel representation at 64 × 64 resolution via pixel-shuffle upsampling, and a strided ConvTranspose2d ( 2 × 2 , stride 2) upsamples from 128 channels back to 1 channel at 128 × 128 , producing the reconstructed patch κ ^ ′ .
During early training, rounding introduces discontinuities in the latent representation. Both models support an optional annealing schedule that bypasses rounding with probability p no _ quant . A Bernoulli mask is sampled independently for each sample and shared across its spatial positions and latent dimensions. When rounding is bypassed, the decoder receives the bounded, normalized value b i ( z i ) / m i rather than the raw encoder output. The bypass probability follows p no _ quant ( t ) = 1 2 [ 1 + cos ( π t / ( f T ) ) ] over the annealing interval 0 ≤ t ≤ f T , where f is the annealing factor and T is the total number of training steps. This gradually shifts training from continuous bounded latents to the discrete FSQ grid. At evaluation, rounding is always applied, so the reported reconstruction metrics use fully quantized latents.
Table 1 summarizes the architecture hyperparameters shared by both models.

3.2. Baseline: MSE-Only Training

The baseline model is trained with a simple pixel-level mean-squared error loss:
L base = 1 B ∑ b = 1 B ∥ κ ^ b − κ ^ b ′ ∥ 2 2 ,
where B = 128 is the batch size. The optimizer is AdamW [46] with learning rate 5 × 10 − 4 , betas= ( 0.9 , 0.999 ) , weight decay 10 − 5 , and a warmup-cosine learning rate schedule: linear warmup over the first 1000 steps followed by cosine decay over the remaining training. Training runs for 1001 epochs on 4 GPUs with gradient clipping (norm=1.0), using PyTorch Lightning’s automatic optimization.
The baseline provides a simple reference with a single optimizer and an MSE objective that directly penalizes pixel-level deviations. Although the neural-network optimization problem remains nonconvex, this setup provides a useful reference for assessing how the adversarial and perceptual objectives affect the structural and statistical fidelity of reconstructions obtained with the same MagViT+FSQ architecture.
However, the MSE loss has well-known limitations for cosmological applications. It penalizes all pixels equally, while cosmological information is concentrated in specific Fourier modes and morphological structures. The pixel-averaged objective encourages the model to produce smooth, blurry reconstructions that minimize the ℓ 2 norm by averaging over plausible structures rather than committing to specific high-frequency details. In practice, this manifests as systematic underestimation of peak counts (∼12%), smoothing of filamentary structures, and power spectrum deviations of ∼5%, particularly at high ℓ where small-scale structure carries substantial non-Gaussian information.

3.3. Adversarial Training with Perceptual Loss

To overcome the limitations of the MSE-only baseline, we introduce an adversarial training variant that augments the training objective with three complementary components: (1) a PatchGAN discriminator that provides patch-level structural feedback, (2) an LPIPS perceptual loss adapted for single-channel astronomical data via a learnable ChannelAdapter, and (3) a learnable log-variance NLL weighting that automatically balances the reconstruction, perceptual, and adversarial objectives [47]. The adversarial model uses manual optimization with alternating generator–discriminator updates.
The total generator loss is:
L gen = L NLL + w d · d f · L G ,
where L G = − E [ D ( κ ^ ′ ) ] is the non-saturating generator loss encouraging the discriminator to classify reconstructions as real, and d f is a warmup factor that ramps from 0 to 1 starting at step t disc = 4800 .
The NLL loss with learnable log-variance σ logvar 2 is:
L NLL = L rec + w p · L LPIPS exp ( σ logvar 2 ) + σ logvar 2 ,
where L rec = ∥ κ ^ − κ ^ ′ ∥ 2 2 / B is the pixel reconstruction loss and w p = 0.01 is the perceptual weight. The learnable σ logvar 2 provides automatic loss balancing: early in training, σ logvar 2 is small, emphasizing pixel-level reconstruction; as training progresses, it grows, shifting weight toward the perceptual and adversarial terms. This eliminates the need for manual loss schedule tuning.
The discriminator is trained with hinge loss:
L disc = d f · [ E [ max ( 0 , 1 − D ( κ ^ ) ) ] + E [ max ( 0 , 1 + D ( κ ^ ′ ) ) ] ] ,
where D is the PatchGAN discriminator operating on the full 128 × 128 single-channel convergence patch with 3 intermediate convolutional layers and 64 base filters. Unlike a global discriminator that produces a single real/fake score, the PatchGAN outputs a spatial grid of decisions, providing localized structural feedback that encourages the autoencoder to maintain consistent morphology across the entire map—peaks, filaments, and void boundaries alike.
A key challenge in adversarial training is preventing the discriminator from overwhelming the reconstruction objective. We compute an adaptive weight w d based on the ratio of gradient norms of L NLL and L G with respect to the last decoder layer θ last [48]:
w d = w disc _ base · ∥ ∇ θ last L NLL ∥ ∥ ∇ θ last L G ∥ + ϵ ,
where w disc _ base = 0.8 is the base discriminator weight and ϵ = 10 − 4 . This ensures the adversarial gradient magnitude matches the reconstruction gradient at every training step, preventing oscillation or mode collapse. The gradient norm ratio is computed via two separate backward passes through the last decoder layer, adding negligible overhead.
The LPIPS perceptual loss uses a pre-trained VGG-16 feature extractor to compare multi-scale deep features between original and reconstructed images. Since VGG-16 expects 3-channel RGB input but CosmoGridV1 maps are single-channel, we introduce a learnable ChannelAdapter C adap : a 1 × 1 convolution initialized with Kaiming-normal weights that projects 1 channel to 3 channels. The adapter is trained jointly with the autoencoder, learning the optimal projection for measuring perceptual similarity on cosmological data:
L LPIPS = ∑ l ∥ f l ( C adap ( κ ^ ) ) − f l ( C adap ( κ ^ ′ ) ) ∥ 2 2 ,
where f l extracts VGG features at layer l (relu1_2 through relu5_3). The perceptual loss complements the pixel-level MSE by penalizing structural differences—texture, edge sharpness, and local pattern consistency—that MSE treats as equivalent if the average pixel value is preserved.
The discriminator is not trained for the first t disc = 4800 steps (approximately 5 epochs at batch size 128), during which the autoencoder learns a reasonable baseline reconstruction using only L NLL . This warmup prevents the adversarial training from destabilizing the encoder–decoder at a stage when the discriminator’s feedback is essentially random noise. After t disc , the warmup factor d f transitions to 1.0, introducing the adversarial gradient gradually.
The adversarial model uses two separate optimizers with manual alternating updates. The autoencoder (generator) optimizer is AdamW ( lr = 5 × 10 − 5 , betas= ( 0.9 , 0.95 ) , weight decay=0.01, CosineAnnealing with T max = 1000 , η min = 10 − 6 ). The discriminator optimizer is Adam ( lr = 2 × 10 − 5 , betas= ( 0.5 , 0.9 ) ). The lower learning rates compared to the baseline ( 5 × 10 − 5 vs. 5 × 10 − 4 ) reflect the more complex loss landscape introduced by adversarial training. Training runs for 1001 epochs with batch size 128 on a single GPU, using DDP to handle the discriminator’s separate gradient graph. The AE optimizer updates the model parameters, ChannelAdapter parameters (if LPIPS enabled), and the learnable log-variance σ logvar 2 jointly in a single step.

4. Results

4.1. Pixel-Level and Visual Reconstruction Quality

We quantify pixel-level reconstruction quality using two standard image metrics. The peak signal-to-noise ratio (PSNR) is defined as:
PSNR = 20 log 10 ( d range MSE ) , MSE = 1 H W ∑ i , j κ i j − κ i j ′ 2 ,
where d range = max ( κ ) − min ( κ ) is the dynamic range of the ground-truth patch and H × W = 128 × 128 is the patch size. The structural similarity index (SSIM) measures global structural similarity:
SSIM = ( 2 μ κ μ κ ′ + C 1 ) ( 2 σ κ κ ′ + C 2 ) ( μ κ 2 + μ κ ′ 2 + C 1 ) ( σ κ 2 + σ κ ′ 2 + C 2 ) ,
where μ and σ 2 denote the pixel mean and variance, σ κ κ ′ is the covariance, C 1 = ( 0.01 d range ) 2 , and C 2 = ( 0.03 d range ) 2 . We additionally report the intersection over union (IoU) with binarization threshold τ = μ κ : IoU = | { ( κ > τ ) ∩ ( κ ′ > τ ) } | / | { ( κ > τ ) ∪ ( κ ′ > τ ) } | .
Table 2 summarizes the reconstruction metrics for both models. The adversarial model achieves consistently higher PSNR and SSIM than the baseline across all test samples.
The adversarial model improves PSNR by Δ PSNR = + 2.63 dB and SSIM by Δ SSIM = + 0.029 , while reducing MSE by 40%. The improvement is most pronounced in regions with complex morphological structures—filaments connecting clusters, void boundaries, and peak neighborhoods—where the PatchGAN discriminator encourages the autoencoder to preserve local structural patterns rather than averaging them out.
While PSNR and SSIM provide scalar summaries, visual inspection reveals the qualitative nature of the reconstruction errors and their spatial structure.
Figure 1 presents a representative comparison on the same slice. The top row shows the original convergence map κ (left), the baseline reconstruction κ base ′ (middle), and the adversarial reconstruction κ adv ′ (right). The bottom row shows the raw differences κ base ′ − κ (left), κ adv ′ − κ (middle), and κ adv ′ − κ base ′ (right). The baseline model produces visibly smoother reconstructions that blur peak structures and broadens void boundaries, with residuals exhibiting coherent spatial patterns. The adversarial model retains sharp peak morphology and accurate void boundaries, with residuals that are smaller in magnitude and substantially less spatially correlated.
We quantify the spatial structure of the residual field r = κ − κ ′ through its autocorrelation:
ρ r ( Δ θ ) = E [ r ( θ ) r ( θ + Δ θ ) ] σ r 2 ,
where σ r 2 = Var ( r ) . For the baseline model, ρ r exhibits significant spatial correlation with a correlation length ξ base ≈ 4.2 pixels, indicating that reconstruction errors are spatially coherent—the model systematically smooths structures at the ∼4-pixel scale. The adversarial model reduces the correlation length to ξ adv ≈ 1.8 pixels, indicating that residuals are substantially closer to uncorrelated noise. This reduction in spatial error correlation is critical for cosmological applications: correlated residuals introduce systematic biases in localized statistics (peak counts, Minkowski functionals), while uncorrelated residuals contribute only statistical noise that averages down with sample size.

4.2. Statistical Fidelity of the Reconstructed Field

The pixel-level and visual analyses above demonstrate high reconstruction quality in image space; we now assess the statistical fidelity of the reconstructed field.
We compute the angular power spectrum C ℓ of both original and reconstructed maps using a two-dimensional discrete Fourier transform.
For a flat-sky convergence map κ ( θ ) of size L × L with N × N pixels, the angular power spectrum is computed as:
C ℓ = L 2 N 4 | κ ˜ ( k ) | 2 | k | = ℓ / L ,
where κ ˜ ( k ) = DFT [ κ ] is the 2D discrete Fourier transform and 〈 · 〉 | k | = ℓ / L denotes the average over all Fourier modes with | k | in the annular bin corresponding to multipole ℓ. The convergence maps are extracted at HEALPix resolution N side = 512 , which sets the Nyquist limit at ℓ max < 3 N side − 1 = 1535 ; beyond this scale, the angular power spectrum is dominated by pixelization artifacts. We therefore restrict our analysis to ℓ ∈ [ 100 , 1535 ] . We apply a Tukey (tapered cosine) window with α = 0.1 to suppress spectral leakage from the finite field boundary, and use logarithmically-spaced ℓ bins from ℓ min = 100 to ℓ max = 1535 . For the full-sky map in Figure 2, we reassemble the 192 patches and compute the spherical C ℓ with spherical harmonic decomposition; this includes cross-patch phase coherence, so the full-sky ratio is lower at high ℓ than the per-patch flat-sky deviation.
We define the relative power spectrum deviation, δ ℓ ≡ C ℓ recon / C ℓ orig , which equals zero for perfect reconstruction and directly shows whether the reconstruction overestimates ( δ ℓ > 0 ) or underestimates ( δ ℓ < 0 ) the power at each scale. The mean absolute deviation over a multipole range [ ℓ a , ℓ b ] is δ ¯ = 1 N b ∑ ℓ i ∈ [ ℓ a , ℓ b ] δ ℓ i , where N b is the number of ℓ bins. We further define the power spectrum correlation coefficient:
r C ℓ = ∑ i ( C ℓ i orig − C ¯ ℓ orig ) ( C ℓ i recon − C ¯ ℓ recon ) ∑ i ( C ℓ i orig − C ¯ ℓ orig ) 2 ∑ i ( C ℓ i recon − C ¯ ℓ recon ) 2 ,
which measures the shape fidelity of the reconstructed power spectrum independent of any overall normalization offset.
Table 3 reports the power spectrum fidelity metrics for both models, decomposed into low-ℓ ( 100 ≤ ℓ < 500 ), intermediate-ℓ ( 500 ≤ ℓ < 1000 ), and high-ℓ ( 1000 ≤ ℓ ≤ 1535 ) regimes.
The adversarial model achieves δ ¯ = 1.5 % averaged over the full ℓ = 100 –1535 range, compared to 4.5% for the baseline. The improvement is concentrated at high ℓ (small angular scales), where the baseline’s smoothing effect reduces small-scale power by up to 8.2%. The adversarial model’s high-ℓ deviation of 2.4% is a 3.4× improvement, critical because high-ℓ modes carry substantial non-Gaussian cosmological information from nonlinear structure formation. The power spectrum correlation coefficient r C ℓ = 0.9991 for the adversarial model (vs. 0.9934 for baseline) confirms near-perfect shape preservation of the C ℓ curve. These numbers quantify local power fidelity within each 128 × 128 patch; the full-sky reassembled map is discussed below and shows a larger high-ℓ deficit.
The full-sky map in Figure 2 has less high-ℓ power than the per-patch flat-sky result in Table 3: reassembling the 192 independently tokenized patches does not preserve cross-patch phase coherence. This global loss is distinct from the local per-patch deviations and must be addressed before full-map applications.
Figure 2 shows the mean power spectra (top) and their relative deviations in the form C ℓ recon / C ℓ orig − 1 (bottom). In the top panel, the three C ℓ curves (ground truth, adversarial, baseline) are plotted together, where closer alignment to the ground truth indicates higher reconstruction fidelity. In the bottom panel, we directly compare the power spectrum of each reconstructed map against the original by computing the ratio C ℓ recon / C ℓ orig and subtracting unity. This ratio-minus-one form centers the comparison at zero—perfect reconstruction yields δ ℓ = 0 for all ℓ—making it straightforward to assess both the magnitude and sign of the deviation at each scale. The adversarial model (orange) stays within ± 3 % of zero across the full ℓ range, indicating that its reconstructed power remains within 3% of the true power at every angular scale. In contrast, the baseline (green) deviates by up to − 8 % at high ℓ, reflecting systematic suppression of small-scale power due to the MSE-driven smoothing effect.
While the power spectrum captures the two-point statistics of the convergence field, cosmological information also resides in higher-order statistics. Peak counts in convergence maps are sensitive to σ 8 and w a , providing non-Gaussian information beyond the power spectrum [42,49]. We define peak counts n peak ( ν ) as the number density of local maxima in the convergence field as a function of signal-to-noise threshold ν = κ / σ κ . The peak count correlation coefficient is:
r peak = ∑ ν ( n peak orig ( ν ) − n ¯ peak orig ) ( n peak recon ( ν ) − n ¯ peak recon ) ∑ ν ( n peak orig ( ν ) − n ¯ peak orig ) 2 ∑ ν ( n peak recon ( ν ) − n ¯ peak recon ) 2 .
The adversarial model achieves r peak = 0.97 between original and reconstructed peak count functions, compared to 0.88 for the baseline. The baseline systematically underestimates peak counts by ∼12% at ν > 3 (corresponding to massive cluster-scale halos), while the adversarial model reduces this bias to ∼3%. Table 4 quantifies the peak count fidelity.
We further assess morphological preservation using Minkowski functionals V 0 ( ν ) , V 1 ( ν ) , V 2 ( ν ) (area, perimeter, genus as functions of density threshold). The adversarial model reproduces all three functionals within 2% relative error, while the baseline deviates by 5–8%. The improvement in Minkowski functional fidelity confirms that the adversarial training preserves not just pixel-level accuracy but the topological and morphological structure of the density field—a prerequisite for unbiased cosmological constraints from non-Gaussian statistics.
Figure 3 further analyzes peak counts, presenting the full pixel-value distribution and the cumulative count of raw local maxima. These counts are cumulative above ν and use a different definition from the peak-count function summarized in Table 4: they are computed directly on the unsmoothed slices. Under this definition the baseline retains 67%, 56%, and 30% of pixels above the 99th, 99.9th, and 99.99th percentiles of the original, whereas the adversarial model retains 90%, 87%, and 65%; the maximum reconstructed values are 0.100 and 0.120, compared with 0.148 for the original. The same tail deficit appears in the peak counts: for 1 ≤ ν ≤ 6 , the baseline retains 31–38% of the original local maxima and the adversarial model 81–83%.

4.3. Ablation and Quantization Analysis

We now dissect the contribution of each adversarial component through ablation experiments, and analyze the sensitivity to FSQ quantization resolution.
Table 5. Ablation study: contribution of each adversarial component to reconstruction fidelity.
Table 5. Ablation study: contribution of each adversarial component to reconstruction fidelity.
Configuration PSNR SSIM IoU δ ¯ C ℓ r peak
Baseline (MSE only) 33.2 0.912 0.891 4.5% 0.88
   + PatchGAN ( w d = 0.5 ) 34.5 0.928 0.912 2.4% 0.93
   + PatchGAN ( w d = 0.8 ) 35.4 0.937 0.924 1.8% 0.95
   + Adaptive weight (Equation (8)) 35.8 0.940 0.930 1.5% 0.96
   + LPIPS + ChannelAdapter 35.8 0.941 0.932 1.5% 0.97
Each row adds one component to the previous configuration. PatchGAN with adaptive weight provides the largest improvement.
The PatchGAN discriminator with w d = 0.8 provides the largest single improvement, increasing SSIM from 0.912 to 0.937 and reducing the per-patch flat-sky power spectrum error from 4.5% to 1.8%. The adaptive weight balancing (Equation (8)) is essential: without it, a fixed discriminator weight either under-constrains the reconstruction ( w d too low) or destabilizes training ( w d too high). The LPIPS perceptual loss with ChannelAdapter provides marginal additional gains on single-channel CosmoGridV1 data but is expected to be more important for multi-channel astronomical images (HSC+DES) where VGG features capture cross-band correlations.
The delayed discriminator start ( t disc = 4800 ) is critical for training stability: without it, the discriminator provides noisy gradient signals during the first ∼5000 steps when the autoencoder has not yet learned a reasonable reconstruction, leading to training collapse or mode dropping.
The learnable log-variance σ logvar 2 in Equation (6) automatically adjusts the relative weighting of reconstruction vs. perceptual loss. Early in training, σ logvar 2 is small, emphasizing pixel-level reconstruction. As training progresses, σ logvar 2 increases, shifting weight toward the perceptual and adversarial terms that refine structural details.
The ablation above confirms that adversarial training is essential for high-fidelity reconstruction. We now examine the complementary question: how does the FSQ quantization resolution affect the achievable quality, independently of the training strategy?
The FSQ configuration introduced in Section 3.1 uses d e = 8 dimensions with levels L = ( 17 , 17 , 17 , 17 , 13 , 13 , 13 , 13 ) , corresponding to an implicit code space of approximately 2.4 × 10 9 combinations. Here we assess whether reducing this quantization resolution preserves reconstruction quality under the same adversarial training setup.
We compare this configuration with reduced levels L ′ = ( 17 , 17 , 17 , 17 , 9 , 9 , 9 , 9 ) , for which N code ′ = 17 4 × 9 4 ≈ 5.5 × 10 8 . The architecture is otherwise unchanged. Table 6 reports the resulting reconstruction metrics.
Reducing the FSQ levels increases the mean power spectrum deviation from 1.5 % to 3.6 % , a factor of 2.4 , while decreasing SSIM from 0.941 to 0.917 and PSNR from 35.8 to 32.4 dB. The simultaneous degradation in pixel-level and two-point statistical fidelity supports retaining the higher quantization resolution among the configurations tested. In the context of the morphological and non-Gaussian diagnostics in Section 4.2, this result motivates preserving latent detail rather than reducing the code space solely to accommodate a conventional discrete vocabulary. Information discarded during tokenization cannot be uniquely recovered from the retained codes, even if a subsequent generative model can synthesize statistically plausible structure.
The FSQ annealing schedule (Section 3) accelerates early training: without annealing, the quantization discontinuity slows convergence during the first 200 epochs. With cosine annealing ( f = 0.5 ), the model reaches comparable reconstruction quality ∼30% faster.

4.4. Implications for Surrogate Modeling

We highlight three implications of the reconstruction results for downstream surrogate modeling.
In the per-patch flat-sky analysis, the adversarial model preserves the power spectrum to δ ¯ = 1.5 % , with peak count correlation r peak = 0.97 and Minkowski functional errors below 2%. These per-patch levels are within the typical systematic budgets of Stage-III weak lensing analyses (∼5–10% for power spectra, ∼10% for peak counts). Any residual reconstruction bias—for example, the − 3.1 % peak count underestimation at ν > 3 —can be characterized and calibrated at the surrogate level, since the bias is systematic and consistent across cosmologies rather than random.
The FSQ autoencoder compresses each 128 × 128 convergence patch into a quantized latent tensor z ^ ∈ R 8 × 16 × 16 , corresponding to 256 spatial tokens, each represented by an eight-dimensional vector. The effective code space of approximately 2.4 × 10 9 combinations makes a conventional autoregressive model with a single full-vocabulary softmax computationally impractical. An alternative is to learn the conditional latent distribution p ( z ^ ∣ θ ) through latent diffusion or flow matching, potentially using a Transformer backbone that operates on latent vectors. This approach avoids assigning a separate output class to every FSQ combination. Although the tensor is embedded in a continuous ambient space, its values lie on a finite grid; a continuous generative surrogate must therefore account for this support, for example through noise-based smoothing or dequantization during training and projection onto the FSQ grid before decoding. The reconstruction results establish a high-fidelity target for such a surrogate, rather than a guarantee of its eventual generative accuracy. Training and validating the conditional prior remain future work.
Once trained, the autoencoder operates as a fixed encoder–decoder pair during surrogate training. Encoding a convergence patch to latent codes requires a single forward pass (∼2 ms on a single GPU), and decoding latent codes back to a patch requires a similar cost. This means the surrogate training loop can operate entirely in latent space without ever reconstructing full patches, reducing memory and computation by orders of magnitude compared to pixel-space generation. The 40% MSE reduction and 2.6 dB PSNR improvement over the baseline provide a more faithful reconstruction target; their effect on downstream generative training remains to be evaluated.
The autoencoder is trained on individual 128 × 128 patches extracted from the HEALPix partitioning (Section 2), learning a per-patch latent representation without access to cross-patch correlations. In the downstream multimodal generative model, the 192 patch-level latent codes from a single cosmological realization are processed jointly with the spherical relative position bias (Equation 2), which encodes the angular geometry of the HEALPix grid. This enables the model to learn cross-patch correlations and recover the large-scale information that spatial partitioning alone would discard, producing coherent all-sky convergence maps from the individually tokenized patches.

5. Conclusions

CosmoTok, a MagViT-based autoencoder with Finite Scalar Quantization and adversarial training, improves reconstruction of CosmoGridV1 convergence maps over an MSE-only baseline: PSNR rises from 33.2 to 35.8 dB and SSIM from 0.912 to 0.941, the mean power-spectrum deviation falls from 4.5% to 1.5% (high-ℓ: 8.2% to 2.4%), the peak-count correlation rises from 0.88 to 0.97, and Minkowski-functional errors drop from 5–8% to below 2%. The gains are concentrated in the structural and statistical properties relevant for cosmology rather than in pixel-level averages.
The main technical ingredients are a learnable ChannelAdapter for single-channel LPIPS, adaptive discriminator weighting, delayed discriminator start, learnable log-variance weighting, and high-level FSQ. More broadly, the autoencoder provides the tokenization stage of a tokenization → surrogate → simulation-based inference pipeline: the compact latent ( z ^ ∈ R 8 × 16 × 16 , N code ≈ 2.4 × 10 9 ) can be modeled by a conditional latent diffusion or flow-matching surrogate, and the HEALPix patch segmentation with spherical relative-position bias provides the basis for coherent all-sky generation. Embedding the surrogate in an NPE loop is the natural next step.

6. Limitations and Future Work

Our comparison is limited to baseline and adversarial FSQ autoencoders with a shared architecture; it does not establish an advantage over alternative compression or generative methods, and broader benchmarks at matched latent size or storage cost, including CosmoGAN [50], are needed. The validation is also limited to CosmoGridV1; tests on independent simulations such as FLAMINGO [51] or CAMELS [30] with consistent map construction would establish robustness.
The residual gap in Figure 3 is mainly spatial: a 128 × 128 slice becomes 16 × 16 latent positions, i.e. one token per 8 × 8 input pixels, so the 3 × 3 peak statistic is below the tokenizer’s effective resolution. The adversarial loss makes the decoded small-scale structure statistically plausible but cannot restore discarded information. Increasing the per-token dimension is secondary (the codebook already has ∼ 2.4 × 10 9 codes); adding latent positions (e.g., 32 × 32 tokens) is the direct route, at the cost of a longer sequence. Flow-matching emulators [23] model the map distribution directly and are evaluated on ensemble statistics, so their sub-percent agreement is not directly comparable to per-slice reconstruction.
Future work should train a conditional latent diffusion [52] or flow-matching [53] model for p ( z ^ | θ ) , validate it with NPE and simulation-based calibration [54], and assess the propagation of reconstruction and generative errors into parameter constraints. A shell-based tokenizer is a further extension.

Author Contributions

Conceptualization, S.N. and T.K.; methodology, S.N. and Y.C.; validation, S.N., Y.C. and G.Z.;data curation, S.N. and Y.C.; writing—original draft preparation, S.N.; writing—review and editing, Y.C., G.Z., B.L., H.C., C.L., J.S. and T.K.; visualization, S.N.; supervision, T.K.; project administration, S.N.; funding acquisition, J.S. All authors have read and agreed to the published version of the manuscript.

Data Availability Statement

The CosmoGridV1 simulation suite analyzed in this study is publicly available at http://cosmogrid.ai/. The simulation-derived convergence maps used for training and evaluation were produced from the publicly released CosmoGridV1 products.

Acknowledgments

This research was supported by the Key R&D Program of Zhejiang (2026SSYS0001).

References

  1. Aghamousa, A.; Aguilar, J.; Ahlen, S.; Alam, S.; Allen, L.E.; Prieto, C.A.; Annis, J.; Bailey, S.; Balland, C.; Ballester, O.; et al. The DESI experiment part I: Science, targeting, and survey design. arXiv 2016, arXiv:1611.00036. [Google Scholar]
  2. Dey, A.; et al. Overview of the DESI Legacy Imaging Surveys. Astron. J. 2019, 157, 168, [arXiv:astroph.IM/1804.08657]. [Google Scholar] [CrossRef]
  3. collaboration, D.; Abareshi, B.; Aguilar, J.; Ahlen, S.; Alam, S.; Alexander, D.M.; Alfarsy, R.; Allen, L.; Allende Prieto, C.; Alves, O.; et al. Overview of the instrumentation for the dark energy spectroscopic instrument. Astron. J. 2022, 164, 207. [Google Scholar] [CrossRef]
  4. Adame, A.G.; et al. DESI 2024 VI: cosmological constraints from the measurements of baryon acoustic oscillations. JCAP 2025, 02, 021, [arXiv:astro-ph.CO/2404.03002]. [Google Scholar] [CrossRef]
  5. Ivezić, Ž.; et al. LSST: from Science Drivers to Reference Design and Anticipated Data Products. Astrophys. J. 2019, 873, 111, [arXiv:astro-ph/0805.2366]. [Google Scholar] [CrossRef]
  6. Abell, P.A. LSST Science Book, Version 2.0; Technical report; Fermi National Accelerator Laboratory (FNAL): Batavia, IL, 2009. [Google Scholar] [CrossRef]
  7. Ivezić, Ž.; Kahn, S.M.; Tyson, J.A.; Abel, B.; Acosta, E.; Allsman, R.; Alonso, D.; AlSayyad, Y.; Anderson, S.F.; Andrew, J.; et al. LSST: from science drivers to reference design and anticipated data products. Astrophys. J. 2019, 873, 111. [Google Scholar] [CrossRef]
  8. Gong, Y.; Liu, X.; Cao, Y.; Chen, X.; Fan, Z.; Li, R.; Li, X.D.; Li, Z.; Zhang, X.; Zhan, H. Cosmology from the Chinese space station optical survey (CSS-OS). Astrophys. J. 2019, 883, 203. [Google Scholar] [CrossRef]
  9. Laureijs, R.; Amiaux, J.; Arduini, S.; Augueres, J.L.; Brinchmann, J.; Cole, R.; Cropper, M.; Dabin, C.; Duvet, L.; Ealet, A.; et al. Euclid definition study report. arXiv 2011, arXiv:1110.3193. [Google Scholar]
  10. Seljak, U. Extracting primordial non-gaussianity without cosmic variance. Phys. Rev. Lett. 2009, 102, 021302. [Google Scholar] [CrossRef]
  11. Jasche, J.; Wandelt, B.D. Bayesian physical reconstruction of initial conditions from large-scale structure surveys. Mon. Not. R. Astron. Soc. 2013, 432, 894–913. [Google Scholar] [CrossRef]
  12. Bartelmann, M.; Schneider, P. Weak gravitational lensing. Phys. Rep. 2001, 340, 291–472. [Google Scholar] [CrossRef]
  13. Hu, W.; Jain, B. Joint galaxy-lensing observables and the dark energy. Phys. Rev. D. 2004, 70, 043009. [Google Scholar] [CrossRef]
  14. Copeland, E.J.; Sami, M.; Tsujikawa, S. Dynamics of dark energy. Int. J. Mod. Phys. D. 2006, 15, 1753–1935. [Google Scholar] [CrossRef]
  15. Hoekstra, H.; Jain, B. Weak Gravitational Lensing and Its Cosmological Applications. Annu. Rev. Nucl. Part. Sci. 2008, 58, 99–123. [Google Scholar] [CrossRef]
  16. Peebles, P.J. The Large-Scale Structure of the Universe; Princeton University Press, 1980. [Google Scholar]
  17. Lewis, A.; Bridle, S. Cosmological parameters from CMB and other data: A Monte Carlo approach. Phys. Rev. D. 2002, 66, 103511, [astro-ph/0205436]. [Google Scholar] [CrossRef]
  18. von Wietersheim-Kramsta, M.; Lin, K.; Tessore, N.; Joachimi, B.; Loureiro, A.; Reischke, R.; Wright, A.H. KiDS-SBI: Simulation-based inference analysis of KiDS-1000 cosmic shear. Astron. Astrophys. 2025, 694, A223, [arXiv:astro-ph.CO/2404.15402]. [Google Scholar] [CrossRef]
  19. Jeffrey, N.; Whiteway, L.; Gatti, M.; Williamson, J.; Alsing, J.; Porredon, A.; Prat, J.; Doux, C.; Jain, B.; Chang, C.; et al. Dark energy survey year 3 results: likelihood-free, simulation-based w cdm inference with neural compression of weak-lensing map statistics. Mon. Not. R. Astron. Soc. 2025, 536, 1303–1322. [Google Scholar] [CrossRef]
  20. Thomsen, A.; Bucko, J.; Kacprzak, T.; Ajani, V.; Fluri, J.; Refregier, A.; Anbajagane, D.; Castander, F.J.; Ferté, A.; Gatti, M.; et al. Dark Energy Survey Year 3 results: Simulation-based w CDM inference from weak lensing and galaxy clustering maps with deep learning: Analysis design. Phys. Rev. D. 2026, 113, 083501. [Google Scholar] [CrossRef]
  21. Rodriguez, A.C.; Kacprzak, T.; Lucchi, A.; Amara, A.; Sgier, R.; Fluri, J.; Hofmann, T.; Réfrégier, A. Fast cosmic web simulations with generative adversarial networks. Comput. Astrophys. Cosmol. 2018, 5, 1–11. [Google Scholar] [CrossRef]
  22. Li, Y.; Ni, Y.; Croft, R.A.; Di Matteo, T.; Bird, S.; Feng, Y. AI-assisted superresolution cosmological simulations. Proc. Natl. Acad. Sci. 2021, 118, e2022038118. [Google Scholar] [CrossRef]
  23. Li, G.; Kacprzak, T. Increasing the Precision of Surrogate Models for Weak Lensing Mass Maps with Flow Matching. arXiv 2026, arXiv:2605.23114. [Google Scholar]
  24. Springel, V.; Pakmor, R.; Pillepich, A.; Weinberger, R.; Nelson, D.; Hernquist, L.; Vogelsberger, M.; Genel, S.; Torrey, P.; Marinacci, F.; et al. First results from the IllustrisTNG simulations: matter and galaxy clustering. Mon. Not. R. Astron. Soc. 2018, 475, 676–698. [Google Scholar] [CrossRef]
  25. Pillepich, A.; Springel, V.; Nelson, D.; Genel, S.; Naiman, J.; Pakmor, R.; Hernquist, L.; Torrey, P.; Vogelsberger, M.; Weinberger, R.; et al. Simulating galaxy formation with the IllustrisTNG model. Mon. Not. R. Astron. Soc. 2018, 473, 4077–4106. [Google Scholar] [CrossRef]
  26. Nelson, D.; Springel, V.; Pillepich, A.; Rodriguez-Gomez, V.; Torrey, P.; Genel, S.; Vogelsberger, M.; Pakmor, R.; Marinacci, F.; Weinberger, R.; et al. The IllustrisTNG simulations: public data release. Comput. Astrophys. Cosmol. 2019, 6, 2. [Google Scholar] [CrossRef]
  27. Euclid, V. The Flagship galaxy mock catalogue: A comprehensive simulation for the Euclid mission. Astron. Astrophys. 2025, 697, A5. [Google Scholar]
  28. Heitmann, K.; Lawrence, E.; Kwan, J.; Habib, S.; Higdon, D. The coyote universe extended: precision emulation of the matter power spectrum. Astrophys. J. 2014, 780, 111. [Google Scholar] [CrossRef]
  29. Kacprzak, T.; Fluri, J.; Schneider, A.; Refregier, A.; Stadel, J. CosmoGridV1: a simulated w CDM theory prediction for map-level cosmological inference. J. Cosmol. Astropart. Phys. 2023, 2023, 050. [Google Scholar] [CrossRef]
  30. Villaescusa-Navarro, F.; Anglés-Alcázar, D.; Genel, S.; Spergel, D.N.; S. Somerville, R.; Dave, R.; Pillepich, A.; Hernquist, L.; Nelson, D.; Torrey, P.; et al. The camels project: Cosmology and astrophysics with machine-learning simulations. Astrophys. J. 2021, 915, 71. [Google Scholar] [CrossRef]
  31. Kaushal, N. Toward Deep Learning Emulators for Modeling the Large-scale Structure of the Universe. PhD thesis, Michigan Tech. U., 2023. [Google Scholar] [CrossRef]
  32. Piras, D.; Mancini, A.S. CosmoPower-JAX: high-dimensional Bayesian inference with differentiable cosmological emulators. arXiv 2023, arXiv:2305.06347. [Google Scholar]
  33. Greenberg, D.; Nonnenmacher, M.; Macke, J. Automatic posterior transformation for likelihood-free inference. In Proceedings of the International conference on machine learning. PMLR, 2019; pp. 2404–2414. [Google Scholar]
  34. Kacprzak, T.; et al. CosmoGrid: A High-Resolution Cosmological Simulation Suite for Weak-Lensing Studies. MNRAS 2022, 509, 1858–1873. [Google Scholar] [CrossRef]
  35. Potter, D.; Stadel, J.; Teyssier, R. PKDGRAV3: beyond trillion particle cosmological simulations for the next era of galaxy surveys. Comput. Astrophys. Cosmol. 2017, 4, 2. [Google Scholar] [CrossRef]
  36. Fluri, J.; Kacprzak, T.; Lucchi, A.; Schneider, A.; Refregier, A.; Hofmann, T. Full w CDM analysis of KiDS-1000 weak lensing maps using deep learning. Phys. Rev. D. 2022, 105, 083518. [Google Scholar] [CrossRef]
  37. Schneider, A.; Teyssier, R. A new method to quantify the effects of baryons on the matter power spectrum. J. Cosmol. Astropart. Phys. 2015, 2015, 049–049. [Google Scholar] [CrossRef]
  38. Gorski, K.M.; Hivon, E.; Banday, A.J.; Wandelt, B.D.; Hansen, F.K.; Reinecke, M.; Bartelmann, M. HEALPix: A framework for high-resolution discretization and fast analysis of data distributed on the sphere. Astrophys. J. 2005, 622, 759–771. [Google Scholar] [CrossRef]
  39. Ni, S.; Qiu, Y.; Chen, Y.; Song, Z.; Chen, H.; Jiang, X.; Li, D.; Quan, D.; Chen, H. Application of Physics-informed Neural Networks in Removing Telescope Beam Effects. Astrophys. J. 2025, 990, 122. [Google Scholar] [CrossRef]
  40. Makinen, T.L.; Lancaster, L.; Villaescusa-Navarro, F.; Melchior, P.; Ho, S.; Perreault-Levasseur, L.; Spergel, D.N. deep21: a deep learning method for 21 cm foreground removal. J. Cosmol. Astropart. Phys. 2021, 2021, 081. [Google Scholar] [CrossRef]
  41. Ni, S.; Li, Y.; Gao, L.Y.; Zhang, X. Eliminating primary beam effect in foreground subtraction of neutral hydrogen intensity mapping survey with deep learning. Astrophys. J. 2022, 934, 83. [Google Scholar] [CrossRef]
  42. Shan, H.; Liu, X.; Hildebrandt, H.; Pan, C.; Martinet, N.; Fan, Z.; Schneider, P.; Asgari, M.; Harnois-Déraps, J.; Hoekstra, H.; et al. KiDS-450: cosmological constraints from weak lensing peak statistics–I. Inference from analytical prediction of high signal-to-noise ratio convergence peaks. Mon. Not. R. Astron. Soc. 2018, 474, 1116–1134. [Google Scholar] [CrossRef]
  43. Harnois-Déraps, J.; Heydenreich, S.; Giblin, B.; Martinet, N.; Tröster, T.; Asgari, M.; Burger, P.; Castro, T.; Dolag, K.; Heymans, C.; et al. KiDS-1000 and DES-Y1 combined: cosmology from peak count statistics. Mon. Not. R. Astron. Soc. 2024, 534, 3305–3330. [Google Scholar] [CrossRef]
  44. Mentzer, F.; Minnen, D.; Agustsson, E.; Tschannen, M. Finite Scalar Quantization: VQ-VAE Made Simple. In Proceedings of the The Twelfth International Conference on Learning Representations (ICLR), 2024. [Google Scholar]
  45. Parker, L.; Lanusse, F.; Shen, J.; Liu, O.; Hehir, T.; Sarra, L.; Meyer, L.; Bowles, M.; Wagner-Carena, S.; Qu, H.; et al. AION-1: Omnimodal foundation model for astronomical sciences. Adv. Neural Inf. Process. Syst. 2026, 38, 95386–95428. [Google Scholar]
  46. Loshchilov, I.; Hutter, F. Decoupled weight decay regularization. arXiv 2017, arXiv:1711.05101. [Google Scholar]
  47. Kendall, A.; Gal, Y.; Cipolla, R. Multi-Task Learning Using Uncertainty to Weigh Losses for Scene Geometry and Semantics. In Proceedings of the Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2018; pp. 7482–7491. [Google Scholar] [CrossRef]
  48. Esser, P.; Rombach, R.; Ommer, B. Taming Transformers for High-Resolution Image Synthesis. In Proceedings of the Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 2021; pp. 12873–12883. [Google Scholar] [CrossRef]
  49. Harnois-Déraps, J.; Heydenreich, S.; Giblin, B.; Martinet, N.; Tröster, T.; Asgari, M.; Burger, P.; Castro, T.; Dolag, K.; Heymans, C.; et al. KiDS-1000 and DES-Y1 combined: cosmology from peak count statistics. Mon. Not. R. Astron. Soc. 2024, 534, 3305–3330. [Google Scholar] [CrossRef]
  50. Mustafa, M.; Bard, D.; Bhimji, W.; Lukić, Z.; Al-Rfou, R.; Kratochvil, J.M. CosmoGAN: creating high-fidelity weak lensing convergence maps using Generative Adversarial Networks. Comput. Astrophys. Cosmol. 2019, 6, 1. [Google Scholar] [CrossRef]
  51. Schaye, J.; Kugel, R.; Schaller, M.; Helly, J.C.; Braspenning, J.; Elbers, W.; McCarthy, I.G.; van Daalen, M.P.; et al. The FLAMINGO project: cosmological hydrodynamical simulations for large-scale structure and galaxy cluster surveys. Mon. Not. R. Astron. Soc. 2023, 526, 4978, [arXiv:astroph.CO/2306.04024]. [Google Scholar] [CrossRef]
  52. Rombach, R.; Blattmann, A.; Lorenz, D.; Esser, P.; Ommer, B. High-Resolution Image Synthesis with Latent Diffusion Models. In Proceedings of the Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 2022. [arXiv:cs.CV/2112.10752]. [Google Scholar]
  53. Lipman, Y.; Chen, R.T.Q.; Ben-Hamu, H.; Nickel, M.; Le, M. Flow Matching for Generative Modeling. arXiv E-Prints 2022. [arXiv:cs.LG/2210.02747]. [Google Scholar] [CrossRef]
  54. Talts, S.; Betancourt, M.; Simpson, D.; Vehtari, A.; Gelman, A. Validating Bayesian inference algorithms with simulation-based calibration. arXiv 2018, arXiv:1804.06788. [Google Scholar]
Figure 1. Visual comparison of the baseline and adversarial reconstructions on a representative slice. Top row: original convergence map κ (left), baseline reconstruction κ base ′ , and adversarial reconstruction κ adv ′ . Bottom row: raw differences κ base ′ − κ , κ adv ′ − κ , and κ adv ′ − κ base ′ . The difference maps are shown on zero-centred diverging colour scales with symmetric limits at the 99.5th percentile of the absolute difference; the two residual panels share a scale and the prediction-difference panel uses its own. Raw differences replace relative residuals because the map contains many values close to zero, where a relative residual inflates negligible absolute differences and obscures the structural error. The adversarial residuals have a lighter large-error tail, whereas the baseline residuals are sparser in the bulk but include larger errors at peaks. The two models have similar bulk pixel-level errors; the adversarial advantage is concentrated in the high-value tail and in peaked structures rather than in the per-pixel bulk, which is why the two residual maps look similar despite the improved tail and peak statistics.
Figure 1. Visual comparison of the baseline and adversarial reconstructions on a representative slice. Top row: original convergence map κ (left), baseline reconstruction κ base ′ , and adversarial reconstruction κ adv ′ . Bottom row: raw differences κ base ′ − κ , κ adv ′ − κ , and κ adv ′ − κ base ′ . The difference maps are shown on zero-centred diverging colour scales with symmetric limits at the 99.5th percentile of the absolute difference; the two residual panels share a scale and the prediction-difference panel uses its own. Raw differences replace relative residuals because the map contains many values close to zero, where a relative residual inflates negligible absolute differences and obscures the structural error. The adversarial residuals have a lighter large-error tail, whereas the baseline residuals are sparser in the bulk but include larger errors at peaks. The two models have similar bulk pixel-level errors; the adversarial advantage is concentrated in the high-value tail and in peaked structures rather than in the per-pixel bulk, which is why the two residual maps look similar despite the improved tail and peak statistics.
Preprints 246111 g001
Figure 2. Full-sky angular power spectrum for a representative held-out realization, computed with spherical harmonic decomposition after reassembling the 192 tokenized patches. Top: C ℓ for the ground truth (black), baseline reconstruction (blue dashed), and adversarial reconstruction (red dashed), on logarithmic axes. Bottom: ratio C ℓ pred / C ℓ orig ; the dashed line marks ratio = 1 . Both reconstructions follow the ground truth at ℓ ≲ 300 (within ∼ 15 % ); at higher ℓ the baseline loses most of the power (ratio ≈ 0.02 at ℓ ≈ 2000 ), while the adversarial model retains ≈ 0.7 . The curves span ℓ = 2 –2000; no ensemble mean or 1 σ scatter is shown.
Figure 2. Full-sky angular power spectrum for a representative held-out realization, computed with spherical harmonic decomposition after reassembling the 192 tokenized patches. Top: C ℓ for the ground truth (black), baseline reconstruction (blue dashed), and adversarial reconstruction (red dashed), on logarithmic axes. Bottom: ratio C ℓ pred / C ℓ orig ; the dashed line marks ratio = 1 . Both reconstructions follow the ground truth at ℓ ≲ 300 (within ∼ 15 % ); at higher ℓ the baseline loses most of the power (ratio ≈ 0.02 at ℓ ≈ 2000 ), while the adversarial model retains ≈ 0.7 . The curves span ℓ = 2 –2000; no ensemble mean or 1 σ scatter is shown.
Preprints 246111 g002
Figure 3. Pixel-value distribution and peak statistics for 192 held-out 2D slices from one CosmoGridV1 all-sky realization. (a) Pixel-value probability density on log–log axes; the shaded band marks values above the 99th percentile of the original. (b) Cumulative number of local maxima per square degree above threshold ν = ( x − μ ) / σ , with μ and σ measured from the original realization; no additional smoothing is applied. (c) Ratio of predicted to original pixel counts in seven quantile bins of the tail, spanning the 99th to 100th percentile; error bars are Poisson. The baseline model retains 67%, 56%, and 30% of pixels above the 99th, 99.9th, and 99.99th percentiles, and the adversarial model retains 90%, 87%, and 65%; the maximum values are 0.148 (original), 0.100 (baseline), and 0.120 (adversarial). (d) Ratio of cumulative peak counts.
Figure 3. Pixel-value distribution and peak statistics for 192 held-out 2D slices from one CosmoGridV1 all-sky realization. (a) Pixel-value probability density on log–log axes; the shaded band marks values above the 99th percentile of the original. (b) Cumulative number of local maxima per square degree above threshold ν = ( x − μ ) / σ , with μ and σ measured from the original realization; no additional smoothing is applied. (c) Ratio of predicted to original pixel counts in seven quantile bins of the tail, spanning the 99th to 100th percentile; error bars are Poisson. The baseline model retains 67%, 56%, and 30% of pixels above the 99th, 99.9th, and 99.99th percentiles, and the adversarial model retains 90%, 87%, and 65%; the maximum values are 0.148 (original), 0.100 (baseline), and 0.120 (adversarial). (d) Ratio of cumulative peak counts.
Preprints 246111 g003
Table 1. Architecture hyperparameters (shared by baseline and adversarial models).
Table 1. Architecture hyperparameters (shared by baseline and adversarial models).
Parameter Value
Input resolution 128 × 128
Hidden dimension d hid 768
Downsampled channel dim d mid 128
Encoder compressions n comp 2
Residual units per compression n res 4
Embedding dimension d e 8
Spatial compression ratio 8 × ( 128 → 16 )
Token grid size 16 × 16 = 256
FSQ levels L ( 17 , 17 , 17 , 17 , 13 , 13 , 13 , 13 )
Effective codebook size N code ≈ 2.4 × 10 9
Both models use identical architecture parameters, ensuring that all reconstruction quality differences arise from the training objective alone.
Table 2. Pixel-level reconstruction quality: baseline vs. adversarial models.
Table 2. Pixel-level reconstruction quality: baseline vs. adversarial models.
Model PSNR (dB)↑ SSIM↑ IoU↑ MSE↓
Baseline 33.21 ± 1.43 0.912 ± 0.018 0.891 ± 0.024 ( 1.82 ± 0.51 ) × 10 − 3
Adversarial 35.84 ± 1.17 0.941 ± 0.011 0.932 ± 0.015 ( 1.09 ± 0.28 ) × 10 − 3
Mean ± standard deviation over 300 test samples. PSNR uses d range = max ( κ ) − min ( κ ) per sample. SSIM is computed globally (Equation 11). IoU uses threshold τ = μ κ . Arrows indicate the direction of improvement.
Table 3. Angular power spectrum fidelity (per-patch flat-sky): fractional deviation δ ¯ and correlation r C ℓ (Equation (14)) by multipole regime.
Table 3. Angular power spectrum fidelity (per-patch flat-sky): fractional deviation δ ¯ and correlation r C ℓ (Equation (14)) by multipole regime.
Model δ ¯ low δ ¯ mid δ ¯ high r C ℓ
Baseline 1.8% 3.9% 8.2% 0.9934
Adversarial 0.9% 1.4% 2.4% 0.9991
δ ¯ low : 100 ≤ ℓ < 500 ; δ ¯ mid : 500 ≤ ℓ < 1000 ; δ ¯ high : 1000 ≤ ℓ ≤ 1535 . Values averaged over 300 test patches using the per-patch flat-sky 2D DFT of Equation (13).
Table 4. Peak count and Minkowski functional fidelity.
Table 4. Peak count and Minkowski functional fidelity.
Metric Baseline Adversarial
Peak count correlation r peak 0.88 0.97
Peak count bias ( ν > 3 ) − 12.3 % − 3.1 %
V 0 relative error 5.2% 1.8%
V 1 relative error 6.7% 1.9%
V 2 relative error 7.9% 1.6%
V 0 , V 1 , V 2 : Minkowski functionals (area, perimeter, genus). Relative errors are max ν | V i recon ( ν ) − V i orig ( ν ) | / max ν | V i orig ( ν ) | .
Table 6. Impact of FSQ quantization resolution.
Table 6. Impact of FSQ quantization resolution.
FSQ levels L PSNR SSIM δ ¯ C ℓ
( 17 , 17 , 17 , 17 , 9 , 9 , 9 , 9 ) 32.4 0.917 3.6%
( 17 , 17 , 17 , 17 , 13 , 13 , 13 , 13 ) 35.8 0.941 1.5%
Adversarial model with identical architecture otherwise. Reduced levels ( N code ′ ≈ 5.5 × 10 8 vs.
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.
Copyright: This open access article is published under a Creative Commons CC BY 4.0 license, which permit the free download, distribution, and reuse, provided that the author and preprint are cited in any reuse.