{
 "cells": [
  {
   "id": "cell-00",
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "# In-Situ Warehouse Modeling, Automated Pipelines, and Distributional Drift\n",
    "**Part IV: The Flight Disruption Binary Classifier Series**\n",
    "\n",
    "**Authoring standard:** *Hidden Technical Debt in Machine Learning Systems* (Sculley et al.)  \n",
    "**Setting:** Hartsfield-Jackson Atlanta International Airport (ATL)  \n",
    "**Case linkage:** `HS-OPS-09` · the sensor tinkerer (Edge Ingestion & BLE Privacy)  \n",
    "**Operational Objective:** Detect non-stationary covariate shift via Population Stability Index (PSI) and establish automated retraining boundaries in BigQuery ML and Vertex AI.\n",
    "\n",
    "### Mathematical Formulation\n",
    "Let $P(X)$ be the reference training distribution and $Q(X)$ be the empirical serving distribution observed across operational window $W$.\n",
    "The symmetric Population Stability Index (PSI) partitioned over $B$ quantile bins is:\n",
    "\n",
    "$$\\text{PSI} = \\sum_{b=1}^B (q_b - p_b) \\ln\\left(\\frac{q_b}{p_b}\\right)$$\n",
    "\n",
    "where $p_b$ is the reference proportion in bin $b$, and $q_b$ is the serving proportion.\n",
    "Operational decision policy:\n",
    "* $\\text{PSI} < 0.10$: Distribution stable; no action.\n",
    "* $0.10 \\le \\text{PSI} < 0.25$: Marginal shift; queue diagnostic pipeline.\n",
    "* $\\text{PSI} \\ge 0.25$: Significant covariate shift; trigger automated retraining DAG.\n"
   ]
  },
  {
   "id": "cell-01",
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## Prerequisites and support\n",
    "\n",
    "The saved environment reports Python 3.12.12. For the public download, use an isolated Python environment with JupyterLab and NumPy, Matplotlib, IPython. These are package prerequisites, not a locked or newly tested environment. The Python examples generate their own teaching data and do not require cloud credentials or a pretrained model.\n",
    "\n",
    "The public download omits the site-only `mementropy.mplstyle` setup cell; use Matplotlib's default style. No style file or environment lock is bundled. The cloud, SQL and deployment discussion is explanatory material, not evidence that a service was deployed by this notebook. If a rerun differs, record package versions and compare to the saved outputs rather than treating them as a guaranteed result.\n",
    "\n",
    "**Evidence:** these are saved outputs from an earlier execution, not rerun for the 2026-10-29 editorial update. Rendering displays saved cells; it does not execute them. The public download is not a locked environment or a production validation.\n"
   ]
  },
  {
   "id": "cell-02",
   "metadata": {},
   "cell_type": "code",
   "execution_count": 2,
   "source": [
    "import math\n",
    "import sys\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from IPython.display import display, Markdown, JSON\n",
    "\n",
    "SEED = 42\n",
    "np.random.seed(SEED)\n",
    "print({'python': sys.version.split()[0], 'seed': SEED, 'module': '04-pipeline-and-drift'})\n"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'python': '3.12.12', 'seed': 42, 'module': '04-pipeline-and-drift'}\n"
     ]
    }
   ]
  },
  {
   "id": "cell-03",
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## Baseline vs Non-Stationary Serving Distribution\n",
    "We simulate $N=2,000$ baseline training records and 8 consecutive weekly serving windows ($N_w = 500$ each).\n",
    "Between Week 4 and Week 8, a seasonal weather transition modifies the distribution of convective storms and flight transit times.\n"
   ]
  },
  {
   "id": "cell-04",
   "metadata": {},
   "cell_type": "code",
   "execution_count": 3,
   "source": [
    "N_BASE = 2000\n",
    "N_WINDOW = 500\n",
    "NUM_WINDOWS = 8\n",
    "\n",
    "# Baseline training distribution\n",
    "baseline_weather = np.random.gamma(shape=2.0, scale=1.5, size=N_BASE)\n",
    "\n",
    "# Serving windows with progressive drift starting at window 4\n",
    "serving_windows = []\n",
    "for w in range(NUM_WINDOWS):\n",
    "    drift_factor = max(0.0, (w - 3) * 0.4)\n",
    "    # Mean shifts rightward, variance expands\n",
    "    w_data = np.random.gamma(shape=2.0 + drift_factor, scale=1.5 + drift_factor * 0.3, size=N_WINDOW)\n",
    "    serving_windows.append(w_data)\n",
    "\n",
    "print({\n",
    "    'baseline_records': N_BASE,\n",
    "    'monitoring_windows': NUM_WINDOWS,\n",
    "    'window_size': N_WINDOW\n",
    "})\n"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'baseline_records': 2000, 'monitoring_windows': 8, 'window_size': 500}\n"
     ]
    }
   ]
  },
  {
   "id": "cell-05",
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## Implementation: Population Stability Index Calculator\n",
    "We compute PSI across 10 empirical quantile bins established on the baseline dataset.\n",
    "\n",
    "### Student Exercise (Stub)\n",
    "Review `compute_psi`. Verify that zero-count buckets are handled via Laplace smoothing ($\\epsilon = 10^{-4}$) to prevent numerical divergence.\n"
   ]
  },
  {
   "id": "cell-06",
   "metadata": {},
   "cell_type": "code",
   "execution_count": 4,
   "source": [
    "def compute_psi(reference, target, num_bins=10, epsilon=1e-4):\n",
    "    \"\"\"Compute Population Stability Index (PSI) between two empirical distributions.\"\"\"\n",
    "    # Quantile bins derived strictly from reference distribution\n",
    "    quantiles = np.linspace(0, 100, num_bins + 1)\n",
    "    bin_edges = np.percentile(reference, quantiles)\n",
    "    bin_edges[0] = -np.inf\n",
    "    bin_edges[-1] = np.inf\n",
    "    \n",
    "    # Bucket counts\n",
    "    ref_counts = np.histogram(reference, bins=bin_edges)[0]\n",
    "    tgt_counts = np.histogram(target, bins=bin_edges)[0]\n",
    "    \n",
    "    # Proportions with Laplace smoothing\n",
    "    p = np.maximum(ref_counts / len(reference), epsilon)\n",
    "    q = np.maximum(tgt_counts / len(target), epsilon)\n",
    "    \n",
    "    # PSI sum\n",
    "    psi_value = np.sum((q - p) * np.log(q / p))\n",
    "    return float(psi_value)\n",
    "\n",
    "# Evaluate PSI trajectory over operational windows\n",
    "psi_series = [compute_psi(baseline_weather, w_data) for w_data in serving_windows]\n",
    "for w, val in enumerate(psi_series):\n",
    "    print(f\"Window {w+1} PSI: {val:.4f} ({'STABLE' if val < 0.1 else ('WARNING' if val < 0.25 else 'CRITICAL_DRIFT')})\")\n"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Window 1 PSI: 0.0183 (STABLE)\n",
      "Window 2 PSI: 0.0245 (STABLE)\n",
      "Window 3 PSI: 0.0091 (STABLE)\n",
      "Window 4 PSI: 0.0192 (STABLE)\n",
      "Window 5 PSI: 0.1427 (WARNING)\n",
      "Window 6 PSI: 0.6782 (CRITICAL_DRIFT)\n",
      "Window 7 PSI: 1.7507 (CRITICAL_DRIFT)\n",
      "Window 8 PSI: 2.0185 (CRITICAL_DRIFT)\n"
     ]
    }
   ]
  },
  {
   "id": "cell-07",
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## Distributional Drift Visualization\n",
    "We contrast the baseline density against Week 8 drifted density and plot the PSI alarm threshold.\n"
   ]
  },
  {
   "id": "cell-08",
   "metadata": {},
   "cell_type": "code",
   "execution_count": 5,
   "source": [
    "fig, ax = plt.subplots(1, 2, figsize=(12, 4))\n",
    "\n",
    "# Density comparison\n",
    "ax[0].hist(baseline_weather, bins=30, density=True, alpha=0.5, color='#1a7f64', label='Baseline P(X)')\n",
    "ax[0].hist(serving_windows[-1], bins=30, density=True, alpha=0.5, color='#cf222e', label='Window 8 Q(X)')\n",
    "ax[0].set(xlabel='Convective Severity Metric', ylabel='Density', title='Covariate Distribution Shift')\n",
    "ax[0].legend(); ax[0].grid(True, alpha=0.3)\n",
    "\n",
    "# PSI Trajectory\n",
    "ax[1].plot(range(1, NUM_WINDOWS + 1), psi_series, 'o-', color='#0969da', lw=2)\n",
    "ax[1].axhline(0.10, color='#b35900', linestyle='--', label='Warning (0.10)')\n",
    "ax[1].axhline(0.25, color='#cf222e', linestyle='--', label='Retrain Trigger (0.25)')\n",
    "ax[1].set(xlabel='Operational Window (Weeks)', ylabel='PSI', title='Population Stability Index Over Time')\n",
    "ax[1].legend(); ax[1].grid(True, alpha=0.3)\n",
    "\n",
    "plt.tight_layout(); plt.show()\n"
   ],
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"858.219141pt\" height=\"282.96pt\" viewBox=\"0 0 858.219141 282.96\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n",
       " <metadata>\n",
       "  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n",
       "   <cc:Work>\n",
       "    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n",
       "    <dc:date>2026-10-06T14:14:55.255174</dc:date>\n",
       "    <dc:format>image/svg+xml</dc:format>\n",
       "    <dc:creator>\n",
       "     <cc:Agent>\n",
       "      <dc:title>Matplotlib v3.11.2, https://matplotlib.org/</dc:title>\n",
       "     </cc:Agent>\n",
       "    </dc:creator>\n",
       "   </cc:Work>\n",
       "  </rdf:RDF>\n",
       " </metadata>\n",
       " <defs>\n",
       "  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 282.96 \n",
       "L 858.219141 282.96 \n",
       "L 858.219141 0 \n",
       "L 0 0 \n",
       "L 0 282.96 \n",
       "z\n",
       "\" style=\"fill: none\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path d=\"M 46.224141 243.3725 \n",
       "L 423.879141 243.3725 \n",
       "L 423.879141 29.925 \n",
       "L 46.224141 29.925 \n",
       "L 46.224141 243.3725 \n",
       "z\n",
       "\" style=\"fill: none\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\">\n",
       "    <g id=\"xtick_1\">\n",
       "     <g id=\"line2d_1\">\n",
       "      <path d=\"M 62.799055 243.3725 \n",
       "L 62.799055 29.925 \n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_2\"/>\n",
       "     <g id=\"text_1\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: middle; fill: #6f706a\" x=\"62.799055\" y=\"257.4645\" transform=\"rotate(-0 62.799055 257.4645)\">0</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_2\">\n",
       "     <g id=\"line2d_3\">\n",
       "      <path d=\"M 139.005696 243.3725 \n",
       "L 139.005696 29.925 \n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_4\"/>\n",
       "     <g id=\"text_2\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: middle; fill: #6f706a\" x=\"139.005696\" y=\"257.4645\" transform=\"rotate(-0 139.005696 257.4645)\">5</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_3\">\n",
       "     <g id=\"line2d_5\">\n",
       "      <path d=\"M 215.212337 243.3725 \n",
       "L 215.212337 29.925 \n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_6\"/>\n",
       "     <g id=\"text_3\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: middle; fill: #6f706a\" x=\"215.212337\" y=\"257.4645\" transform=\"rotate(-0 215.212337 257.4645)\">10</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_4\">\n",
       "     <g id=\"line2d_7\">\n",
       "      <path d=\"M 291.418978 243.3725 \n",
       "L 291.418978 29.925 \n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_8\"/>\n",
       "     <g id=\"text_4\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: middle; fill: #6f706a\" x=\"291.418978\" y=\"257.4645\" transform=\"rotate(-0 291.418978 257.4645)\">15</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_5\">\n",
       "     <g id=\"line2d_9\">\n",
       "      <path d=\"M 367.625619 243.3725 \n",
       "L 367.625619 29.925 \n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_10\"/>\n",
       "     <g id=\"text_5\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: middle; fill: #6f706a\" x=\"367.625619\" y=\"257.4645\" transform=\"rotate(-0 367.625619 257.4645)\">20</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_6\">\n",
       "     <text style=\"font-size: 9px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: middle; fill: #484945\" x=\"235.051641\" y=\"273.843\" transform=\"rotate(-0 235.051641 273.843)\">Convective Severity Metric</text>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_2\">\n",
       "    <g id=\"ytick_1\">\n",
       "     <g id=\"line2d_11\">\n",
       "      <path d=\"M 46.224141 243.3725 \n",
       "L 423.879141 243.3725 \n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_12\"/>\n",
       "     <g id=\"text_7\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: end; fill: #6f706a\" x=\"40.224141\" y=\"247.4185\" transform=\"rotate(-0 40.224141 247.4185)\">0.00</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_2\">\n",
       "     <g id=\"line2d_13\">\n",
       "      <path d=\"M 46.224141 199.816089 \n",
       "L 423.879141 199.816089 \n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_14\"/>\n",
       "     <g id=\"text_8\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: end; fill: #6f706a\" x=\"40.224141\" y=\"203.862089\" transform=\"rotate(-0 40.224141 203.862089)\">0.05</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_3\">\n",
       "     <g id=\"line2d_15\">\n",
       "      <path d=\"M 46.224141 156.259678 \n",
       "L 423.879141 156.259678 \n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_16\"/>\n",
       "     <g id=\"text_9\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: end; fill: #6f706a\" x=\"40.224141\" y=\"160.305678\" transform=\"rotate(-0 40.224141 160.305678)\">0.10</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_4\">\n",
       "     <g id=\"line2d_17\">\n",
       "      <path d=\"M 46.224141 112.703267 \n",
       "L 423.879141 112.703267 \n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_18\"/>\n",
       "     <g id=\"text_10\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: end; fill: #6f706a\" x=\"40.224141\" y=\"116.749267\" transform=\"rotate(-0 40.224141 116.749267)\">0.15</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_5\">\n",
       "     <g id=\"line2d_19\">\n",
       "      <path d=\"M 46.224141 69.146856 \n",
       "L 423.879141 69.146856 \n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_20\"/>\n",
       "     <g id=\"text_11\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: end; fill: #6f706a\" x=\"40.224141\" y=\"73.192856\" transform=\"rotate(-0 40.224141 73.192856)\">0.20</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_12\">\n",
       "     <text style=\"font-size: 9px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: middle; fill: #484945\" x=\"15.768\" y=\"136.64875\" transform=\"rotate(-90 15.768 136.64875)\">Density</text>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path d=\"M 63.390277 243.3725 \n",
       "L 73.742471 243.3725 \n",
       "L 73.742471 145.257831 \n",
       "L 63.390277 145.257831 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path d=\"M 73.742471 243.3725 \n",
       "L 84.094665 243.3725 \n",
       "L 84.094665 54.197158 \n",
       "L 73.742471 54.197158 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path d=\"M 84.094665 243.3725 \n",
       "L 94.446858 243.3725 \n",
       "L 94.446858 40.089167 \n",
       "L 84.094665 40.089167 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path d=\"M 94.446858 243.3725 \n",
       "L 104.799052 243.3725 \n",
       "L 104.799052 50.990797 \n",
       "L 94.446858 50.990797 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path d=\"M 104.799052 243.3725 \n",
       "L 115.151246 243.3725 \n",
       "L 115.151246 86.902048 \n",
       "L 104.799052 86.902048 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path d=\"M 115.151246 243.3725 \n",
       "L 125.50344 243.3725 \n",
       "L 125.50344 108.705308 \n",
       "L 115.151246 108.705308 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path d=\"M 125.50344 243.3725 \n",
       "L 135.855633 243.3725 \n",
       "L 135.855633 163.213457 \n",
       "L 125.50344 163.213457 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path d=\"M 135.855633 243.3725 \n",
       "L 146.207827 243.3725 \n",
       "L 146.207827 184.375444 \n",
       "L 135.855633 184.375444 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_11\">\n",
       "    <path d=\"M 146.207827 243.3725 \n",
       "L 156.560021 243.3725 \n",
       "L 156.560021 199.765981 \n",
       "L 146.207827 199.765981 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_12\">\n",
       "    <path d=\"M 156.560021 243.3725 \n",
       "L 166.912215 243.3725 \n",
       "L 166.912215 206.178704 \n",
       "L 156.560021 206.178704 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_13\">\n",
       "    <path d=\"M 166.912215 243.3725 \n",
       "L 177.264408 243.3725 \n",
       "L 177.264408 210.66761 \n",
       "L 166.912215 210.66761 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_14\">\n",
       "    <path d=\"M 177.264408 243.3725 \n",
       "L 187.616602 243.3725 \n",
       "L 187.616602 222.851785 \n",
       "L 177.264408 222.851785 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_15\">\n",
       "    <path d=\"M 187.616602 243.3725 \n",
       "L 197.968796 243.3725 \n",
       "L 197.968796 232.47087 \n",
       "L 187.616602 232.47087 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_16\">\n",
       "    <path d=\"M 197.968796 243.3725 \n",
       "L 208.32099 243.3725 \n",
       "L 208.32099 232.47087 \n",
       "L 197.968796 232.47087 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_17\">\n",
       "    <path d=\"M 208.32099 243.3725 \n",
       "L 218.673183 243.3725 \n",
       "L 218.673183 238.883594 \n",
       "L 208.32099 238.883594 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_18\">\n",
       "    <path d=\"M 218.673183 243.3725 \n",
       "L 229.025377 243.3725 \n",
       "L 229.025377 240.807411 \n",
       "L 218.673183 240.807411 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_19\">\n",
       "    <path d=\"M 229.025377 243.3725 \n",
       "L 239.377571 243.3725 \n",
       "L 239.377571 239.524866 \n",
       "L 229.025377 239.524866 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_20\">\n",
       "    <path d=\"M 239.377571 243.3725 \n",
       "L 249.729765 243.3725 \n",
       "L 249.729765 242.089955 \n",
       "L 239.377571 242.089955 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_21\">\n",
       "    <path d=\"M 249.729765 243.3725 \n",
       "L 260.081959 243.3725 \n",
       "L 260.081959 243.3725 \n",
       "L 249.729765 243.3725 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_22\">\n",
       "    <path d=\"M 260.081959 243.3725 \n",
       "L 270.434152 243.3725 \n",
       "L 270.434152 243.3725 \n",
       "L 260.081959 243.3725 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_23\">\n",
       "    <path d=\"M 270.434152 243.3725 \n",
       "L 280.786346 243.3725 \n",
       "L 280.786346 242.731228 \n",
       "L 270.434152 242.731228 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_24\">\n",
       "    <path d=\"M 280.786346 243.3725 \n",
       "L 291.13854 243.3725 \n",
       "L 291.13854 243.3725 \n",
       "L 280.786346 243.3725 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_25\">\n",
       "    <path d=\"M 291.13854 243.3725 \n",
       "L 301.490734 243.3725 \n",
       "L 301.490734 243.3725 \n",
       "L 291.13854 243.3725 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_26\">\n",
       "    <path d=\"M 301.490734 243.3725 \n",
       "L 311.842927 243.3725 \n",
       "L 311.842927 243.3725 \n",
       "L 301.490734 243.3725 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_27\">\n",
       "    <path d=\"M 311.842927 243.3725 \n",
       "L 322.195121 243.3725 \n",
       "L 322.195121 243.3725 \n",
       "L 311.842927 243.3725 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_28\">\n",
       "    <path d=\"M 322.195121 243.3725 \n",
       "L 332.547315 243.3725 \n",
       "L 332.547315 243.3725 \n",
       "L 322.195121 243.3725 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_29\">\n",
       "    <path d=\"M 332.547315 243.3725 \n",
       "L 342.899509 243.3725 \n",
       "L 342.899509 243.3725 \n",
       "L 332.547315 243.3725 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_30\">\n",
       "    <path d=\"M 342.899509 243.3725 \n",
       "L 353.251702 243.3725 \n",
       "L 353.251702 243.3725 \n",
       "L 342.899509 243.3725 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_31\">\n",
       "    <path d=\"M 353.251702 243.3725 \n",
       "L 363.603896 243.3725 \n",
       "L 363.603896 243.3725 \n",
       "L 353.251702 243.3725 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_32\">\n",
       "    <path d=\"M 363.603896 243.3725 \n",
       "L 373.95609 243.3725 \n",
       "L 373.95609 242.731228 \n",
       "L 363.603896 242.731228 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_33\">\n",
       "    <path d=\"M 74.967336 243.3725 \n",
       "L 86.025525 243.3725 \n",
       "L 86.025525 224.161902 \n",
       "L 74.967336 224.161902 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_34\">\n",
       "    <path d=\"M 86.025525 243.3725 \n",
       "L 97.083714 243.3725 \n",
       "L 97.083714 214.556604 \n",
       "L 86.025525 214.556604 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_35\">\n",
       "    <path d=\"M 97.083714 243.3725 \n",
       "L 108.141903 243.3725 \n",
       "L 108.141903 195.346006 \n",
       "L 97.083714 195.346006 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_36\">\n",
       "    <path d=\"M 108.141903 243.3725 \n",
       "L 119.200092 243.3725 \n",
       "L 119.200092 166.53011 \n",
       "L 108.141903 166.53011 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_37\">\n",
       "    <path d=\"M 119.200092 243.3725 \n",
       "L 130.258281 243.3725 \n",
       "L 130.258281 118.503615 \n",
       "L 119.200092 118.503615 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_38\">\n",
       "    <path d=\"M 130.258281 243.3725 \n",
       "L 141.316469 243.3725 \n",
       "L 141.316469 125.70759 \n",
       "L 130.258281 125.70759 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_39\">\n",
       "    <path d=\"M 141.316469 243.3725 \n",
       "L 152.374658 243.3725 \n",
       "L 152.374658 116.102291 \n",
       "L 141.316469 116.102291 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_40\">\n",
       "    <path d=\"M 152.374658 243.3725 \n",
       "L 163.432847 243.3725 \n",
       "L 163.432847 147.319512 \n",
       "L 152.374658 147.319512 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_41\">\n",
       "    <path d=\"M 163.432847 243.3725 \n",
       "L 174.491036 243.3725 \n",
       "L 174.491036 140.115538 \n",
       "L 163.432847 140.115538 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_42\">\n",
       "    <path d=\"M 174.491036 243.3725 \n",
       "L 185.549225 243.3725 \n",
       "L 185.549225 185.740707 \n",
       "L 174.491036 185.740707 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_43\">\n",
       "    <path d=\"M 185.549225 243.3725 \n",
       "L 196.607414 243.3725 \n",
       "L 196.607414 168.931434 \n",
       "L 185.549225 168.931434 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_44\">\n",
       "    <path d=\"M 196.607414 243.3725 \n",
       "L 207.665603 243.3725 \n",
       "L 207.665603 185.740707 \n",
       "L 196.607414 185.740707 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_45\">\n",
       "    <path d=\"M 207.665603 243.3725 \n",
       "L 218.723792 243.3725 \n",
       "L 218.723792 202.54998 \n",
       "L 207.665603 202.54998 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_46\">\n",
       "    <path d=\"M 218.723792 243.3725 \n",
       "L 229.781981 243.3725 \n",
       "L 229.781981 204.951305 \n",
       "L 218.723792 204.951305 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_47\">\n",
       "    <path d=\"M 229.781981 243.3725 \n",
       "L 240.84017 243.3725 \n",
       "L 240.84017 197.747331 \n",
       "L 229.781981 197.747331 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_48\">\n",
       "    <path d=\"M 240.84017 243.3725 \n",
       "L 251.898359 243.3725 \n",
       "L 251.898359 200.148655 \n",
       "L 240.84017 200.148655 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_49\">\n",
       "    <path d=\"M 251.898359 243.3725 \n",
       "L 262.956548 243.3725 \n",
       "L 262.956548 224.161902 \n",
       "L 251.898359 224.161902 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_50\">\n",
       "    <path d=\"M 262.956548 243.3725 \n",
       "L 274.014737 243.3725 \n",
       "L 274.014737 221.760578 \n",
       "L 262.956548 221.760578 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_51\">\n",
       "    <path d=\"M 274.014737 243.3725 \n",
       "L 285.072926 243.3725 \n",
       "L 285.072926 226.563227 \n",
       "L 274.014737 226.563227 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_52\">\n",
       "    <path d=\"M 285.072926 243.3725 \n",
       "L 296.131115 243.3725 \n",
       "L 296.131115 233.767201 \n",
       "L 285.072926 233.767201 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_53\">\n",
       "    <path d=\"M 296.131115 243.3725 \n",
       "L 307.189304 243.3725 \n",
       "L 307.189304 231.365876 \n",
       "L 296.131115 231.365876 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_54\">\n",
       "    <path d=\"M 307.189304 243.3725 \n",
       "L 318.247493 243.3725 \n",
       "L 318.247493 238.569851 \n",
       "L 307.189304 238.569851 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_55\">\n",
       "    <path d=\"M 318.247493 243.3725 \n",
       "L 329.305682 243.3725 \n",
       "L 329.305682 238.569851 \n",
       "L 318.247493 238.569851 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_56\">\n",
       "    <path d=\"M 329.305682 243.3725 \n",
       "L 340.363871 243.3725 \n",
       "L 340.363871 243.3725 \n",
       "L 329.305682 243.3725 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_57\">\n",
       "    <path d=\"M 340.363871 243.3725 \n",
       "L 351.42206 243.3725 \n",
       "L 351.42206 240.971175 \n",
       "L 340.363871 240.971175 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_58\">\n",
       "    <path d=\"M 351.42206 243.3725 \n",
       "L 362.480248 243.3725 \n",
       "L 362.480248 240.971175 \n",
       "L 351.42206 240.971175 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_59\">\n",
       "    <path d=\"M 362.480248 243.3725 \n",
       "L 373.538437 243.3725 \n",
       "L 373.538437 243.3725 \n",
       "L 362.480248 243.3725 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_60\">\n",
       "    <path d=\"M 373.538437 243.3725 \n",
       "L 384.596626 243.3725 \n",
       "L 384.596626 240.971175 \n",
       "L 373.538437 240.971175 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_61\">\n",
       "    <path d=\"M 384.596626 243.3725 \n",
       "L 395.654815 243.3725 \n",
       "L 395.654815 240.971175 \n",
       "L 384.596626 240.971175 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_62\">\n",
       "    <path d=\"M 395.654815 243.3725 \n",
       "L 406.713004 243.3725 \n",
       "L 406.713004 240.971175 \n",
       "L 395.654815 240.971175 \n",
       "z\n",
       "\" clip-path=\"url(#pbacb44981b)\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_63\">\n",
       "    <path d=\"M 46.224141 243.3725 \n",
       "L 46.224141 29.925 \n",
       "\" style=\"fill: none; stroke: #d1d2cb; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_64\">\n",
       "    <path d=\"M 46.224141 243.3725 \n",
       "L 423.879141 243.3725 \n",
       "\" style=\"fill: none; stroke: #d1d2cb; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"text_13\">\n",
       "    <text style=\"font-weight: 600; font-size: 11px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: start; fill: #171817\" x=\"46.224141\" y=\"17.925\" transform=\"rotate(-0 46.224141 17.925)\">Covariate Distribution Shift</text>\n",
       "   </g>\n",
       "   <g id=\"legend_1\">\n",
       "    <g id=\"patch_65\">\n",
       "     <path d=\"M 336.075469 45.667 \n",
       "L 353.075469 45.667 \n",
       "L 353.075469 39.717 \n",
       "L 336.075469 39.717 \n",
       "z\n",
       "\" style=\"fill: #1a7f64; opacity: 0.5\"/>\n",
       "    </g>\n",
       "    <g id=\"text_14\">\n",
       "     <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: start; fill: #484945\" x=\"359.875469\" y=\"45.667\" transform=\"rotate(-0 359.875469 45.667)\">Baseline P(X)</text>\n",
       "    </g>\n",
       "    <g id=\"patch_66\">\n",
       "     <path d=\"M 336.075469 59.8195 \n",
       "L 353.075469 59.8195 \n",
       "L 353.075469 53.8695 \n",
       "L 336.075469 53.8695 \n",
       "z\n",
       "\" style=\"fill: #cf222e; opacity: 0.5\"/>\n",
       "    </g>\n",
       "    <g id=\"text_15\">\n",
       "     <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: start; fill: #484945\" x=\"359.875469\" y=\"59.8195\" transform=\"rotate(-0 359.875469 59.8195)\">Window 8 Q(X)</text>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       "  <g id=\"axes_2\">\n",
       "   <g id=\"patch_67\">\n",
       "    <path d=\"M 473.364141 243.3725 \n",
       "L 851.019141 243.3725 \n",
       "L 851.019141 29.925 \n",
       "L 473.364141 29.925 \n",
       "L 473.364141 243.3725 \n",
       "z\n",
       "\" style=\"fill: none\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_3\">\n",
       "    <g id=\"xtick_6\">\n",
       "     <g id=\"line2d_21\">\n",
       "      <path d=\"M 490.530277 243.3725 \n",
       "L 490.530277 29.925 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_22\"/>\n",
       "     <g id=\"text_16\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: middle; fill: #6f706a\" x=\"490.530277\" y=\"257.4645\" transform=\"rotate(-0 490.530277 257.4645)\">1</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_7\">\n",
       "     <g id=\"line2d_23\">\n",
       "      <path d=\"M 539.576381 243.3725 \n",
       "L 539.576381 29.925 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_24\"/>\n",
       "     <g id=\"text_17\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: middle; fill: #6f706a\" x=\"539.576381\" y=\"257.4645\" transform=\"rotate(-0 539.576381 257.4645)\">2</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_8\">\n",
       "     <g id=\"line2d_25\">\n",
       "      <path d=\"M 588.622485 243.3725 \n",
       "L 588.622485 29.925 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_26\"/>\n",
       "     <g id=\"text_18\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: middle; fill: #6f706a\" x=\"588.622485\" y=\"257.4645\" transform=\"rotate(-0 588.622485 257.4645)\">3</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_9\">\n",
       "     <g id=\"line2d_27\">\n",
       "      <path d=\"M 637.668589 243.3725 \n",
       "L 637.668589 29.925 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_28\"/>\n",
       "     <g id=\"text_19\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: middle; fill: #6f706a\" x=\"637.668589\" y=\"257.4645\" transform=\"rotate(-0 637.668589 257.4645)\">4</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_10\">\n",
       "     <g id=\"line2d_29\">\n",
       "      <path d=\"M 686.714693 243.3725 \n",
       "L 686.714693 29.925 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_30\"/>\n",
       "     <g id=\"text_20\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: middle; fill: #6f706a\" x=\"686.714693\" y=\"257.4645\" transform=\"rotate(-0 686.714693 257.4645)\">5</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_11\">\n",
       "     <g id=\"line2d_31\">\n",
       "      <path d=\"M 735.760796 243.3725 \n",
       "L 735.760796 29.925 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_32\"/>\n",
       "     <g id=\"text_21\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: middle; fill: #6f706a\" x=\"735.760796\" y=\"257.4645\" transform=\"rotate(-0 735.760796 257.4645)\">6</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_12\">\n",
       "     <g id=\"line2d_33\">\n",
       "      <path d=\"M 784.8069 243.3725 \n",
       "L 784.8069 29.925 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_34\"/>\n",
       "     <g id=\"text_22\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: middle; fill: #6f706a\" x=\"784.8069\" y=\"257.4645\" transform=\"rotate(-0 784.8069 257.4645)\">7</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_13\">\n",
       "     <g id=\"line2d_35\">\n",
       "      <path d=\"M 833.853004 243.3725 \n",
       "L 833.853004 29.925 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_36\"/>\n",
       "     <g id=\"text_23\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: middle; fill: #6f706a\" x=\"833.853004\" y=\"257.4645\" transform=\"rotate(-0 833.853004 257.4645)\">8</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_24\">\n",
       "     <text style=\"font-size: 9px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: middle; fill: #484945\" x=\"662.191641\" y=\"273.843\" transform=\"rotate(-0 662.191641 273.843)\">Operational Window (Weeks)</text>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_4\">\n",
       "    <g id=\"ytick_6\">\n",
       "     <g id=\"line2d_37\">\n",
       "      <path d=\"M 473.364141 234.545602 \n",
       "L 851.019141 234.545602 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_38\"/>\n",
       "     <g id=\"text_25\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: end; fill: #6f706a\" x=\"467.364141\" y=\"238.591602\" transform=\"rotate(-0 467.364141 238.591602)\">0.00</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_7\">\n",
       "     <g id=\"line2d_39\">\n",
       "      <path d=\"M 473.364141 210.403547 \n",
       "L 851.019141 210.403547 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_40\"/>\n",
       "     <g id=\"text_26\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: end; fill: #6f706a\" x=\"467.364141\" y=\"214.449547\" transform=\"rotate(-0 467.364141 214.449547)\">0.25</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_8\">\n",
       "     <g id=\"line2d_41\">\n",
       "      <path d=\"M 473.364141 186.261491 \n",
       "L 851.019141 186.261491 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_42\"/>\n",
       "     <g id=\"text_27\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: end; fill: #6f706a\" x=\"467.364141\" y=\"190.307491\" transform=\"rotate(-0 467.364141 190.307491)\">0.50</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_9\">\n",
       "     <g id=\"line2d_43\">\n",
       "      <path d=\"M 473.364141 162.119436 \n",
       "L 851.019141 162.119436 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_44\"/>\n",
       "     <g id=\"text_28\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: end; fill: #6f706a\" x=\"467.364141\" y=\"166.165436\" transform=\"rotate(-0 467.364141 166.165436)\">0.75</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_10\">\n",
       "     <g id=\"line2d_45\">\n",
       "      <path d=\"M 473.364141 137.97738 \n",
       "L 851.019141 137.97738 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_46\"/>\n",
       "     <g id=\"text_29\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: end; fill: #6f706a\" x=\"467.364141\" y=\"142.02338\" transform=\"rotate(-0 467.364141 142.02338)\">1.00</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_11\">\n",
       "     <g id=\"line2d_47\">\n",
       "      <path d=\"M 473.364141 113.835325 \n",
       "L 851.019141 113.835325 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_48\"/>\n",
       "     <g id=\"text_30\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: end; fill: #6f706a\" x=\"467.364141\" y=\"117.881325\" transform=\"rotate(-0 467.364141 117.881325)\">1.25</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_12\">\n",
       "     <g id=\"line2d_49\">\n",
       "      <path d=\"M 473.364141 89.693269 \n",
       "L 851.019141 89.693269 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_50\"/>\n",
       "     <g id=\"text_31\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: end; fill: #6f706a\" x=\"467.364141\" y=\"93.739269\" transform=\"rotate(-0 467.364141 93.739269)\">1.50</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_13\">\n",
       "     <g id=\"line2d_51\">\n",
       "      <path d=\"M 473.364141 65.551214 \n",
       "L 851.019141 65.551214 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_52\"/>\n",
       "     <g id=\"text_32\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: end; fill: #6f706a\" x=\"467.364141\" y=\"69.597214\" transform=\"rotate(-0 467.364141 69.597214)\">1.75</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_14\">\n",
       "     <g id=\"line2d_53\">\n",
       "      <path d=\"M 473.364141 41.409158 \n",
       "L 851.019141 41.409158 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke: #e3e4de; stroke-opacity: 0.3; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_54\"/>\n",
       "     <g id=\"text_33\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: end; fill: #6f706a\" x=\"467.364141\" y=\"45.455158\" transform=\"rotate(-0 467.364141 45.455158)\">2.00</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_34\">\n",
       "     <text style=\"font-size: 9px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: middle; fill: #484945\" x=\"442.908\" y=\"136.64875\" transform=\"rotate(-90 442.908 136.64875)\">PSI</text>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"line2d_55\">\n",
       "    <path d=\"M 490.530277 232.783179 \n",
       "L 539.576381 232.177501 \n",
       "L 588.622485 233.670341 \n",
       "L 637.668589 232.693983 \n",
       "L 686.714693 220.768005 \n",
       "L 735.760796 169.050839 \n",
       "L 784.8069 65.487206 \n",
       "L 833.853004 39.627159 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke: #0969da; stroke-width: 2; stroke-linecap: round\"/>\n",
       "    <defs>\n",
       "     <path id=\"mfd24055806\" d=\"M 0 3 \n",
       "C 0.795609 3 1.55874 2.683901 2.12132 2.12132 \n",
       "C 2.683901 1.55874 3 0.795609 3 0 \n",
       "C 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \n",
       "C 1.55874 -2.683901 0.795609 -3 0 -3 \n",
       "C -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \n",
       "C -2.683901 -1.55874 -3 -0.795609 -3 0 \n",
       "C -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \n",
       "C -1.55874 2.683901 -0.795609 3 0 3 \n",
       "z\n",
       "\" style=\"stroke: #0969da\"/>\n",
       "    </defs>\n",
       "    <g clip-path=\"url(#p86f09d73b3)\">\n",
       "     <use xlink:href=\"#mfd24055806\" x=\"490.530277\" y=\"232.783179\" style=\"fill: #0969da; stroke: #0969da\"/>\n",
       "     <use xlink:href=\"#mfd24055806\" x=\"539.576381\" y=\"232.177501\" style=\"fill: #0969da; stroke: #0969da\"/>\n",
       "     <use xlink:href=\"#mfd24055806\" x=\"588.622485\" y=\"233.670341\" style=\"fill: #0969da; stroke: #0969da\"/>\n",
       "     <use xlink:href=\"#mfd24055806\" x=\"637.668589\" y=\"232.693983\" style=\"fill: #0969da; stroke: #0969da\"/>\n",
       "     <use xlink:href=\"#mfd24055806\" x=\"686.714693\" y=\"220.768005\" style=\"fill: #0969da; stroke: #0969da\"/>\n",
       "     <use xlink:href=\"#mfd24055806\" x=\"735.760796\" y=\"169.050839\" style=\"fill: #0969da; stroke: #0969da\"/>\n",
       "     <use xlink:href=\"#mfd24055806\" x=\"784.8069\" y=\"65.487206\" style=\"fill: #0969da; stroke: #0969da\"/>\n",
       "     <use xlink:href=\"#mfd24055806\" x=\"833.853004\" y=\"39.627159\" style=\"fill: #0969da; stroke: #0969da\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"line2d_56\">\n",
       "    <path d=\"M 473.364141 224.88878 \n",
       "L 851.019141 224.88878 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke-dasharray: 6.66,2.88; stroke-dashoffset: 0; stroke: #b35900; stroke-width: 1.8\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_57\">\n",
       "    <path d=\"M 473.364141 210.403547 \n",
       "L 851.019141 210.403547 \n",
       "\" clip-path=\"url(#p86f09d73b3)\" style=\"fill: none; stroke-dasharray: 6.66,2.88; stroke-dashoffset: 0; stroke: #cf222e; stroke-width: 1.8\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_68\">\n",
       "    <path d=\"M 473.364141 243.3725 \n",
       "L 473.364141 29.925 \n",
       "\" style=\"fill: none; stroke: #d1d2cb; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_69\">\n",
       "    <path d=\"M 473.364141 243.3725 \n",
       "L 851.019141 243.3725 \n",
       "\" style=\"fill: none; stroke: #d1d2cb; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"text_35\">\n",
       "    <text style=\"font-weight: 600; font-size: 11px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: start; fill: #171817\" x=\"473.364141\" y=\"17.925\" transform=\"rotate(-0 473.364141 17.925)\">Population Stability Index Over Time</text>\n",
       "   </g>\n",
       "   <g id=\"legend_2\">\n",
       "    <g id=\"line2d_58\">\n",
       "     <path d=\"M 481.014141 42.692 \n",
       "L 489.514141 42.692 \n",
       "L 498.014141 42.692 \n",
       "\" style=\"fill: none; stroke-dasharray: 6.66,2.88; stroke-dashoffset: 0; stroke: #b35900; stroke-width: 1.8\"/>\n",
       "    </g>\n",
       "    <g id=\"text_36\">\n",
       "     <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: start; fill: #484945\" x=\"504.814141\" y=\"45.667\" transform=\"rotate(-0 504.814141 45.667)\">Warning (0.10)</text>\n",
       "    </g>\n",
       "    <g id=\"line2d_59\">\n",
       "     <path d=\"M 481.014141 56.8445 \n",
       "L 489.514141 56.8445 \n",
       "L 498.014141 56.8445 \n",
       "\" style=\"fill: none; stroke-dasharray: 6.66,2.88; stroke-dashoffset: 0; stroke: #cf222e; stroke-width: 1.8\"/>\n",
       "    </g>\n",
       "    <g id=\"text_37\">\n",
       "     <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: start; fill: #484945\" x=\"504.814141\" y=\"59.8195\" transform=\"rotate(-0 504.814141 59.8195)\">Retrain Trigger (0.25)</text>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pbacb44981b\">\n",
       "   <rect x=\"46.224141\" y=\"29.925\" width=\"377.655\" height=\"213.4475\"/>\n",
       "  </clipPath>\n",
       "  <clipPath id=\"p86f09d73b3\">\n",
       "   <rect x=\"473.364141\" y=\"29.925\" width=\"377.655\" height=\"213.4475\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<Figure size 1200x400 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ]
  },
  {
   "id": "cell-09",
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## Automated Retraining Boundary\n",
    "When $\\text{PSI} \\ge 0.25$, the monitoring engine issues an automated dispatch event triggering model retraining on Vertex AI Pipelines.\n"
   ]
  },
  {
   "id": "cell-10",
   "metadata": {},
   "cell_type": "code",
   "execution_count": 6,
   "source": [
    "trigger_window = next((w + 1 for w, psi in enumerate(psi_series) if psi >= 0.25), None)\n",
    "print(f\"Automated Pipeline Action: Retrain triggered at Window {trigger_window} (PSI = {psi_series[trigger_window-1]:.4f})\")\n"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Automated Pipeline Action: Retrain triggered at Window 6 (PSI = 0.6782)\n"
     ]
    }
   ]
  },
  {
   "id": "cell-11",
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## Method Invariant and Failure Probe\n",
    "Assert that identical distributions produce $\\text{PSI} \\approx 0$ within numerical tolerance.\n"
   ]
  },
  {
   "id": "cell-12",
   "metadata": {},
   "cell_type": "code",
   "execution_count": 7,
   "source": [
    "psi_zero = compute_psi(baseline_weather, baseline_weather)\n",
    "assert psi_zero < 0.001, f\"Self-PSI must be zero, got {psi_zero}\"\n",
    "print(f\"EXPECTED BEHAVIOR: Identity PSI = {psi_zero:.6f}\")\n"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "EXPECTED BEHAVIOR: Identity PSI = 0.000000\n"
     ]
    }
   ]
  },
  {
   "id": "cell-13",
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## Google Cloud Platform Transition\n",
    "1. **BigQuery ML:** Retrain model on fresh table partition via scheduled queries.\n",
    "2. **Vertex AI Model Monitoring:** Configure `ModelDeploymentMonitoringJob` with drift threshold `0.20` to automate alert publication to Cloud Pub/Sub.\n"
   ]
  },
  {
   "id": "cell-14",
   "metadata": {
    "tags": [
     "vit-result"
    ]
   },
   "cell_type": "code",
   "execution_count": 8,
   "source": [
    "display(JSON({\n",
    "    'baseline_records': N_BASE,\n",
    "    'total_windows_evaluated': NUM_WINDOWS,\n",
    "    'retrain_triggered_at_window': trigger_window,\n",
    "    'terminal_psi': round(psi_series[-1], 4),\n",
    "    'status': 'VERIFIED_DRIFT_DETECTION'\n",
    "}))\n"
   ],
   "outputs": [
    {
     "data": {
      "application/json": {
       "baseline_records": 2000,
       "retrain_triggered_at_window": 6,
       "status": "VERIFIED_DRIFT_DETECTION",
       "terminal_psi": 2.0185,
       "total_windows_evaluated": 8
      },
      "text/plain": [
       "<IPython.core.display.JSON object>"
      ]
     },
     "metadata": {
      "application/json": {
       "expanded": false,
       "root": "root"
      }
     },
     "output_type": "display_data"
    }
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.12.12"
  },
  "mementropy": {
   "contentKind": "notebook",
   "world": "hungersync",
   "capabilities": [
    "drift-detection",
    "retraining-policy"
   ],
   "implementations": [
    "NumPy",
    "Matplotlib",
    "IPython"
   ],
   "evidenceStatus": "executed-example",
   "updatedDate": "2026-10-29"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
