Papers
Topics
Authors
Recent
Search
2000 character limit reached

Weighted Contrastive Adaptation (WECA)

Updated 15 December 2025
  • Weighted Contrastive Adaptation (WECA) is an anomaly-aware training algorithm for time-series forecasting that balances invariance to benign perturbations with preservation of anomaly-specific features.
  • It employs a weighted InfoNCE contrastive loss where similarity weights, derived from input perturbation magnitudes, modulate the alignment between normal and anomaly-augmented samples.
  • Applications include enhanced forecasting robustness for ATM cash logistics, demonstrating significant SMAPE improvements on anomalous data while maintaining near-optimal performance on normal conditions.

Weighted Contrastive Adaptation (WECA) is a training algorithm for multivariate time-series forecasting that explicitly accounts for anomaly-awareness when learning representations, targeting improved performance under distribution shift scenarios without degrading accuracy on normal data. WECA introduces a weighted contrastive objective, interpolating between invariance to benign augmentations and the preservation of anomaly-specific information. Its principal application, as demonstrated in the context of nationwide ATM cash logistics, is to enhance forecaster robustness when encountering realistic, domain-informed anomaly events (Ekstrand et al., 8 Dec 2025).

1. Objective Formulation and Loss Derivation

WECA extends instance-wise contrastive learning (InfoNCE) for representations {zi,t}\{z_{i,t}\} of normal windows and {z~i,t}\{\tilde z_{i,t}\} of anomaly-augmented windows produced by an encoder gϕg_\phi. For each window ii and time tt, a similarity weight w(i,t)[0,1]w^{(i,t)} \in [0,1] scales the strength of alignment in the loss. The core weighted InfoNCE term is

WECA(i,t)=w(i,t)  logexp ⁣(zi,t,z~i,t/τ)j=1B[exp ⁣(zi,t,z~j,t/τ)+1jiexp ⁣(zi,t,zj,t/τ)],\ell_{\mathrm{WECA}}^{(i,t)} = -w^{(i,t)}\;\log \frac{\exp\!\bigl(\langle z_{i,t},\tilde z_{i,t}\rangle/\tau\bigr)} {\sum_{j=1}^B\left[\exp\!\bigl(\langle z_{i,t},\tilde z_{j,t}\rangle/\tau\bigr) + \mathbb{1}_{j\neq i} \exp\!\bigl(\langle z_{i,t},z_{j,t}\rangle/\tau\bigr) \right]},

where ,\langle\cdot,\cdot\rangle denotes the dot-product. The full batch loss combines the contrastive term and a mean absolute error (MAE) forecast loss with balance coefficient λ\lambda: L=1Bi=1BLforecast(i)+λ1BTi=1Bt=1TWECA(i,t),\mathcal{L} = \frac{1}{B}\sum_{i=1}^B \mathcal{L}_{\mathrm{forecast}}^{(i)} + \lambda \frac{1}{BT'} \sum_{i=1}^B \sum_{t=1}^{T'} \ell_{\mathrm{WECA}}^{(i,t)}, where

{z~i,t}\{\tilde z_{i,t}\}0

with decoder {z~i,t}\{\tilde z_{i,t}\}1, forecast targets {z~i,t}\{\tilde z_{i,t}\}2, and per-timestep outputs {z~i,t}\{\tilde z_{i,t}\}3.

2. Contrastive Pairing and Anomaly Augmentation

The contrastive setup defines, for each sample {z~i,t}\{\tilde z_{i,t}\}4 at position {z~i,t}\{\tilde z_{i,t}\}5, a positive pair {z~i,t}\{\tilde z_{i,t}\}6 and negative pairs both as {z~i,t}\{\tilde z_{i,t}\}7 for all {z~i,t}\{\tilde z_{i,t}\}8 (augmented negatives), and {z~i,t}\{\tilde z_{i,t}\}9 (other normal negatives). Anomaly-augmented samples are synthesized at the input level: for each gϕg_\phi0, the last window positions (tail) are perturbed using an anomaly function gϕg_\phi1, where gϕg_\phi2 are stochastically sampled to mimic historically observed anomaly statistics (e.g. gϕg_\phi3, gϕg_\phi4, gϕg_\phi5). The generated anomaly gϕg_\phi6 is injected into the tail of gϕg_\phi7 and propagated into the forecast horizon, yielding gϕg_\phi8.

