WorksPhysics and Astronomy
CosmoSim: Lens-parameter estimation of the Einstein Cross NGC 6505 using machine learning
Abstract
CosmoSim is an open-source tool for simulating gravitational lenses and reconstructing lens mass distributions, either by ray tracing a parametric lens model or through a Roulette expansion of the lens potential. It is also used to generate the large, labelled synthetic image sets needed to train machine-learning (ML) parameter estimators. We present the first application of CosmoSim to real data. A convolutional neural network trained only on CosmoSim images estimates Singular Isothermal Ellipsoid lens and source parameters directly from observed images. We test the pipeline on 21 images of 19 strong lenses from Euclid and the AGEL survey, after removing the foreground lens light with a custom decontamination tool built on AstroPy. As a case study we reconstruct the Einstein Cross NGC 6505 both from the lens model published by the discovery team and from parameters predicted by our ML model. Both reconstructions recover the observed four-image structure, and the ML-based reconstruction performs at least as well as the literature-based one: it scores better on masked structural similarity, intersection-over-union and Chamfer distance, with an essentially equal Hausdorff distance. Across the ensemble, the predicted Einstein radii are consistent with catalogued values within the quoted uncertainties (mean relative difference 0.08 for Euclid and 0.19 for AGEL lenses), and the enclosed masses agree to within a median of 0.12 dex. The predicted ellipticities differ systematically from the catalogued values, while the comparison of orientations is inconclusive. These results establish CosmoSim as a tool that can be applied directly to observational data.
Highlights
First application of CosmoSim to observed strong gravitational lenses
CNN trained only on CosmoSim simulations estimates SIE lens parameters
ML reconstruction of NGC 6505 matches one built from the published model
Predicted Einstein radii agree with Euclid and AGEL catalogue values
Predicted ellipticities differ systematically from catalogue values
Introduction
Gravitational lensing is one of the few direct probes of the total mass distribution of galaxies, including their dark matter content, and allows for a variety of applications, such as the estimation of cosmological probes like the Hubble constant or the subhalo mass function. The next generation of wide-field space surveys, in particular Euclid and the forthcoming Chinese Survey Space Telescope (CSST), are expected to increase the number of known strong lens systems by two to three orders of magnitude [5]. Exploiting this sample requires lens-modelling software that is both fast enough to run at scale and flexible enough to be trained, or retrained, on large synthetic datasets.
CosmoSim is a tool developed for exactly this purpose: visualising gravitational lenses and reconstructing lens mass distributions, either by direct ray tracing of a parametric lens model or through the parameter-free Roulette expansion of the lens potential [2 b], as implemented in CosmoSim [14]. Because it is fast and fully labelled, CosmoSim is also used to generate the large synthetic image sets needed to train machine-learning (ML) parameter estimators. CosmoSim has been applied successfully to lens-mass reconstruction [15, 14], and a forthcoming software-release paper will describe the tool in detail. These previous studies have, however, been limited to synthetic data; in the present paper we apply CosmoSim to lens-mass reconstruction with real data for the first time. This is done with an ML model trained on CosmoSim’s synthetic output, and serves as a demonstration that the pipeline works as intended.
As a headline result we reconstruct the Einstein Cross NGC 6505, discovered in Euclid imaging [12], directly from an observational image, and we quantify how this reconstruction compares with the lens model published by the discovery team. We also test the ML model on strong lenses from the AGEL survey and the Euclid Strong Lensing Discovery Engine, and quantify how well it performs on these systems.
The remainder of this paper is structured as follows: Section 2 describes the relevant theoretical background for gravitational lens mass reconstruction in general. Section 3 describes the main tool and how it is used to train the ML parameter estimator on synthetic data. The full processing pipeline is also described. Section 4 reports the results: how the resulting reconstruction of NGC 6505 performs, in particular relative to the discovery team’s own lens model, together with the validation results over the AGEL and Euclid ensemble. Finally, in Section 5 we conclude. The underlying theoretical background and the full analysis are given in the associated thesis [9], on which this paper is based. Appendix A gives the full set of decontaminated/reconstructed image pairs for the observational ensemble.
[email protected] (B.D. Normann); [email protected] (O. Hjemli); [email protected] (H.G. Schaathun)
ORCID(s):
Lens-parameter reconstruction
The theory behind gravitational lensing is well established, and we refer the reader to Schneider, Ehlers and Falco [16], or newer references, such as Congdon and Keeton [4] for a comprehensive review. In this section we summarise the key concepts and equations relevant to our analysis.
Lens model: the singular isothermal ellipsoid
A source at angular position is mapped to image positions by the lens equation
where is the scaled projected lens potential and the convergence. For an isothermal sphere (SIS) with velocity dispersion , the surface density falls off as , giving with Einstein radius
Real lens galaxies and their dark-matter haloes are, however, elliptical, and the isothermal profile of the combined mass is well described by the singular isothermal ellipsoid (SIE) (Kormann, Schneider and Bartelmann, [11]). In lens-centred coordinates , rotated counter-clockwise by the orientation angle from the image -axis, the circular radius is replaced by the elliptical radius , where the ellipticity is the minor-to-major axis ratio. Since , the major axis of the mass distribution lies along , i.e. at . The convergence and potential become
with and the polar angle. The SIE reduces to the SIS for . Unlike the SIS, it can produce four images of a single source, as observed in Einstein crosses such as NGC 6505. The lens is thus described by three parameters: , the ellipticity and the orientation (Table 1).
| Symbol | Parameter | Range | Unit |
| Einstein radius | 5–75 | pixels | |
| Ellipticity | 0.5–1.0 | ||
| Lens orientation | 0–180 | deg | |
| Source effective radius | 2–5 | pixels | |
| Source radius | 1–10 | pixels | |
| Source angle | 0–360 | deg | |
| Sérsic index | 0.5–5.0 | ||
| Total luminosity | 10–20 |
Table 1. Parameter ranges used to generate the synthetic training data.
Source model: the Sérsic light profile
Lensing conserves surface brightness, so the lensed image is , where is the source light profile. For the source we use the Sérsic profile (Sérsic, 1963), which describes the light of a range of different galaxies:
where is the distance from the source centre, the effective (half-light) radius, the intensity at and the Sérsic index, which sets how steeply the light falls off ( gives an exponential disc, a de Vaucouleurs profile). The constant is fixed by requiring that enclose half the total light, , and is well approximated by (Graham and Driver, [7]). Integrating Eq. (5) gives the total flux
where ZP is the zero-point magnitude of the telescope and filter. In CosmoSim the source can therefore be specified by observable quantities – the apparent magnitude , and – with following from Eq. (6). Alternatively, the brightness can be set by a dimensionless total luminosity , which is what we use for the training data in this paper. Together with the source position this completes the parameter set in Table 1.
Tools and method
To actually train an ML model for lens parameter reconstruction, we use the recently developed CosmoSim toolbox. All simulations in this paper were made with the development branch physical implementation of CosmoSim in April and May 2026; the nearest archived release is v2.8.0 of 12 April 2026 (Schaathun, Hjemli, Hatedal, Ingebrigtsen, Runde, Leite, Westbø and Jackson, [13]). The training data (6 April) and the reconstructions of NGC 6505 (15 May) were made with slightly different versions of this branch, but both use the same Sérsic source model and luminosity normalisation (Sect. 2.2), so we expect the difference between them to have a negligible effect on our results.
CosmoSim2 is an open-source tool for visualising strong gravitational lenses and reconstructing lens mass distributions from either simulated or observed images. One of the major features of CosmoSim is its ability to locally expand the lens potential around any point, in a so-called Roulette expansion. CosmoSim is built around a three-layer architecture: A C++ simulation library performs the lens-equation computations, including the derivation of Roulette amplitudes, critical curves and the source light distribution; a Python wrapper, CosmoSimPy, exposes this library to user-facing tools; and a set of Python scripts and a graphical user interface (CosmoGUI.py) allow interactive or batch generation of lensed images. The simulator currently implements Singular Isothermal Sphere (SIS), Singular Isothermal Ellipsoid (SIE), and Point Mass lens models, with spherical, elliptical and triangular source models. It supports both ray-traced and Roulette-expansion simulation modes; the latter reconstructs an image from a specified number of Roulette terms. The source-light distribution is given by a Sérsic profile (Sect. 2.2), which lets the simulated source be specified by an apparent magnitude and effective radius. CosmoSim also uses a deferred, telescope-agnostic pixel-to-angular-scale calibration, in which pixel quantities are only converted to angular units after a reconstruction is complete, by multiplying by the telescope’s arcseconds-per-pixel scale (e.g. 0.1″/pixel for Euclid VIS, 0.04″/pixel for HST/UVIS):
This lets a single ML model, trained once on CosmoSim’s dimensionless pixel images, be applied unchanged to imaging from any survey, and, where the redshifts of lens and source are known, lets the resulting angular Einstein radius be converted to a physical Einstein radius and an enclosed mass (Sect. 4).
Training on synthetic data
CosmoSim includes the dataset and datagen scripts, which generate labelled parameter tables and the corresponding images in bulk. We used these tools to generate a large synthetic training set of SIE lens images with the new Sérsic source profile, spanning a broad range of Einstein radii, ellipticities, orientations and source positions – including configurations both inside and outside the critical curves, so that the training set contains doubly, triply and quadruply imaged systems in proportions representative of the real observational sample. A convolutional neural network (CNN) was trained exclusively on this synthetic data to predict seven ray-trace parameters directly from an image: the lens Einstein radius, ellipticity and orientation, and the source effective radius, position angle and radius, and Sérsic index.
Parameter uncertainties are obtained with Monte Carlo dropout (Gal and Ghahramani (2016); Shirmohammadi and Al Osman [18]): each image is passed through the network 200 times with 20 per cent of the units randomly dropped, and the mean and standard deviation of the predictions are taken as the estimate and its uncertainty. Because the model never sees a real image during training, applying it to observational data is a genuine out-of-distribution test of both the ML model and of how realistic the underlying CosmoSim images are.
Training data The training set comprises 30 000 CosmoSim images of SIE lenses with a spherical, Sérsic-profile source, split 70/15/15 into training, validation and test sets, with parameter ranges (Table 1) adapted from Hezaveh, Levasseur and Marshall [8]. The source brightness is set by the dimensionless total luminosity , which is varied in the training data but not predicted by the ML model.
Hyperparameters The final model (a Wide ResNet50-2 backbone, trained with a batch size of 96) was selected by a grid search over hyperparameters including the learning rate and weight decay, choosing the combination that minimised the validation loss. Training ran for at most 500 epochs with early stopping: training was halted once the validation loss had not improved for 20 epochs (the patience), which limits overfitting and saves computing time.
Real lenses: Noise and decontamination
To test CosmoSim and the ML estimator of Sect. 3.1 against real data, we chose the newly discovered Euclid Einstein Cross NGC 6505 (O’Riordan et al. [12]) alongside 20 further images of 18 systems: 12 from the AGEL survey (Tran, Harshan, Glazebrook et al. [19]) and 8 images of 6 systems from the Euclid Strong Lensing Discovery Engine (Euclid Collaboration et al. [5]). For two of the Euclid systems the lens light was removed in two versions, retaining one or two images of the source, respectively; both versions are kept as separate entries (Euclid-3/Euclid-5 and Euclid-4/Euclid-6 in Table 9). Before a real image can be compared with, or fed into, CosmoSim, the foreground lens galaxy’s light must be removed so that only the lensed source remains. Working with lens-light-subtracted images follows Hezaveh et al. [8], who applied convolutional networks to real lenses after removing the lens light; unlike them, however, we do not add observational noise to the synthetic training images, but instead process the real images so that they resemble the noise-free CosmoSim output, as described below. We developed a graphical tool for removing lens-galaxy light: it fits the lens with one or more Sérsic components using AstroPy (Astropy Collaboration, Price-Whelan, Lim, Earl et al. [1]), subtracts the model, and then isolates the lensed arcs by applying Gaussian smoothing and a threshold mask. Figure 2 shows an example of fitted lens-light model and the resulting raw residual immediately after subtraction; visual inspection of this residual is used to verify the quality of the fit before the lensed arcs are isolated. The raw residual is then cleaned up by masking out unrelated objects and enforcing a minimum object size and flux threshold, and the resulting mask is smoothed to soften its edges before being applied to the residual, producing a final image with an arc morphology closer to CosmoSim’s own simulated output. For NGC 6505, the best lens subtraction was obtained with the three Sérsic components listed in Table 2. Figure 1 shows the resulting fitted lens light, the mask of the remaining light after subtraction, and the final post-processed image, while Figure 3 shows the same final image rescaled for use as input to the reconstruction and ML pipelines. Figure 4 summarises the full pipeline, from a real survey image to a reconstructed image and its comparison metrics.
| Component | Amplitude | (pixels) | |
| 1 | 1.0 | 40 | 1.00 |
| 2 | 0.3 | 70 | 1.35 |
| 3 | 0.1 | 125 | 4.00 |
Table 2. Sérsic components used to fit and subtract the lens light of NGC 6505.



Figure 1. NGC 6505 lens subtraction: (a) the fitted lens light, (b) the mask of the remaining light after subtraction, with smoothing and a threshold value, and (c) the final image after lens fitting and post-processing.

Figure 3. Decontaminated Euclid image of NGC 6505, with the foreground lens light subtracted using AstroPy, used as input to both the direct reconstruction and the machine-learning pipeline.


Figure 2. Example AstroPy fit: the modelled foreground lens light (left) and the raw residual obtained by subtracting it from the observed image (right), which reveals the lensed arcs.

Figure 4. The full CosmoSim reconstruction pipeline. A real, decontaminated survey image is reconstructed in CosmoSim either from literature lens parameters or from parameters predicted by an ML model; the ML model is trained only on CosmoSim’s own synthetic images (bottom row). The reconstruction is compared with the cleaned image using several morphology-sensitive metrics. Blue boxes mark the tools and data sets developed by the authors.
| Label | Target ids |
| Euclid 1 | 102158584_2687900321650859511 |
| Euclid 2 | 102158887_2646461630654930628 |
| Euclid 3 | 102023478_NEG628457640459296313 |
| Euclid 4 | 102158275_2709777393645726835 |
| Euclid 5 | 102023478_NEG628457640459296313 |
| Euclid 6 | 102158275_2709777393645726835 |
| Euclid 7 | 102159773_2677079122669151496 |
| Euclid 8 | 102021017_NEG634146279486865014 |
| AGEL 1 | DESJ0141-1713-1 |
| AGEL 2 | DESJ0142-1831 |
| AGEL 3 | DESJ2125-6504 |
| AGEL 4 | DESJ0102+0158 |
| AGEL 5 | DESJ2219-4348 |
| AGEL 6 | DESJ2137-0129 |
| AGEL 7 | DESJ0537-4647 |
| AGEL 8 | DESJ2014-5757 |
| AGEL 9 | DCLS1427-0645 |
| AGEL 10 | DESJ2335-5152 |
| AGEL 11 | PS1J2336 |
| AGEL 12 | DESJ2334-6404 |
Table 9. Mapping between target ids of the observational data samples and the labels used in this paper.
Comparison metrics We compare each reconstruction with the cleaned image using four complementary metrics. The structural similarity index (SSIM; Wang, Bovik, Sheikh and Simoncelli [21]) compares local brightness, contrast and structure in a sliding window and averages the result, with 1 for identical images. We evaluate it both over the full image (global SSIM) and only over the non-zero pixels, i.e. the lensed arcs (masked or local SSIM). The remaining three metrics compare the shapes of the arcs, represented by binary masks obtained by thresholding the two images. The intersection-over-union (IoU) is the area where the two masks overlap divided by the area covered by either, with 1 for perfect overlap. The Hausdorff distance is the largest distance from a point in one mask to the nearest point in the other, and so measures the worst mismatch, while the
Chamfer distance averages the distance to the nearest point in the other mask and is less sensitive to single outliers; both are given in pixels and vanish for identical masks.
Results and analysis
In the following we present the results on our main target of investigation, the Einstein Cross NGC 6505, alongside 20 additional images on which our reconstruction pipeline was applied.
NGC 6505
Reconstruction from literature parameters Feeding the Elliptical Power Law lens parameters (with slope ) reported by O’Riordan et al. [12] directly into CosmoSim as a SIE lens (Table 3; the source position and light-profile parameters were not published and were tuned manually) reproduces the observed four-fold image structure with high visual fidelity (Figure 5): a correctly positioned quadruple Einstein Cross, with only slight positional offsets relative to the decontaminated Euclid data (Figure 3). Quantitatively (Table 5, row “Literature”), this reconstruction scores a masked SSIM of 0.54, an IoU of 0.45, a Chamfer distance of 5.5 pixels and a Hausdorff distance of 11.5 pixels against the cleaned image. We attribute the residual mismatch to two simplifications. First, the source position and light profile were not published and had to be tuned by hand. Second, CosmoSim’s SIE is only an approximation to the discovery team’s model: their Elliptical Power Law (EPL) reduces to the SIE for a power-law slope , and although their slope () is close to this, their preferred model also includes external shear and an multipole (O’Riordan et al., [12]), which the SIE lacks. Such limitations of a fixed parametric form illustrate the potential value of parameter-free modelling.
| Symbol | Parameter | Value | Unit |
| Einstein radius | 64 | pixels | |
| Lens orientation | 143.3 | deg | |
| Ellipticity | 0.702 | ||
| Source radius | 3.8 | pixels | |
| Source angle | 77.5 | deg | |
| Source effective radius | 3.47 | pixels |
Table 3. Literature SIE lens and source parameters used to reconstruct NGC 6505 (O’Riordan et al. [12], their preferred model, Table 2). , and were not reported and were tuned manually. The pixel scale of the simulated image is 0.0390625″/pixel.

Figure 5. CosmoSim reconstruction of NGC 6505 using the SIE lens parameters derived from the EPL fit of O’Riordan et al. [12] (left) and the pixel-by-pixel difference with respect to the cleaned Euclid image of Figure 3 (right).
| Reconstruction | Chamf. | SSIM (local) | IoU | Hausd. |
| Literature | 5.464 | 0.542 | 0.449 | 11.5 |
| ML-predicted | 4.144 | 0.654 | 0.550 | 11.7 |
Table 5. Image-comparison metrics for the two CosmoSim reconstructions of NGC 6505, evaluated against the decontaminated Euclid image. SSIM is evaluated over the lensed arcs only (masked SSIM); the Chamfer and Hausdorff distances are in pixels. Higher SSIM and IoU, and smaller distances, indicate better agreement.
Reconstruction from ML-predicted parameters Without using any literature values, the ML model of Sect. 3.1 estimated the lens and source parameters directly from the cleaned image of Figure 3 (Table 4): Einstein radius 61.7 5.5 pixels, ellipticity 0.63 0.04 and lens orientation 142.7° 14.7°. Feeding these predictions back into CosmoSim again reproduces the ring-like structure with its four brightness knots (Figure 6): the reconstruction correctly recovers the spatial position of three of the four images, with the fourth showing an inward radial offset and unsubtracted flux, consistent with the residual ellipticity error
| Symbol | Parameter | Value | Unit |
| Source radius | pixels | ||
| Source angle | deg | ||
| Einstein radius | pixels | ||
| Ellipticity | |||
| Lens orientation | deg | ||
| Source effective radius | pixels | ||
| Sérsic index |
Table 4. Lens and source parameters for NGC 6505 predicted by the ML model with Monte Carlo dropout uncertainties over 200 forward passes (Sect. 3.1).

Figure 6. Cleaned Euclid image of NGC 6505 (left) and CosmoSim reconstruction (right) using lens and source parameters predicted by the machine-learning model, with no manual adjustment and no access to the literature parameters of O’Riordan et al. [12].
of the prediction. This reconstruction – built without any access to the discovery team’s measurements and with no manual tuning – performs at least as well as the one built directly from their published parameters (Table 5, row “ML-predicted”): it scores better on masked SSIM (0.65 versus 0.54), IoU (0.55 versus 0.45) and Chamfer distance (4.1 versus 5.5 pixels), while the Hausdorff distances are essentially equal (11.7 versus 11.5 pixels). A masked SSIM well below unity indicates that pixel-level flux agreement within the arcs is still limited, even though their overall shape and position are well recovered.
Summary of comparison metrics Table 5 collects the comparison metrics for the two reconstructions side by side. The Chamfer distance is insensitive to the exact pixel-flux values and instead compares the geometric boundaries of the lensed arcs.
Overall, both reconstruction routes – literature parameters and ML-predicted parameters – recover the correct qualitative topology of the Einstein Cross, and the ML-predicted reconstruction performs at least as well: it has higher masked SSIM and IoU and a smaller Chamfer distance, whereas the literature reconstruction has a marginally smaller Hausdorff distance (Table 5). Since the ML model had no access whatsoever to the discovery team’s own measurements, this is a positive validation of the full CosmoSim/ML pipeline, and of CosmoSim’s synthetic training images as a usable proxy for real Euclid data. The residual errors in both cases point to the same root cause: parametric reconstructions will never be perfect, precisely because they are built from parameter models that do not fully correspond to the real world.
Ensemble of additional strong lenses
Beyond NGC 6505, a further 20 images of 18 strong-lens systems from the AGEL survey and the Euclid Strong Lensing Discovery Engine were lens-subtracted, decontaminated and reconstructed with the same pipeline, for an ensemble of 21 images in total. Figure 7 shows four qualitatively successful reconstructions, clearly recognisable to the human eye even where the size or position of the arcs shows a small spatial offset. Figure 8 shows four qualitatively unsuccessful cases, where the model fails to capture the core topology of the lensed arcs – these are predominantly the systems with the most complex arc/ring morphology or the lowest signal-to-noise ratio after decontamination.

Figure 7. Four qualitatively successful reconstructions from the observational ensemble. Top row: original survey images. Middle row: decontaminated versions. Bottom row: final CosmoSim reconstructions.

Figure 8. Four qualitatively unsuccessful reconstructions, where the model fails to capture the core topology of the lensed arcs. Rows as in Fig. 7.
Averaging the SSIM score across the full ensemble reveals a large gap between the global and masked (arc-only) values: a global SSIM of 0.95 compared with a masked SSIM of only 0.24. As for NGC 6505 individually, this shows that the global score is dominated by the shared, mostly empty background, and that the masked score is a much stricter, and more representative, measure of how well the reconstructed arcs actually agree with the observed ones; the same caveat applies to the IoU score, which is similarly sensitive to small positional offsets between otherwise well-matched arcs. Bypassing this spatial sensitivity
| Metric | ML model |
| Local SSIM | 0.24 |
| Chamfer distance | 16.54 |
| Hausdorff distance | 23.16 |
| IoU | 0.19 |
Table 6. Ensemble-averaged image-comparison metrics for the ML model.
with the Chamfer distance – which compares the geometric boundaries of the lensed arcs directly – generally shows a high degree of morphological similarity between observation and reconstruction, even in cases penalised harshly by SSIM/IoU, though it also exposes cases where CosmoSim merges several separate, distinct lensed features (as resolved in the real image) into a single continuous arc.
Physical parameters: Euclid systems Table 7 compares the predicted Einstein radius, ellipticity and lens orientation for the Euclid-discovered systems with the catalogued PyAutoLens models (SIE plus external shear) of the Euclid Q1 Strong Lensing Discovery Engine Euclid Collaboration et al., [5]; Walmsley, Holloway, Lines, Rojas, Collett, Verma, Li, Nightingale, Despali and Schuldt [20]. Catalogued models are available for seven of the eight Euclid entries (Euclid-8 has none), and Euclid-3/Euclid-5 and Euclid-4/Euclid-6 are two versions of the same systems, so the table contains five distinct systems. The catalogued values are themselves model estimates with purely statistical uncertainties, not ground truth, so the comparison tests the consistency of two independent modelling approaches. The predicted Einstein radii agree with the catalogued ones within the prediction uncertainty for all systems (mean relative difference 0.08). The predicted axis ratios, by contrast, differ systematically from the catalogued values: they are lower (0.44–0.54 versus 0.61–0.88, by more than for four of the seven entries). Since the catalogued values are themselves model estimates, this comparison alone cannot establish which is correct. Several observations nevertheless point to a limitation of the ML model rather than of the catalogue. (i) Four of the predicted axis ratios lie below 0.5, the lower edge of the training range (Table 1), suggesting that the real images differ from the synthetic training images. (ii) The catalogue models are fitted at pixel level to the original images including the PSF, whereas the ML model sees images that have been lens-subtracted, smoothed and masked, processing that may alter the shape of the arcs. (iii) The catalogued axis ratios are typical of massive elliptical lens galaxies, whereas all seven predictions are unusually flattened. Conversely, the catalogue models include external shear, which is partly degenerate with ellipticity (Keeton, Kochanek and Seljak, [10]). A model without shear, such as CosmoSim’s SIE, must absorb an external shear aligned with the lens into a flatter mass distribution, lowering the axis ratio by an amount of order a few times . The catalogued shears (0.02–0.12) can account for most of the difference for Euclid-4/Euclid-6, which has the largest shear (), nearly aligned with the lens, and for part of it for Euclid-2 and Euclid-7, but not for Euclid-1, where the shear is small, nor for Euclid-3/Euclid-5, where it is nearly perpendicular to the lens. External shear thus explains part, but not all, of the systematic offset.
Euclid ensemble: predicted vs. catalogued Einstein radius (arcsec), ellipticity and lens orientation (deg). Catalogued values are the PyAutoLens SIE models of the Euclid Q1 Strong Lensing Discovery Engine ([5, 20]): is their effective Einstein radius and their axis ratio . Their position angle refers to the major axis, whereas CosmoSim’s refers to the minor axis (both counter-clockwise from the image -axis, Sect. 2.1); the catalogued angles have therefore been converted as (mod ). RD is the relative difference ; for the orientation we give instead the absolute difference (mod ). Whether CosmoSim and PyAutoLens orient the image axes identically has not been established, so the orientation comparison should be treated with caution (see text). Euclid-3/Euclid-5 and Euclid-4/Euclid-6 are the same systems with different lens-light subtraction; Euclid-8 has no catalogued model and is omitted. The lensing systems have been given an arbitrary order.
| Object | pred | lit. | RD | pred | lit. | RD | pred | lit. | |
| Euclid-1 | 0.00 | 0.41 | 79.6 | ||||||
| Euclid-2 | 0.02 | 0.40 | 45.2 | ||||||
| Euclid-3 | 0.13 | 0.11 | 50.7 | ||||||
| Euclid-4 | 0.19 | 0.44 | 57.1 | ||||||
| Euclid-5 | 0.01 | 0.28 | 41.3 | ||||||
| Euclid-6 | 0.11 | 0.49 | 79.6 | ||||||
| Euclid-7 | 0.13 | 0.16 | 20.1 |
Table 7.
The comparison of lens orientations is less conclusive. CosmoSim and the catalogue define the angle relative to different axes of the ellipse (minor versus major axis; Sect. 2.1), which we have corrected for, but we have not been able to establish whether the two codes also orient the image axes identically, in particular whether the image -axis points up or down. With the conversion adopted in Table 7, the orientations differ by on average, comparable to the expected for random orientations; with a reversed -axis it would be . Only if, in addition, CosmoSim’s referred to the major rather than the minor axis would the mean difference drop to , with four of the seven entries agreeing to within . The orientation is moreover poorly defined for the nearly round systems with . We therefore draw no conclusion about how well the ML model recovers the lens orientation.
Physical parameters: AGEL systems Table 8 compares the predicted Einstein radius and enclosed mass for the 12 AGEL systems with the values of Gottemoller, Sahu, Cordova Rosado et al. [6]. These catalogued Einstein radii come from simple ring or image-pair fits to ground-based imaging and carry uncertainties of 0.7–1.2″ (30–50 per cent), so they are considerably less precise than the Euclid values. The mean relative difference in is 0.19, but all predictions agree with the catalogued values within the combined uncertainties (the largest difference, AGEL-1, is ). Since the enclosed mass is computed from using the catalogued lens and source redshifts, , differences in carry over directly to the mass: the predicted masses differ from the catalogued values by 0.01–0.56 dex (median 0.12 dex), again within the combined uncertainties (at most ). The AGEL lenses are predominantly group- and cluster-embedded (Gottemoller et al., [6]), so neither CosmoSim’s single-galaxy SIE nor a simple ring fit need describe them fully; the larger scatter relative to the Euclid sample therefore reflects both the less precise catalogue values and the more complex lens environments.
AGEL ensemble: predicted vs. catalogued Einstein radius (arcsec) and enclosed mass (). Catalogued values are from Gottemoller et al. [6]. For we give the relative difference (RD, as in Table 7); for the mass, the absolute difference in dex. The lensing systems have been arbitrarily ordered.
| Object | pred | lit. | RD | pred | lit. | |
| AGEL-1 | 0.50 | 0.56 | ||||
| AGEL-2 | 0.07 | 0.02 | ||||
| AGEL-3 | 0.08 | 0.04 | ||||
| AGEL-4 | 0.02 | 0.01 | ||||
| AGEL-5 | 0.08 | 0.07 | ||||
| AGEL-6 | 0.37 | 0.38 | ||||
| AGEL-7 | 0.21 | 0.21 | ||||
| AGEL-8 | 0.25 | 0.21 | ||||
| AGEL-9 | 0.16 | 0.12 | ||||
| AGEL-10 | 0.07 | 0.11 | ||||
| AGEL-11 | 0.12 | 0.09 | ||||
| AGEL-12 | 0.33 | 0.31 |
Table 8.
The catalogue identifiers of the 12 AGEL systems and the 8 Euclid entries (6 distinct systems) are listed in Table 9.
Conclusion
In this paper we have presented the first application of the CosmoSim toolbox to real data, using a machine-learning model trained on synthetic CosmoSim images to predict lens and source parameters directly from observational images. We have validated the full pipeline against 21 images of 19 real strong lenses from Euclid and the AGEL survey, after subtracting the foreground lens light with a custom decontamination tool built on AstroPy. As a case study we have reconstructed the Einstein Cross NGC 6505, discovered by Euclid, both from the Elliptical Power Law lens parameters reported by the discovery team and from parameters predicted directly by our ML model. Both reconstructions recover the observed four-fold image structure against the decontaminated Euclid image.
The ML-predicted reconstruction, built with no access to the discovery team’s own measurements, performs at least as well as the one built directly from their published lens model: it scores better on masked structural similarity, intersection-over-union (0.55 versus 0.45) and Chamfer distance (4.1 versus 5.5 pixels), while the Hausdorff distances are essentially equal (11.7 versus 11.5 pixels). Across the wider ensemble, the predicted Einstein radius is consistent with catalogued values within the quoted uncertainties for all systems (mean relative difference 0.08 for Euclid systems and 0.19 for the group- and cluster-embedded AGEL lenses), and the corresponding enclosed masses agree to within a median of 0.12 dex. The predicted lens ellipticity, by contrast, differs systematically from the catalogued values; the evidence points to a limitation of the ML model on real images, and testing this directly is a target for future work. The comparison of lens orientations is inconclusive, since we have not been able to establish that CosmoSim and the catalogue use identical angle conventions. These results establish CosmoSim, for the first time, as a tool that can be applied directly to observational data rather than only to synthetic images.
CRediT authorship contribution statement
Ben David Normann: Conceptualization, Supervision, Writing – review and editing. Oda Hjemli: Software, Investigation, Data curation, Writing – original draft. Hans Georg Schaa thun: Software, Supervision, Writing – review and editing.
Decontaminated and reconstructed image pairs
Figure 9 shows, for every system in the observational ensemble, the decontaminated survey image next to its CosmoSim reconstruction from the ML-predicted parameters. Labels follow Table 9.
Figure 9. Decontaminated (left in each pair) and CosmoSim-reconstructed (right in each pair) images for the observational ensemble.
References
- [1]Astropy Collaboration, Price-Whelan, A.M., Lim, P.L., Earl, N., et al., 2022. The Astropy project: Sustaining and growing a community-oriented open-source project and the latest major release (v5.0) of the core package. The Astrophysical Journal 935, 167. doi:10.3847/1538-4357/ac7c74.DOI
- [2]Clarkson, C., 2016a. Roulettes: a weak lensing formalism for strong lensing: I. Overview. Classical and Quantum Gravity 33, 16LT01. arXiv:1603.04698.DOI
- [4]Congdon, A., Keeton, C., 2018. Principles of Gravitational Lensing. 1 ed., Springer-Cham. doi:10.1007/978-3-030-02122-1.DOI
- [5]Euclid Collaboration, Walmsley, M., Holloway, P., Lines, N., et al., 2025. Euclid quick data release (Q1). the strong lensing discovery engine A – system overview and lens catalogue. Astronomy & Astrophysics arXiv:2503.15324.
- [6]Gottemoller, W.J., Sahu, N., Cordova Rosado, R., et al., 2026. Most strong lenses in the AGEL survey are in group and cluster environments. The Astronomical Journal arXiv:2602.11068.DOI
- [7]Graham, A.W., Driver, S.P., 2005. A concise reference for (projected) Sérsic R1/n quantities, including concentration, profile slopes, petrosian indices, and kron magnitudes. Publications of the Astronomical Society of Australia 22, 118–127. doi:10.1071/AS05001.DOI
- [8]Hezaveh, Y.D., Levasseur, L.P., Marshall, P.J., 2017. Fast automated analysis of strong gravitational lenses with convolutional neural networks. Nature 548, 555–557.DOI
- [9]Hjemli, O., 2026. Simulated Reconstruction and Parameter Estimation on Observational Gravitational Lens Data. Master’s thesis. Norwegian University of Science and Technology (NTNU).
- [10]Keeton, C.R., Kochanek, C.S., Seljak, U., 1997. Shear and ellipticity in gravitational lenses. The Astrophysical Journal 482, 604–620. doi:10.1086/304172, arXiv:astro-ph/9610163.DOI
- [11]Kormann, R., Schneider, P., Bartelmann, M., 1994. Isothermal elliptical gravitational lens models. Astronomy and Astrophysics 284, 285–299.
- [12]O’Riordan, C.M., Vernardos, G., Nightingale, J.W., et al., 2025. Euclid: A complete einstein ring in NGC 6505. Astronomy & Astrophysics 694, A145.
- [13]Schaathun, H.G., Hjemli, O., Hatledal, L.I., Ingebrigtsen, S., Runde, S.N., Leite, E., Westbø, S., Jackson, S., 2026. Cosmoai-AES/CosmoSim: v2.8.0. doi:10.5281/ZENODO.24078838.DOI
- [14]Schaathun, H.G., Normann, B.D., Austnes, E.L., Ingebrigtsen, S., Remøy, S.W., Runde, S.N., 2023a. Simulation of gravitational lensing in the roulette formalism, in: Vicario, E., Bandinelli, R., Fani, V., Mastronianni, M. (Eds.), Proceedings of the 37th ECMS International Conference on Modelling and Simulation. ECMS - European Council for Modelling and Simulation. URL: https://www.scs-europe.net/dlib/2023/2023-0141.html, doi:10.7148/2023-0141. Florence, Italy, 21–23 June 2023.DOI
- [15]Schaathun, H.G., Normann, B.D., Solevåg-Hoti, K., 2023b. Om å kartleggja mørk materie med maskinlæring. Norsk IKT-konferanse for forskning og utdanning To be presented at Norsk Informatikkonferanse in Stavanger 28–29 November 2023.
- [16]Schneider, P., Ehlers, J., Falco, E.E., 1992. Gravitational Lenses. Astronomy and Astrophysics Library, Springer-Verlag, Berlin. doi:10.1007/978-3-662-03758-4.DOI
- [18]Shirmohammadi, S., Al Osman, A., 2021. Machine learning in measurement part 2: Uncertainty quantification. IEEE Instrumentation & Measurement Magazine 24. doi:10.1109/MIM.2021.9436102.DOI
- [19]Tran, K.V.H., Harshan, A., Glazebrook, K., et al., 2022. The AGEL survey: Spectroscopic confirmation of strong gravitational lenses in the DES and DECaLS fields selected using convolutional neural networks. The Astronomical Journal 164, 148.DOI
- [20]Walmsley, M., Holloway, P., Lines, N., Rojas, K., Collett, T., Verma, A., Li, T., Nightingale, J., Despali, G., Schudlt, S., 2025. Euclid quick data release (Q1): The strong lensing discovery engine (data release, v0.0.0.3). Zenodo. doi:10.5281/zenodo.15025832.
- [21]Wang, Z., Bovik, A.C., Sheikh, H.R., Simoncelli, E.P., 2004. Image quality assessment: From error visibility to structural similarity. IEEE Transactions on Image Processing 13, 600–612. doi:10.1109/TIP.2003.819861.DOI
