Covariant Contrastive Learning for Uncertainty-Aware Anomaly Detection
Abstract
Machine-learning-based anomaly detection (AD) offers a promising, model-agnostic alternative to traditional LHC analyses, allowing to search for many signals at once. Recent advances in representation learning motivate the use of neural embeddings to map high-dimensional physics observables into low-dimensional latent spaces better suited to statistical inference. However, the propagation of systematic uncertainty in embedded spaces remains poorly understood, severely limiting the application of these methods to real LHC analyses. We address this gap with a machine learning strategy that uses a likelihood-based regularization to improve the structure of embedded spaces. Building on previous work using supervised contrastive learning for physics-aware embeddings, our approach trains them jointly with a downstream parameterized classification task that incorporates continuous uncertainties as nuisance parameters. This method returns a latent space that covaries predictably with systematic shifts, and a model of such distortions that can be exploited in the downstream statistical test for anomaly detection. Using simulated CMS Level-1 trigger data, we show that our method successfully models continuous uncertainties in a 4D latent space with a linear parametric downstream classifier, improving both the interpretability and robustness of the statistical anomaly detection task. This framework offers a general way to study and control systematic uncertainties in latent spaces, opening the way to a new scalable statistical analysis workflow for anomaly detection at the LHC, and other high energy physics experiments.
I Introduction
The Large Hadron Collider (LHC) experiments have performed several tests of the Standard Model (SM) of particle physics, and continue to produce measurements of increasingly high precision. However, they have yet to find any convincing evidence of new physics. One reason may be methodological: most searches are optimized for a specific signal hypothesis and lose sensitivity to signatures that fall outside it. Since the space of possible new-physics signatures is far larger than the set of models that can be tested individually, dedicated searches can only ever cover a small fraction. This has motivated the development of signal-agnostic searches based on anomaly detection (AD), which leverages machine learning to identify deviations between the observed data and the SM expectation. By searching for deviations without assuming a particular signal model, a single analysis can be sensitive to a wide range of possible new-physics signatures [1, 2, 3, 4, 5].
The proton-proton collision events collected and analyzed by the LHC experiments are characterized by very high-dimensional representations, and the most viable strategy to robustly perform statistical analysis is to compress the representation into a low-dimensional summary statistic, and perform statistical inference in the reduced space. While for a signal-specific search, one knows the best way to reduce the data to one or a few summary statistics thanks to physics knowledge and supervised machine learning algorithms, in signal-agnostic approaches, the target is not known a priori, and the risk of detection failure due to a wrong summarization becomes critical. Supervised contrastive learning has emerged as an effective way to build such a summary for AD, organizing events by physics process while preserving the structure that separates background from potential anomalies [6, 7, 8, 9]. Compressions of this kind mitigate the look-elsewhere effect inherent in high-dimensional searches and simultaneously reduce the complexity of the problem, retaining power in the downstream statistical test and making it scalable to the full rate of LHC data (see panel A of Figure 1).
For any of this to translate into a complete LHC result, however, systematic uncertainties must be propagated rigorously through the entire pipeline. A credible discovery claim requires a calibrated and robust statistical test. At LHC experiments, every source of uncertainty is treated as a nuisance parameter and profiled. This is exactly where current latent-space AD methods fall short. A nonlinear encoder can turn a simple, smooth systematic shift of the observables into an arbitrarily complicated deformation of the latent space. The dependence of the background density on the nuisance parameters can then become difficult to model, breaking down the profile-likelihood machinery and any robustness guarantee with it. Without robustness guarantees, the test can mistake a systematic shift for a signal leading to an increased chance of false discovery. Panel B of Figure 1 illustrates the problem: when systematic uncertainties are inadequately modeled in the test, the resulting shifts in the data can trigger false alarms (dashed red histogram) that mimic genuine new physics signals (blue step histograms). Treating systematic uncertainties properly and rigorously in the embedding space is, therefore, not just an additional refinement, but a central challenge that must be addressed before these methods can be used in real analyses.
In this work we propose to address this gap by introducing a likelihood-based regularization to jointly train a contrastive encoder so that its latent space covaries linearly with the nuisance parameters. This restores a tractable, analytic model of the background density ratio in the latent space, which we feed into the New Physics Learning Machine (NPLM) profile-likelihood test [10, 11, 12]. The result is an AD workflow that is simultaneously low-dimensional and statistically rigorous: systematic distortions are absorbed by the nuisance model rather than faked as signal. Using simulated CMS Level-1 trigger data, we demonstrate that the method models a realistic jet-energy-scale uncertainty in a 4D latent space, passes closure tests on nuisance-shifted backgrounds, and retains sensitivity to a range of injected beyond-the-SM (BSM) signals.
The rest of this work is organized as follows. Section II reviews related work, covering contrastive learning for anomaly detection at the LHC, equivariant contrastive learning, and the profile-likelihood treatment of systematic uncertainties on which we build. Section III presents our method: a likelihood-based regularization that fine-tunes a contrastive encoder so that its latent space covaries linearly with the nuisance parameters, together with the resulting profile-likelihood anomaly-detection test. Section IV validates the approach on simulated CMS Level-1 trigger data, reporting both closure tests on nuisance-shifted backgrounds and sensitivity to a range of injected BSM signals. Section V summarizes our findings and outlines directions for future work.
II Related Work
II.1 Contrastive learning for anomaly detection
Contrastive learning constructs a latent representation by pulling together the representations of similar examples and pushing apart dissimilar ones. Choosing a latent space with fewer dimensions than the input space also allows this representation to compress the inputs and perform dimensionality reduction. Since the introduction of instance-discrimination frameworks such as SimCLR [13], it has become a standard tool for representation learning. In high energy physics it was first deployed in a self-supervised form to build symmetry-aware jet representations: JetCLR [14] maps jet constituents into a space that is approximately invariant to physically motivated augmentations, later it was used in the context of augmenting simulations to mitigate systematics [15], and closely related self-supervised approaches have since been applied directly to model-agnostic anomaly detection [16]. Building on this line of work, Metzger et al. [6] and related studies [7] established that supervised contrastive losses with physics-process labels produce latent spaces well suited for signal-agnostic AD at the LHC, with domain-knowledge-informed label encoding being the key ingredient for statistical discovery performance. Our encoder is built with exactly this supervised contrastive strategy. None of these works, however, address how systematic uncertainties propagate through the learned embedding once it is used for inference—the gap we fill here.
II.2 Equivariant contrastive learning
Controlling how a learned representation responds to a transformation of its input is precisely the subject of equivariant representation learning. Standard contrastive learning enforces invariance, training representations to be unchanged under a chosen set of augmentations. Invariance is a special case of the more general notion of equivariance, in which a transformation of the input induces a corresponding, specified transformation of its representation. Dangovski et al. [17] added an auxiliary prediction task to self-supervised learning based on invariance: identifying the transformation applied to each input. This encourages broken equivariance for some transformations while retaining invariance for others. They showed that this approach improves the semantic quality of the learned representations. We adapt this idea to the physics setting: the transformations of interest are not geometric augmentations but the systematic distortions of the observables parameterized by nuisance parameters , and the property we require is not invariance but a controlled, linear covariance of the latent density with . Rather than requiring invariance under these distortions, we require the latent density to vary with in a controlled, linear manner (cf. Eq. 8). Enforcing this equivariance-like structure is what renders the downstream profile-likelihood test tractable, as detailed in Section III.
II.3 Dealing with systematic uncertainties in statistical anomaly detection
The statistical framework in which we ultimately deploy the embedding is the “New Physics Learning Machine” (NPLM) [10, 11], a statistical test for signal-agnostic detection based on the likelihood-ratio, which includes a treatment of systematic uncertainties using nuisance parameters. Since our work is directly built on this framework, we review it below.
The NPLM hypothesis test.
The NPLM method [10, 11] treats signal-agnostic anomaly detection as a likelihood-ratio test between an an empirical model of the observed dataset and the Standard Model (SM) hypothesis represented by a reference set . In the language of hypothesis testing, is simply the null hypothesis—the Standard Model prediction in the absence of new physics—which,in NPLM terminology, we call the Reference and denote by throughout. Under the alternative hypothesis , the data density distribution is defined as a local reweighting of the Reference distribution by the exponential of a neural network with trainable parameters ,
| (1) |
The test statistic is the maximum log-likelihood-ratio
| (2) |
obtained directly from the minimum of a training loss acting on and . Because is a flexible, unbiased approximant, the test is sensitive to generic departures from the SM rather than to a single signal model. Ref. [11] showed that, under the Reference hypothesis and with a suitable regularization scheme for the test network , closely follows a distribution.
Continuous systematics as nuisance parameters.
The treatment above assumes the Reference is known exactly, which is never the case: detector calibration, theory, and PDF uncertainties all distort the expected SM distribution, and these effects must be propagated into any LHC result for it to be trusted. Ref. [12] extends NPLM to incorporate them following the canonical profile-likelihood treatment, by associating each source of uncertainty with a nuisance parameter constrained by an auxiliary likelihood . The Reference hypothesis becomes composite, , and the alternative gains the same nuisance dependence, :
| (3) |
Normalizing both likelihoods to that of the central-value Reference , where is the best prior estimate of the nuisance parameter, allows us to express the test statistic as the difference of two positive-definite terms:
| (4) |
and the nuisances ,
| (5) | ||||
| (6) |
Intuitively, is the full “discovery” term: it measures how much better the flexible alternative with nuisances describes the data than the central-value Reference. As a result, we see the test statistic deviates from for any reason, whether it is a genuine signal or a mismodeled systematic. The correction contains no test network: it measures how much of that same departure can be absorbed by the Reference alone, simply by pulling the nuisance away from its central value. Subtracting from therefore removes the part of the discrepancy that is explainable as a systematic distortion, so that isolates genuinely anomalous structure. Both terms are maximum-likelihood log-ratios and are asymptotically -distributed; the cancellation between them is precisely what keeps close to a -independent , so that a single calibration on yields a -value valid across the allowed range of .
Modeling the nuisance dependence.
Both and require the density ratio between the shifted and nominal Reference distributions,
| (7) |
to be known as a function of at every point . Ref. [12] models its logarithm with a low-order polynomial in ,
| (8) |
whose coefficient functions are learned by training a parameterized classifier between the nominal and shifted samples with a quadratic (mean-squared) loss. This expansion is tractable only when the systematic effect is a small, smooth deformation of the distribution—a condition that holds in the space of physical observables, and is not guaranteed to survive a nonlinear encoder. Related strategies for handling systematics in learned classifiers include parameterized networks [18], uncertainty-aware inference [19], and invariance via adversarial decorrelation [20, 21].
Linear Nuisance Dependence.
The methods we build on were designed to act on physical observables, where the small-deformation condition behind Eq. (8) may or may not hold depending on the problem under study, limiting the application of the method. Our goal is move the statistical test from the space of the physical observables to the latent space of a contrastive encoder , that we have the freedom to train or fine-tune. A nuisance shift induces a transformation of the embedding. The latter could be large and difficult to approximate with a polynomial expansion. The polynomial model of then breaks down resulting in a poor estimation of the correction term (Eq. (6)). We resolve it by training the encoder so that the latent log-density-ratio is, by construction, linear in . This recovers a controlled term and an interpretable, profilable nuisance model directly in the embedded space.
III Method
Our end-to-end analysis workflow includes three stages, as illustrated in Figure 2:
- 1.
Building Contrastive Embeddings with Controlled Covariance. We map high-dimensional physics observables into a low-dimensional latent space with supervised contrastive learning, training the encoder jointly with a likelihood-based regularization. The resulting embedding preserves the physics structure needed for anomaly detection while forcing continuous systematic uncertainties to act on the latent space in a controlled way, such that their effect is linear in the nuisance parameter .
- 2.
Fine-tuning and Validating the Linear Nuisance Model. We freeze the embedding, further fine-tune the linear model of the nuisance dependence, and validate it with NPLM closure tests performed in the presence of systematic uncertainties.
- 3.
Signal Injection and Anomaly Detection. We inject signal and run the profile-likelihood NPLM test directly in the latent space, quantifying the resulting shift of the test-statistic distribution and converting it into a calibrated significance.
We describe the three stages in turn below; their empirical implementation and validation are reported in Section IV.
III.1 Stage 1: Building neural embeddings with a controlled covariance
Supervised contrastive learning offers a scalable route to anomaly detection by performing dimensionality reduction through neural embeddings: it compresses physics observables into a low-dimensional latent space while preserving sensitivity to statistical anomalies. Refs. [6, 7] showed that contrastive losses defined with physics-process labels yield latent spaces well suited to signal-agnostic anomaly detection at the LHC, with domain-informed label encoding being the key ingredient for statistical discovery performance.
We train a transformer-based encoder () with the supervised contrastive loss [22],
| (9) |
where is the -normalized embedding, indexes the events in the batch produced by the same background physics process as event , and is a hyperparameter denoted temperature. With labels taken from simulation, this organizes the latent space by background physics process, clustering SM events of the same type. This loss does not account for systematic uncertainties. To include systematic uncertainties, we add an additional term to the loss that controls systematic variations on the latent space.
A continuous systematic uncertainty is described by a nuisance parameter that induces a deterministic distortion of the observables, . After encoding, this becomes a transformation of the latent distribution, . Without any constraint on , this transformation can be arbitrarily nonlinear in , making the latent log-density-ratio
| (10) |
difficult to model. As discussed in Section II.3, the NPLM strategy requires uncertainties to be well approximated by a polynomial model, so recovering a well behaved transformation in the embedded space is essential.
To this end, we impose a linear covariance condition on the latent space. Under this penalty loss the encoder is induced to organize the embedding so that the log-density-ratio is linear in ,
| (11) |
where depends on the embedding alone. Under this condition is directly estimable by maximum likelihood in the latent space, and the nuisance profiling required by the statistical test becomes tractable.
We enforce condition (11) by training the encoder jointly with a model of the log-density-ratio. This mirrors equivariant self-supervised learning [17], where an auxiliary head that predicts the applied transformation improves representation quality; here we replace the geometric transformations with systematic effects parameterized by . Concretely, we generate labeled pairs on a discrete grid of spanning the expected range , and train as a parameterized classifier between the nominal and shifted distributions following [12], minimizing the quadratic loss
| (12) |
where denotes the sigmoid function and the sum runs over the grid of nuisance values. By the likelihood-ratio argument of [12], the minimizer satisfies , so training enforces the linear model in (11).
The encoder and the ratio model are therefore optimized together, from the beginning of training, with the combined objective
| (13) |
where balances the two terms. Backpropagating through into encourages the encoder to learn a representation in which the nuisance dependence of the density ratio is well described by the linear nuisance model.
III.2 Stage 2: Fine-tuning and validating the linear nuisance model with NPLM
Once this joint optimization has converged, we freeze the embedding and validate the linear nuisance model within the NPLM framework, following the strategy outlined in [12]. The procedure, summarized in Fig. 3, consists of four steps: we fine-tune the linear model, use it to build the profiled test statistic, tune the weight clipping of test network for compatibility, and finally validate the modeling via closure checks.
With the encoder frozen, we first fine-tune further to reach the accuracy needed for the statistical test. The frozen encoder and the fine-tuned linear model then integrate directly into the profile-likelihood NPLM framework described in Section II.3. The test statistic is the profile-likelihood ratio defined in Eq. (3), evaluated in the latent space , with modeling the density ratio given in Eq. 10.
To calibrate the test, we identify an architecture and regularization for the test network that render the test statistic approximately -distributed under the null in the absence of uncertainties. We then incorporate the systematic via the linear model of Eq. (11) and validate the modeling via closure checks. We describe the regularization and closure checks below.
Weight clipping for regularization.
The flexibility of the test network must be controlled for the test to behave well. Left unconstrained, the maximum-likelihood fit in Eq. (3) is unbounded: can grow without limit to chase the statistical fluctuations of a finite sample, overfitting the data and driving the null distribution of into heavy, non-universal tails that spoil the asymptotic behavior. Following the NPLM prescription [11, 12], we regularize the fit by weight clipping such that after every gradient update, the trainable weights of are projected back onto a bounded box , where the weight-clipping parameter caps the effective capacity of the network. This bounds the achievable log-density-ratio, and, although the formal conditions of Wilks’ theorem are not satisfied in this setting, we find the null distribution remains close to the asymptotic regime. As a consequence, the function approaches a whose number of degrees of freedom matches the number of trainable parameters of .
The value of is a hyperparameter that trades calibration against sensitivity: if is too small, is too rigid to capture genuine departures and the NPLM test loses power; if is too large, the network overfits and the null distribution drifts away from the asymptotic . Following [11, 12], we choose the weight clipping for which the empirical null distribution—built from an ensemble of central value Reference pseudo-experiments—remains statistically compatible with a with number of degrees of freedom matching the number of trainable parameters. The value of W selected this way is then used in the computation of likelihood.
Closure tests for the linear nuisance model
The choice of weight clipping and the fine tuning of the linear model fully determine the statistical model used in the test. The next step is to check the robustness of the latter to systematic variations of the data. In particular, the test statistics is considered robust to systematic effects if its distribution under the null does not change under mild systematic variations. Operationally,
| (14) |
To verify this property, we build the null distribution from an ensemble of pseudo-experiments (toys) drawn from the central-value reference. The analogous distribution is ontained from toys drawn from a reference with nuisance shifted of from the central value. We then quantify their agreement with a two-sample Kolmogorov–Smirnov (KS) test. The resulting KS -value measures whether the two empirical distributions are statistically compatible. A large value confirms that the profiled nuisance model absorbs the systematic shift, i.e. that is effectively independent of , as anticipated by the cancellation. This construction uses the entire distribution on both sides, each estimated from a large set of toys. We refine the linear model and perform this check recursively, until a good agreement is found.
III.3 Stage 3: Signal injection and anomaly detection
After the test has passed the robustness checks it is ready to be deployed for anomaly detection. When applied to real data , a single value of the test statistic is observed and thus a single global p-value is reported:
| (15) |
To assess the expected sensitivity to a simulated signal, we apply the test to many pseudo-experiments containing both background and signal. This gives the distribution of the test statistic under the alternative hypothesis. We then estimate the power at a given false-positive rate as the fraction of these pseudo-experiments in which the null hypothesis is rejected. We also report the p-value corresponding to the median test statistic, calculated using Eq. (15), as a measure of typical sensitivity. For probabilities estimated from finite samples of pseudo-experiments, we report Clopper–Pearson confidence intervals. Throughout this article we will often refer to p-values by their significance expressed as , with the standard-normal cumulative distribution function.
We evaluate this against three choices of null: (a) the empirical distribution from central-value toys; (b) the empirical distributions of the nuisance-shifted references at and ; and (c) the analytic survival function of the asymptotic distribution discussed above. In all three cases, we used the median of the signal distribution, exactly as the significance would be quoted for a single observed dataset. To assess how residual nuisance dependence affects the expected significance, we compare the nominal null distribution with those obtained for nuisance shifts of . Although the test statistic is designed to be approximately independent of the nuisance parameter, small differences may remain, particularly in the tails of these distributions. At the same median test statistic, a heavier tail gives a larger -value and lower significance. Comparing the nominal and shifted null distributions allows us to check whether using only the nominal reference would overstate the expected sensitivity. Close agreement among (a), (b), and (c) then doubles as a check that is effectively -independent, so that the single calibration on remains valid across the allowed range of the nuisance. In Section IV we use the KS construction as a closure test on nuisance-shifted backgrounds and the median- construction as our sensitivity measure for injected signals.
IV Numerical Experiments on LHC Data
In this section, we apply the approach proposed in Section III to a simulated LHC dataset. We evaluate the role of co-training in achieving closure by comparing the test-statistic distributions under nominal and nuisance-shifted background conditions. We also study its impact on signal sensitivity, considering both an idealized setting without nuisance parameters in the NPLM test and a nuisance-aware setting that includes them.
IV.1 Dataset
We apply the method to simulated CMS Level-1 trigger data [23] available on Zenodo [24, 25, 26, 27, 28]. Each event is represented by up to 19 reconstructed objects: 4 electrons/photons, 4 muons, 10 jets, and one missing transverse energy (MET) slot. Each object is described by , yielding 57 input features per event, with zero padding applied when fewer objects are present. The background sample consists of (), QCD multijet (), (), and () events, while the signal benchmarks are , , , and .
To model a realistic systematic effect, we introduce a nuisance parameter that rescales the jet transverse momentum as , with nominal value . We set the standard uncertainty to , a typical percent-level size of jet energy scale uncertainties in LHC analyses [29].
After rescaling, we apply the same jet-level cut of to the nominal and nuisance-shifted samples, giving them a common selection threshold. This ordering reflects an experimental selection, where trigger or analysis cuts act on the measured jet momenta, which already include any underlying systematic shift. Jets can therefore move across the selection threshold as varies.


