pdmlabs.energy.drift#

Distribution shift, for the effective-payback correction.

E-LQOโ€™s Eq. 14 states EPT_eff ~= EPT / rho^2, where rho is the similarity between the training and deployment distributions. The dependence is quadratic because shift degrades both the per-cycle saving and the accuracy of the predictions producing it.

The paper supplies the correction but not a way to measure rho. This module provides two estimators, because they answer different questions and can disagree informatively:

  • distribution_similarity() โ€“ a covariate measure computed from the feature distributions alone. Available before any model is trained, and independent of how well the model happens to do.

  • performance_similarity() โ€“ an outcome measure: how much of the training-split quality survives on the deployment split. Directly reflects what shift costs, but conflates shift with ordinary generalisation gap.

Drift matters more in predictive maintenance than in query workloads: sensors age, equipment is replaced, and operating regimes change seasonally, so a model tuned on one period routinely meets a different one.

Functions

distribution_similarity(train_dfs,ย test_dfs)

Covariate similarity in [0, 1] via mean histogram intersection.

effective_payback(ept_value,ย rho)

EPT_eff = ceil(EPT / rho^2) with the inputs echoed back.

performance_similarity(q_train,ย q_test[,ย ...])

Outcome similarity: the fraction of tuned quality that survives deployment.

pdmlabs.energy.drift.distribution_similarity(train_dfs, test_dfs, bins=30, columns=None)#

Covariate similarity in [0, 1] via mean histogram intersection.

For each numeric feature, both splits are histogrammed over a shared range and normalised to densities; their intersection (sum(min(p, q))) is the per-feature similarity, and the mean across features is rho.

Histogram intersection rather than a distance: it is bounded in [0, 1] by construction, which is what Eq. 14 requires, needs no scale calibration, and degrades gracefully. An unbounded distance would have to be squashed by some arbitrary transform to be usable as rho.

Returns {'rho', 'per_feature', 'n_features'}.

pdmlabs.energy.drift.effective_payback(ept_value, rho)#

EPT_eff = ceil(EPT / rho^2) with the inputs echoed back.

Thin wrapper over pdmlabs.energy.metrics.ept_effective() that keeps rho and the inflation factor alongside the result, so a reported EPT_eff always carries the assumption that produced it.

pdmlabs.energy.drift.performance_similarity(q_train, q_test, maximize=True)#

Outcome similarity: the fraction of tuned quality that survives deployment.

Clipped to (0, 1]. Values above 1 (the deployment split scoring better than the tuning split) are clipped to 1 rather than reported as โ€œbetter than no shiftโ€: Eq. 14 has no meaning for rho > 1, and the honest reading is simply that no degradation was observed.