3. Weight Function Design and Principle

The weight gϕg_\phi9 is a continuous function of the input-level perturbation magnitude, typically of the form ii0, with ii1 chosen so domain-plausible (benign) variations yield ii2 (strong invariance imposed), while major anomaly-like deviations yield ii3 (weak or no invariance). This soft weighting causes the encoder to enforce invariance only for small (non-anomalous) perturbations, while explicitly retaining anomaly-specific features otherwise. Consequently, WECA can interpolate between pure contrastive learning (full invariance) and no contrastive adaptation, preserving anomaly detectability while improving normal operational robustness.

4. Training Protocol and Network Architecture

The WECA training loop proceeds as follows:

tt5

The backbone architecture is TimesNet, which achieves optimal symmetric mean absolute percentage error (SMAPE) on normal data. The contrastive head projects encoded features to a ii4-dimensional space for dot-product similarity.

5. Hyperparameter Selection and Weighting Strategy

Selected hyperparameters:

  • Learning rate: ii5 (Adam optimizer)
  • Batch size: ii6
  • Contrastive weight ii7: ii8 (tuned via validation)
  • InfoNCE temperature ii9: usually tt0 or absorbed into dot product scaling
  • Weighting function parameter tt1: tuned so that small (domain-plausible) perturbations produce tt2 and large-scale anomalies tt3
  • Early stopping: monitored on validation MAE

Editor's term: "Dynamic similarity weighting" refers to the weighting mechanism for anchoring contrastive invariance according to anomaly severity.

6. Empirical Evaluation and Performance

The primary empirical benchmark uses approximately 1,300 ATMs' daily withdrawal data over two years, with a rolling-origin 70/10/20 training/validation/test split. Anomaly-augmented data is generated using the described injection procedure.

Evaluation metric: SMAPE (%) on a 14-day forecast horizon.

Performance summary:

Method Normal Data (ND) SMAPE ± std Δ vs NT Anomaly Data (AD) SMAPE ± std Δ vs NT
NT 28.73 37.91
FT 31.50±0.87 +2.77 30.69±2.03 −7.22
CL-IL 28.62±0.97 −0.11 33.09±0.96 −4.82
WECA 28.70±1.00 −0.03 31.78±1.93 −6.13

WECA achieves a 6.13 percentage point reduction in SMAPE on anomaly-affected test data compared to the normally trained baseline (NT), while only marginally affecting normal-data performance (0.03 pp difference). Instance-level contrastive learning (CL-IL) offers some anomaly robustness but with weaker margins; fine-tuning on anomaly-only data (FT) yields the largest anomaly gain but with a significant loss on normal data, consistent with catastrophic forgetting (Ekstrand et al., 8 Dec 2025).

7. Implementation and Applicability Considerations

  • The anomaly injection process is fully reproducible with fixed random seeds and parameter distributions.
  • WECA approximately doubles encoder passes per batch (normal + augmented), but the total computational overhead remains under 20% of standard GPU training time.
  • The similarity weight tt4 can be adapted to rely on alternative distance metrics or learned heuristics.
  • WECA is compatible with any deep forecaster architecture that exposes intermediate latent representations; no property is exclusive to TimesNet.
  • Training is most stable when the forecasting backbone is pre-trained on normal data and then fine-tuned with the WECA joint objective.
  • The method requires access to domain knowledge or distributions for realistic anomaly magnitude modeling, especially for applications like cash logistics where external events influence future behavior.

By calibrating the trade-off between invariance and anomaly awareness, WECA provides reliable forecasting resilience across severe real-world distribution shifts without compromising peacetime operational accuracy (Ekstrand et al., 8 Dec 2025).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Weighted Contrastive Adaptation (WECA).