IV.2 Contrastive Embedding Models
Following Ref. [6], we use a Transformer-based encoder to map the 57-dimensional input to a 4-dimensional embedding, which gave the strongest AD performance among the dimensions tested. We leave the systematic study of nuisance uncertainty in higher-dimensional embeddings to future work. Nominal SM background events are used for the supervised contrastive task with physics labels. The initial contrastive embedding is shown in Figure 5. Before co-training with the linear nuisance model, the empirical log-ratios are not always smoothly ordered or approximately linear across values of , making their nuisance dependence difficult to model with the linear log-density-ratio parametrization of Eq. (11).
To impose a more controlled nuisance dependence, we performed the regularized training described in Section III.1. The encoder is trained in a 5-fold co-training setup with the linear model , using events per fold per dataset, 60 epochs, a batch size of 1024, and a learning rate of .The resulting embedding is shown in Figure 5. After co-training with the covariance loss , the nuisance-shifted marginal distributions vary more smoothly and coherently with , making the latent deformation easier to describe with the linear log-density-ratio model . Although co-training takes longer than standard contrastive training, the encoder is trained only once and then frozen for the statistical tests. The covariance loss plateaus during training, while the nuisance model benefits from longer fine-tuning.
Figure 6 directly compares the nuisance dependence of before and after co-training. Each panel shows a selected bin in the first embedding dimension, with the bin center indicated above the panel. These bins are chosen only to illustrate the effect of linearization and are not representative of every bin in the embedding space. Here, is the number of events in that bin for a nuisance-shifted sample, while is the corresponding nominal count. The solid lines with error bars show the empirical values at , , and , while the dashed lines show the fits from the linear nuisance model. Results for the original embedding are shown in blue, while those for the linearized embedding are shown in red.
Before co-training, the empirical blue lines can deviate substantially from the corresponding predictions of the linear model, indicating that the nuisance dependence encoded in the original embedding is not sufficiently linear to be accurately described by the linear parameterization of . After co-training, the empirical red lines follow the dashed predictions much more closely across the selected bins, demonstrating a clear improvement in the quality of the linear fit. These results show that jointly training the contrastive embedding and linear nuisance models reshapes the embedding such that its nuisance dependence is more accurately described by . In this sense, co-training effectively linearizes the nuisance response of the embedding, making the chosen linear parameterization a substantially better approximation of the observed variations.
IV.3 Linear Model
We co-train the linear nuisance model of Eq. (11) on the learned embeddings. It is linear in the nuisance parameter and, as a function of the embedding , is implemented as a fully connected network with architecture , ReLU activations in the hidden layers, and a linear output. It is trained jointly with the contrastive encoder (Eq. (13)) using a learning rate of , regularization of , and co-training weight , then further fine-tuned on events per nuisance parameter. Both nominal and nuisance-shifted samples at and are used for this task. Figure 7 compares the nuisance-shifted test samples with the predictions of the fitted linear model across the four latent dimensions. The top row shows the nominal distribution at in gray, together with the test distributions at (solid lines) and their corresponding model predictions (dash-dotted lines). The middle row shows the same comparison in terms of . In both rows, the test and model samples are visually in close agreement across all four latent dimensions, indicating that the model accurately captures how the latent distributions change with . This agreement is further confirmed by the bottom-row ratios of the model prediction to the test distribution, , which remain close to one throughout most regions in the latent space. Overall, the close visual agreement demonstrates that the linear nuisance model accurately captures the nuisance dependence of the embedding, suggesting that co-training has successfully linearized the nuisance dependence of the embedding.
IV.4 Weight clipping regularization
The alternative-hypothesis network in Eq. (3)is implemented as a fully connected neural network with architecture , corresponding to 45 trainable parameters, with sigmoid activations in the hidden layers and a linear output. Following the calibration procedure of Section III, a weight-clipping regularizer is tuned with 400 pseudo-experiments drawn from the nominal reference sample so that the empirical null distribution matches the asymptotic (45 degrees of freedom, one per trainable parameter) [11]. Weight clipping bounds the absolute value of the network’s trainable parameters during training, which constrains the smoothness of the learned density ratio and prevents the model from overfitting statistical fluctuations in ; tuning the clipping value is what brings the empirical null into fair agreement with the asymptotic . We train using reference events and background events per replica. We tune the weight clipping for two different implementations: (1) NPLM implemented in the original embedding from [6] as it is before co-training with the linear nuisance model, and (2) NPLM implemented in the embedding co-trained with the linear nuisance model as explained in Section IV.3. The optimal weight-clipping is 2.12 in the first case and 1.94 in the second case. Table 1 reports the results of the Kolmogorov–Smirnov, Anderson–Darling, Cramér–von Mises, and Pearson compatibility tests between the analytical distribution and the empirical test-statistic distributions obtained with the original and linearized embeddings. Pearson tests are performed using binnings corresponding to 10 and 25 degrees of freedom, and each embedding is evaluated at its selected weight-clipping value. All of the resulting -values are greater than , indicating good agreement with the analytical distribution and supporting the chosen weight-clipping values.
| Test | Unlinearized | Linearized |
|---|---|---|
| () | () | |
| KS | ||
| AD | ||
| CvM | ||
| (10 DoF) | ||
| (25 DoF) |
IV.5 NPLM Validations
We perform the closure test described in Section III.2 to verify that nuisance-induced background variations are not misidentified as signal-like excesses. Specifically, we apply the NPLM test to nuisance-shifted SM samples , using the same luminosity as in the nominal calibration. Since these samples do not contain injected signal, their test-statistic distributions should remain consistent with the central-value null distribution once nuisance effects are properly modeled.
Figure 8 compares the background-only test-statistic distributions for and under three configurations. In all three panels, the filled red histogram represents the empirical distribution under the central-value reference hypothesis, while the orange and brown step histograms represent the distributions under and , respectively. Panel 8(a) shows the NPLM test without treatment of uncertainties. In this case, the test has no way to account for the expected nuisance-induced variations, so the shifted background distributions move away from and can appear signal-like. In panel 8(b), nuisance parameters are included in the NPLM test, but the original unlinearized embedding from Ref. [6] is used. The shifted distributions still do not reach closure because the nuisance dependence is encoded nonlinearly in the learned representation and cannot be fully absorbed by adding only a downstream linear nuisance model. This motivates linearizing the embedding itself rather than relying on the NPLM nuisance fit alone. Finally, panel 8(c) shows the result of our method, co-training the embedding with the linear nuisance model. The nominal and nuisance-shifted distributions are now in good agreement, demonstrating that the linearized embedding, together with the nuisance-aware NPLM test, successfully prevents the systematic variations from causing false positives.
We quantify the agreement in the final linearized configuration shown in panel 8(c) using 400 background-only replicas for each nuisance value. Table 2 presents two complementary checks. First, we assess closure by comparing the nuisance-shifted test-statistic distributions, , with the nominal reference using the Kolmogorov–Smirnov (KS), Anderson-Darling (AD), and Cramer-von-Mises (CvM) tests, and binned Pearson compatibility tests with 10 and 25 degrees of freedom. All closure-test -values exceed 0.5, indicating that the shifted distributions are consistent with the nominal reference. Second, we compare the same nuisance-shifted distributions with the analytical distribution using the KS, Anderson–Darling (AD), Cramér–von Mises (CvM), and Pearson tests. These -values range from 0.24 to 0.86 and show no significant departure from the analytical reference. Together, these results support the interpretation that the linear model , combined with the co-trained embedding, describes the nuisance-induced deformation sufficiently well to preserve the background-only test-statistic distribution. This closure is essential for latent-space anomaly detection, where an unmodeled systematic shift could otherwise produce an artificially significant excess.
To assess the role of co-training in achieving this closure, Table 3 reports the same tests for the unlinearized embedding with nuisance parameters included in the NPLM test, corresponding to panel 8(b). Although the nominal distribution agrees with the analytical reference, both nuisance-shifted distributions are inconsistent with and with the analytical reference, with small -values across all tests. Agreement at the nominal nuisance value therefore does not ensure closure under nuisance shifts. Together with the linearized results, this comparison shows that the downstream linear nuisance model alone is insufficient to describe the shifts in the original embedding, while co-training enables the same model to achieve closure.
| Test | empirical | analytical | ||
|---|---|---|---|---|
| KS | ||||
| AD | ||||
| CvM | ||||
| (10 DoF) | ||||
| (25 DoF) | ||||
| Test | empirical | analytical | ||
|---|---|---|---|---|
| KS | ||||
| AD | ||||
| CvM | ||||
| (10 DoF) | ||||
| (25 DoF) | ||||
IV.6 Signal Sensitivity
We then assess signal sensitivity by injecting a small signal component into the SM background sample. We consider 0.5% and 1% signal injections, corresponding in our luminosity settings to 50 and 100 injected signal events, respectively. For each injected sample, we compute the NPLM test statistic and convert it into an empirical -score relative to the chosen background-only calibration distribution, estimated from 400 replicas. Figure 9 compares the test-statistic distributions obtained for a injection under the three nuisance-treatment configurations considered in this work. The first configuration, Figure 9(a), omits nuisance parameters from the NPLM test and shows how the test responds when systematic variations are not explicitly accounted for. In the second configuration, shown in Figure 9(b), the nuisance parameters are included in the test using the original, unlinearized embedding. Figure 9(c) combines the nuisance-aware NPLM test with the co-trained, linearized embedding and therefore corresponds to the full procedure proposed in this work.
The distributions in Figure 9 show that, when nuisance parameters are omitted from the NPLM test, the test statistic distribution under nuisance-shifted background-only (orange and brown) and under signal-injection (shades of blue) both shift toward larger values and cannot be reliably distinguished. Including the nuisance parameters with the original, unlinearized embedding also does not fully resolve this problem, as shown in Figure 9(b), where the shifted background distributions remain separated from and alter the calculation of p-values. On the other hand, after co-training, the background-only distributions achieve closure, while the signal-injected distributions remain right-shifted toward larger for all tested nuisance values. The linearized embedding therefore allows nuisance-induced variations to be calibrated retaining sensitivity to the signal injection across the tested values of .
The detection results of our method on experiments with signal-injection across the four signal benchmarks are summarized in Table 4. The table reports the median observed -scores obtained by calibrating each test sample against the empirical background-only distribution . We use the same reference for the unlinearized results in Table 5 to allow a direct comparison. These results show that the NPLM test retains sensitivity to small injected signals across the tested nuisance values. To further show the stability of our results, we report in Appendix A the same study using the nominal reference , the nuisance-shifted reference , and the asymptotic distribution for calibration.
| Test sample | ||||||||
|---|---|---|---|---|---|---|---|---|
| (calibrated by ) | ||||||||
| Test sample | ||||||||
|---|---|---|---|---|---|---|---|---|
| (calibrated by ) | ||||||||
Table 5 instead evaluates the original embedding after nuisance parameters are incorporated into the NPLM test. Because the unlinearized embedding does not achieve closure between and , the nominal distribution cannot be treated as a nuisance-independent null reference. Among the tested reference distributions, has the longest high- tail and yields slightly more conservative significances. We therefore calibrate these results against as the conservative reference where closure is not achieved. Even under this conservative calibration, the significance of the same signal injection remains strongly dependent on the nuisance value of the test sample. Although some variation is expected from finite-sample fluctuations and further reduced sensitivity can be caused by nuisance coupling with the injected signal, the variations observed across nuisance values within the same signal-injection column in Table 5 indicate that the reported sensitivity is strongly driven by the lack of background closure. In particular, the sensitivity is systematically larger when the nuisance is not in the central value, suggesting that the observed z-score is inflated by the residual mismodeling of the uncertainties. The instability is further reflected in the negative -scores, which occur when the median test statistic of a signal-injected distribution lies below the median of the conservative reference distribution, corresponding to a one-sided empirical -value greater than . In these cases, the nuisance-induced displacement of the unlinearized background distribution is larger than the displacement produced by the injected signal. The negative values therefore do not indicate a “negative signal,” but instead demonstrate that a post-hoc correction for the absence of closure causes a systematic shift that can obscure or overwhelm the signal response. Overall, this nuisance dependence makes the resulting significances unreliable. The same underlying signal can appear more significant, less significant, or even shifted below the reference median, causing loss in sensitivity and even chances of false claims.
Unlinearized embedding
Linearized embedding
Figure 10 illustrates this effect for a injection of the signal. The background-only distribution at has a larger median test statistic than the signal-injected distribution at . Calibrating the latter against therefore gives a median -value above and a negative -score, despite the presence of signal. This example shows how, without co-training, residual nuisance effects can exceed the response to an injected signal,limiting the test’s ability to distinguish new physics from nuisance-induced shifts.
Conversely, the detection performed in the linearized embedding (Table ) yields -scores that are substantially more stable across the tested nuisance values: within each benchmark and injection fraction, the spread across is at most , compared with up to for the unlinearized embedding. At the nominal value , the linearized embedding also yields equal or higher significance for every benchmark. At the unlinearized embedding can return larger -scores, but, as discussed above, these are inflated by residual nuisance mismodeling rather than reflecting genuine sensitivity. The closure between and provides a consistent background-only calibration, ensuring that the inferred significances primarily reflect the injected signals rather than unknown nuisance variations. The linearized embedding therefore provides both improved sensitivity and reliably calibrated significances, making it the more robust and practically usable representation for an uncertainty-aware anomaly search.
The power curves in Figures 11 and 12 provide a richer view of the discovery sensitivity, inspecting all discovery thresholds simultaneously for and signal injections, respectively. Each figure compares the unlinearized embedding in the top row with the linearized embedding in the bottom row, both calibrated against . Each curve gives the probability that the observed significance exceeds a threshold ; better performance is indicated by signal-injected curves that lie well above the gray calibration curve and retain high power as increases. For the linearized embedding, the power curves corresponding to different nuisance values overlap closely in most cases, indicating that the discovery power is both strong and mostly independent of . In contrast, the unlinearized embedding shows much larger shifts and fluctuations across nuisance values. Overall, the linearized embedding yields power curves that are nearly independent of and, at the nominal value , lie at or above those of the unlinearized embedding. The higher power of the unlinearized embedding at in some panels reflects the lack of background closure rather than genuine discovery sensitivity. These trends are consistent with the test-statistic distributions in Fig. and the median -scores reported in Tables and : the linearized embedding gives stable sensitivity across nuisance values, whereas the unlinearized embedding produces a less reliable and strongly nuisance-dependent response.
IV.7 Computational Resources.
Encoder () training was performed on a 48 GB GPU, with a typical training time of 4 hours and 45 minutes. Linear model () fine-tuning was performed on a 48 GB GPU, with a typical training time of 3 hours. The test network was trained on CPUs, with a typical training time of 50 minutes.
IV.8 Code Availability.
The code and detailed documentation to reproduce the experiments can be found at https://github.com/tshelley200/cl4ad_uncertainty.
Unlinearized embedding
Linearized embedding
V Conclusion
We introduced a method for incorporating continuous systematic uncertainties into contrastive latent spaces. The approach imposes a controlled linear covariance structure, with the goal of enabling statistically rigorous profile-likelihood anomaly detection at the LHC. We regularized the training of a contrastive neural embedding using an auxiliary objective that encourages the learned log-density ratio to vary linearly with the nuisance parameter. This keeps the latent space compact, while preserving the information needed to model systematic variations.
This construction integrates naturally with the anomaly detection framework of [12]. It provides a scalable workflow in which nuisance-dependent effects can be included directly in the likelihood-based test statistic, rather than treated through post-hoc calibration.
The results presented in this work demonstrate that we can build anomaly detection methods that capture high-dimensional event structure, while remaining tractable and enabling robust and interpretable inference. Contrastive representations can be made compatible with continuous nuisance profiling, allowing the quantitative study of systematic uncertainties affecting an arbitrarily complex input representation in the flat, low-dimensional representation of an embedded space.
Enforcing linearity in carries two additional benefits: (1) it simplifies the modelling and combination of multiple nuisance parameters and (2) it enables powerful combination of the test statistic across batches of data [30]. The proposed approach therefore offers a path toward the deployment of contrastive anomaly detection pipelines in full-scale LHC analyses, where a robust treatment of systematic uncertainties is essential. Future work will extend the method to multiple nuisance parameters and to higher luminosity, towards more realistic experimental settings.
Acknowledgements.
This work is supported by the National Science Foundation under Cooperative Agreement PHY-2019786, the NSF AI Institute for Artificial Intelligence and Fundamental Interactions, http://iaifi.org/. Computations in this paper were run on the FASRC Cannon cluster supported by the FAS Division of Science Research Computing Group at Harvard University.Appendix A Additional calibration tables
We report in Tables 4 and 6 the observed median z-scores of the signal injection experiments using as empirical calibration the test statistic distribution under and . Results in these Tables are compatible with the ones reported in Table 7, further confirming that the NPLM test was implemented in a robust way.
| Test sample | ||||||||
|---|---|---|---|---|---|---|---|---|
| (calibrated by ) | ||||||||
| Test sample | ||||||||
|---|---|---|---|---|---|---|---|---|
| (calibrated by ) | ||||||||
We report in Table 8 the observed median z-scores of the signal injection experiments using as calibration the asymptotic . The results in this Table are compatible with the ones reported in Table 6, further confirming the compatibility of the null distribution with obtained via weight clipping tuning.
| Test sample | ||||||||
|---|---|---|---|---|---|---|---|---|
| (cal. by ) | ||||||||
| 0.33 | 1.08 | 0.82 | 3.19 | 0.17 | 0.65 | 0.99 | 3.05 | |
| 0.31 | 0.96 | 0.90 | 3.03 | 0.20 | 0.61 | 0.96 | 2.80 | |
| 0.28 | 0.93 | 0.87 | 3.06 | 0.21 | 0.61 | 0.86 | 2.72 | |
Appendix B The effect of linearization in the latent representation
Table 9 shows the detection performance of NPLM in the absence of uncertainties, for both the original embedding, trained with supervised contrastive learning alone, and our proposed embedding, co-trained with a linearization penalty. While this is not a realistic scenario it informs us about the properties of the embedding as an input to the NPLM test. After linearization the sensitivity of NPLM is moderately degraded, telling us that accounting for systematics in the embedding come at the cost of degraded sensitivity. This is a price we are willing to pay in order to make the detection robust and reliable.
| Embedding | ||||||||
|---|---|---|---|---|---|---|---|---|
| Before Linearization | ||||||||
| After Linearization | ||||||||
Appendix C Quadratic Nuisance Model
Throughout the main text, we use a linear nuisance model in the NPLM test, corresponding to the simplest nontrivial polynomial dependence on the nuisance parameter. This choice is motivated primarily by its use in “stacking,” where multiple datasets are combined to increase the effective luminosity beyond that of the individual 10,000-event samples considered here; a detailed treatment of this procedure is left to a separate future work. However, a higher-order polynomial model can generally better describe residual nonlinearities in the nuisance dependence across the embedding space. In particular, a quadratic model can improve closure where the linear approximation is insufficient and yield more stable signal significances across different nuisance values.
In this section, we evaluate a quadratic nuisance model using the same linearized embeddings, closure tests, and signal-injection studies as in the main text. In Table 10, we report compatibility tests between the nominal and nuisance-shifted background-only distributions, and , and in Table 11 the observed median -scores for the signal-injection experiments, calibrated against the empirical nominal distribution . The results are broadly consistent with those obtained using the linear nuisance model in Tables 6 and 4, with slight improvements in closure tests. The quadratic model yields results in close agreement with those of the linear model, indicating that the additional complexity provides no meaningful improvement. The linear assumption is therefore good enough for this study.
| Test | DoF | ||
|---|---|---|---|
| Kolmogorov–Smirnov | — | ||
| Pearson | 10 | ||
| 14 | |||
| 17 | |||
| 20 | |||
| 25 |
| Test sample | ||||||||
|---|---|---|---|---|---|---|---|---|
References
- [1] G. Aad et al. (ATLAS), Dijet resonance search with weak supervision using TeV collisions in the ATLAS detector, Phys. Rev. Lett. 125, 131801 (2020), arXiv:2005.02983 [hep-ex] .
- [2] G. Aad et al. (ATLAS), Anomaly detection search for new resonances decaying into a Higgs boson and a generic new particle in hadronic final states using TeV collisions with the ATLAS detector, Phys. Rev. D 108, 052009 (2023), arXiv:2306.03637 [hep-ex] .
- [3] G. Aad et al. (ATLAS), Weakly supervised anomaly detection for resonant new physics in the dijet final state using proton-proton collisions at s=13 TeV with the ATLAS detector, Phys. Rev. D 112, 072009 (2025), arXiv:2502.09770 [hep-ex] .
- [4] V. Chekhovsky et al. (CMS), Model-agnostic search for dijet resonances with anomalous jet substructure in proton–proton collisions at = 13 TeV, Rept. Prog. Phys. 88, 067802 (2025), arXiv:2412.03747 [hep-ex] .
- [5] A. Hayrapetyan et al. (CMS), Machine-learning techniques for model-independent searches in dijet final states 10.5281/zenodo.16656501 (2025), arXiv:2512.20395 [hep-ex] .
- [6] K. Metzger, L. Xu, M. Sodini, T. K. Arrestad, K. Govorkova, G. Grosso, and P. Harris, Anomaly-preserving contrastive neural embeddings for end-to-end model-independent searches at the LHC, Phys. Rev. D 112, 072011 (2025), arXiv:2502.15926 [hep-ex] .
- [7] S. Bright-Thonney, C. Reissel, G. Grosso, N. Woodward, K. Govorkova, A. Novak, S. E. Park, E. Moreno, and P. Harris, Autoscidact: Automated scientific discovery through contrastive embedding and hypothesis testing, arXiv preprint arXiv:2510.21935 (2025).
- [8] R. Li, B. Nachman, and D. Noll, Signal-Aware Contrastive Latent Spaces for Anomaly Detection, (2026), arXiv:2603.25794 [hep-ph] .
- [9] C. L. Cheng, J. Gonski, R. Li, Q. Liu, B. Nachman, D. Noll, J. K. Romman, and L. Wu, Towards anomaly detection searches for new physics signatures including Higgs bosons with weakly supervised machine learning, (2026), arXiv:2607.19323 [hep-ex] .
- [10] R. T. D’Agnolo and A. Wulzer, Learning new physics from a machine, Physical Review D 99, 015014 (2019).
- [11] R. T. D’Agnolo, G. Grosso, M. Pierini, A. Wulzer, and M. Zanetti, Learning multivariate new physics, Eur. Phys. J. C 81, 89 (2021), arXiv:1912.12155 [hep-ph] .
- [12] R. T. D’Agnolo, G. Grosso, M. Pierini, A. Wulzer, and M. Zanetti, Learning new physics from an imperfect machine, Eur. Phys. J. C 82, 275 (2022), arXiv:2111.13633 [hep-ph] .
- [13] T. Chen, S. Kornblith, M. Norouzi, and G. Hinton, A simple framework for contrastive learning of visual representations, in Proceedings of the 37th International Conference on Machine Learning (ICML), Vol. 119 (2020) pp. 1597–1607, arXiv:2002.05709 [cs.LG] .
- [14] B. M. Dillon, G. Kasieczka, H. Olischläger, T. Plehn, P. Sorrenson, and L. Vogel, Symmetries, safety, and self-supervision, SciPost Physics 12, 188 (2022a), arXiv:2108.04253 [hep-ph] .
- [15] P. Harris, M. Kagan, J. Krupa, B. Maier, and N. Woodward, Re-Simulation-based Self-Supervised Learning for Pre-Training Foundation Models, (2024), arXiv:2403.07066 [hep-ph] .
- [16] B. M. Dillon, R. Mastandrea, and B. Nachman, Self-supervised anomaly detection for new physics, Physical Review D 106, 056005 (2022b), arXiv:2205.10380 [hep-ph] .
- [17] R. Dangovski, L. Jing, C. Loh, S. Han, A. Srivastava, B. Cheung, P. Agrawal, and M. Soljačić, Equivariant contrastive learning, arXiv preprint arXiv:2111.00899 (2021).
- [18] P. Baldi, K. Cranmer, T. Faucett, P. Sadowski, and D. Whiteson, Parameterized neural networks for high-energy physics, The European Physical Journal C 76, 235 (2016).
- [19] P. De Castro and T. Dorigo, Inferno: inference-aware neural optimisation, Computer Physics Communications 244, 170 (2019).
- [20] G. Louppe, M. Kagan, and K. Cranmer, Learning to pivot with adversarial networks, Advances in neural information processing systems 30 (2017).
- [21] G. Kasieczka and D. Shih, Disco fever: Robust networks through distance correlation, arXiv preprint arXiv:2001.05310 (2020).
- [22] P. Khosla, P. Teterwak, C. Wang, A. Sarna, Y. Tian, P. Isola, A. Maschinot, C. Liu, and D. Krishnan, Supervised contrastive learning, Advances in neural information processing systems 33, 18661 (2020).
- [23] E. Govorkova, E. Puljak, T. Aarrestad, M. Pierini, K. A. Woźniak, and J. Ngadiuba, Lhc physics dataset for unsupervised new physics detection at 40 mhz, Scientific Data 9, 118 (2022).
- [24] T. Aarrestad, E. Govorkova, J. Ngadiuba, E. Puljak, M. Pierini, and K. A. Wozniak, Unsupervised new physics detection at 40 mhz: Training dataset, 10.5281/zenodo.5046389 (2021a).
- [25] T. Aarrestad, E. Govorkova, J. Ngadiuba, E. Puljak, M. Pierini, and K. A. Wozniak, Unsupervised new physics detection at 40 mhz: A -¿ 4 leptons signal benchmark dataset, 10.5281/zenodo.5046446 (2021b).
- [26] T. Aarrestad, E. Govorkova, J. Ngadiuba, E. Puljak, M. Pierini, and K. A. Wozniak, Unsupervised new physics detection at 40 mhz: Lq -¿ b tau signal benchmark dataset, 10.5281/zenodo.5055454 (2021c).
- [27] T. Aarrestad, E. Govorkova, J. Ngadiuba, E. Puljak, M. Pierini, and K. A. Wozniak, Unsupervised new physics detection at 40 mhz: h0 -¿ tau tau signal benchmark dataset, 10.5281/zenodo.5061633 (2021d).
- [28] T. Aarrestad, E. Govorkova, J. Ngadiuba, E. Puljak, M. Pierini, and K. A. Wozniak, Unsupervised new physics detection at 40 mhz: h+ -¿ tau nu signal benchmark dataset, 10.5281/zenodo.5061688 (2021e).
- [29] ATLAS Collaboration, A precise measurement of the jet energy scale derived from single-particle measurements and in situ techniques in proton-proton collisions at 13 TeV with the ATLAS detector, (2024), arXiv:2407.15627 [hep-ex] .
- [30] G. Grosso, Anomaly-aware summary statistic from data batches, JHEP 12, 093, arXiv:2407.01249 [hep-ex] .
- [31] R. Jiang, P. Y. Lu, and R. Willett, Embed and emulate: Contrastive representations for simulation-based inference, arXiv preprint arXiv:2409.18402 (2024).
- [32] G. Cowan, K. Cranmer, E. Gross, and O. Vitells, Asymptotic formulae for likelihood-based tests of new physics, Eur. Phys. J. C 71, 1554 (2011), [Erratum: Eur.Phys.J.C 73, 2501 (2013)], arXiv:1007.1727 [physics.data-an] .
*