{
 "cells": [
  {
   "id": "cell-00",
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "# HungerSync: a synthetic workload forecasting baseline\n",
    "\n",
    "**Role:** Workload forecasting analyst (HungerSync operations)\n",
    "\n",
    "**Division:** Operations planning\n",
    "\n",
    "**Goal:** Compare weekly repetition with a drift-adjusted baseline for a 14-day forecast of synthetic review workload.\n",
    "\n",
    "**Boundary:** Original generated daily values, not observed demand or live telemetry. No staffing changes, scheduling, or production actions are performed.\n"
   ]
  },
  {
   "id": "cell-01",
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## Prerequisites and support\n",
    "\n",
    "The saved execution reports Python 3.12.12. To explore the public download, use an isolated Python environment with JupyterLab, Matplotlib and IPython. The forecasting calculations use Python's `math`, `random` and `statistics` standard-library modules. No external dataset, model weights, credentials, GPU or inference service is needed after installing the packages.\n",
    "\n",
    "The public download omits the site-only styling cell, so it does not require `mementropy.mplstyle`; default Matplotlib styling is sufficient. Dependency versions are not locked in this download, and a clean-environment rerun has not been verified.\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 random\n",
    "import statistics\n",
    "import sys\n",
    "import matplotlib.pyplot as plt\n",
    "from IPython.display import display, Markdown, JSON\n",
    "\n",
    "SEED = 42\n",
    "HORIZON = 14\n",
    "print({'python': sys.version.split()[0], 'seed': SEED, 'model': 'transparent drift-adjusted baseline'})\n"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'python': '3.12.12', 'seed': 42, 'model': 'transparent drift-adjusted baseline'}\n"
     ]
    }
   ]
  },
  {
   "id": "cell-03",
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## Data and the information boundary\n",
    "\n",
    "There are 90 daily observations with zero-based day indices 0–89. The unit is **review cases/day**, represented as continuous synthetic workload rather than measured integer case counts. With seed 42, each value combines a level of 60, an upward trend of 0.2 per day, a seven-day sine wave of amplitude 8, and Gaussian noise with standard deviation 2.\n",
    "\n",
    "The first 76 observations (days 0–75) are history. The final 14 observations (days 76–89) are the unseen evaluation interval: a single 14-day forecast made after day 75. Both methods use history only. This is not a streaming or intraday forecasting experiment, and the fixture contains no external records.\n"
   ]
  },
  {
   "id": "cell-04",
   "metadata": {},
   "cell_type": "code",
   "execution_count": 3,
   "source": [
    "rng = random.Random(SEED)\n",
    "days = list(range(90))\n",
    "volume = [60 + .2*t + 8*math.sin(2*math.pi*t/7) + rng.gauss(0, 2) for t in days]\n",
    "train, truth = volume[:-HORIZON], volume[-HORIZON:]\n",
    "assert len(train) >= 14 and len(truth) == HORIZON\n",
    "assert all(math.isfinite(x) and x >= 0 for x in volume)\n",
    "print({'observations': len(volume), 'training': len(train), 'holdout': len(truth), 'units': 'review cases/day'})\n"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'observations': 90, 'training': 76, 'holdout': 14, 'units': 'review cases/day'}\n"
     ]
    }
   ]
  },
  {
   "id": "cell-05",
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## Implementation and cheap comparator\n",
    "\n",
    "The **Weekly baseline** repeats the final seven observed values twice. The **Drift adjusted** candidate estimates daily drift as the difference between the means of the final and first observed weeks, divided by the distance between those weeks (`len(history) - 7`). It adds seven days of estimated drift to the first forecast week and fourteen days to the second.\n",
    "\n",
    "Both methods see exactly the same 76 observations. This transparent Python baseline has no learned checkpoint and does not emulate a foundation model.\n"
   ]
  },
  {
   "id": "cell-06",
   "metadata": {},
   "cell_type": "code",
   "execution_count": 4,
   "source": [
    "def predict(history, horizon):\n",
    "    if len(history) < 14 or horizon < 1:\n",
    "        raise ValueError('At least two weeks of history and a positive horizon are required')\n",
    "    if not all(math.isfinite(x) for x in history):\n",
    "        raise ValueError('Missing or infinite observations need an explicit data-quality decision')\n",
    "    weekly = [history[-7:][i % 7] for i in range(horizon)]\n",
    "    daily_drift = (statistics.mean(history[-7:]) - statistics.mean(history[:7])) / (len(history)-7)\n",
    "    adjusted = [value + daily_drift*7*(i//7+1) for i, value in enumerate(weekly)]\n",
    "    return {'Weekly baseline': weekly, 'Drift adjusted': adjusted}\n",
    "\n",
    "predictions = predict(train, HORIZON)\n",
    "assert all(len(values) == len(truth) for values in predictions.values())\n"
   ],
   "outputs": []
  },
  {
   "id": "cell-07",
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## Inspect the saved errors\n",
    "\n",
    "MAE is the mean absolute error over the final 14 days, in review cases/day. The saved outputs report **Weekly baseline: 2.216** and **Drift adjusted: 1.870**. Those displayed values are rounded; the saved JSON receipt retains the underlying precision.\n",
    "\n",
    "The shaded interval covers zero-based days 76–89, the 77th through 90th observations. Neither method uses those values when predicting. The candidate benefits from a trend that continues in this generated series; a trend reversal could change the result. One synthetic split is not a benchmark or evidence of real-world superiority.\n"
   ]
  },
  {
   "id": "cell-08",
   "metadata": {},
   "cell_type": "code",
   "execution_count": 5,
   "source": [
    "#| fig-alt: \"Line chart comparing the weekly baseline and drift-adjusted forecast against synthetic observed volume across 90 days, with the final 14 days shaded as the unseen holdout window where the drift-adjusted model tracks the upward trend more closely.\"\n",
    "#| fig-cap: \"Holdout comparison (zero-based days 76–89): the drift-adjusted comparator tracks the upward trend better than the static weekly repeat baseline on this synthetic series.\"\n",
    "metrics = {name: statistics.mean(abs(a-b) for a,b in zip(truth,values))\n",
    "           for name,values in predictions.items()}\n",
    "for name, mae in metrics.items():\n",
    "    print(f'{name}: MAE = {mae:.3f} cases/day')\n",
    "fig, ax = plt.subplots(figsize=(10, 4))\n",
    "ax.plot(days, volume, label='Synthetic observed volume', color='#171817')\n",
    "for name, values in predictions.items():\n",
    "    ax.plot(days[-HORIZON:], values, label=name)\n",
    "ax.axvspan(len(train)-.5, len(volume)-.5, alpha=.1, color='#1a7f64', label='Holdout')\n",
    "ax.set(xlabel='Day', ylabel='Review cases/day', title='The same unseen future for both methods')\n",
    "ax.legend(); fig.tight_layout(); plt.show()\n",
    "winner = min(metrics, key=metrics.get)\n",
    "display(Markdown(f'**Observed in this execution:** {winner} has the lowest MAE. This is not proof of general superiority.'))\n"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Weekly baseline: MAE = 2.216 cases/day\n",
      "Drift adjusted: MAE = 1.870 cases/day\n"
     ]
    },
    {
     "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=\"714.330938pt\" height=\"282.96pt\" viewBox=\"0 0 714.330938 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:26:51.638038</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 714.330938 282.96 \n",
       "L 714.330938 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 39.135938 243.3725 \n",
       "L 707.130937 243.3725 \n",
       "L 707.130937 29.925 \n",
       "L 39.135938 29.925 \n",
       "L 39.135938 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",
       "     <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=\"69.499347\" y=\"257.4645\" transform=\"rotate(-0 69.499347 257.4645)\">0</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_2\">\n",
       "     <g id=\"line2d_2\"/>\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=\"205.201734\" y=\"257.4645\" transform=\"rotate(-0 205.201734 257.4645)\">20</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_3\">\n",
       "     <g id=\"line2d_3\"/>\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=\"340.904121\" y=\"257.4645\" transform=\"rotate(-0 340.904121 257.4645)\">40</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_4\">\n",
       "     <g id=\"line2d_4\"/>\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=\"476.606508\" y=\"257.4645\" transform=\"rotate(-0 476.606508 257.4645)\">60</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_5\">\n",
       "     <g id=\"line2d_5\"/>\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=\"612.308895\" y=\"257.4645\" transform=\"rotate(-0 612.308895 257.4645)\">80</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=\"373.133438\" y=\"273.843\" transform=\"rotate(-0 373.133438 273.843)\">Day</text>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_2\">\n",
       "    <g id=\"ytick_1\">\n",
       "     <g id=\"line2d_6\">\n",
       "      <path d=\"M 39.135938 234.724906 \n",
       "L 707.130937 234.724906 \n",
       "\" clip-path=\"url(#p57b53acb8d)\" style=\"fill: none; stroke: #e3e4de; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_7\"/>\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=\"33.135938\" y=\"238.770906\" transform=\"rotate(-0 33.135938 238.770906)\">50</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_2\">\n",
       "     <g id=\"line2d_8\">\n",
       "      <path d=\"M 39.135938 209.112497 \n",
       "L 707.130937 209.112497 \n",
       "\" clip-path=\"url(#p57b53acb8d)\" style=\"fill: none; stroke: #e3e4de; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_9\"/>\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=\"33.135938\" y=\"213.158497\" transform=\"rotate(-0 33.135938 213.158497)\">55</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_3\">\n",
       "     <g id=\"line2d_10\">\n",
       "      <path d=\"M 39.135938 183.500089 \n",
       "L 707.130937 183.500089 \n",
       "\" clip-path=\"url(#p57b53acb8d)\" style=\"fill: none; stroke: #e3e4de; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_11\"/>\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=\"33.135938\" y=\"187.546089\" transform=\"rotate(-0 33.135938 187.546089)\">60</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_4\">\n",
       "     <g id=\"line2d_12\">\n",
       "      <path d=\"M 39.135938 157.88768 \n",
       "L 707.130937 157.88768 \n",
       "\" clip-path=\"url(#p57b53acb8d)\" style=\"fill: none; stroke: #e3e4de; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_13\"/>\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=\"33.135938\" y=\"161.93368\" transform=\"rotate(-0 33.135938 161.93368)\">65</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_5\">\n",
       "     <g id=\"line2d_14\">\n",
       "      <path d=\"M 39.135938 132.275271 \n",
       "L 707.130937 132.275271 \n",
       "\" clip-path=\"url(#p57b53acb8d)\" style=\"fill: none; stroke: #e3e4de; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_15\"/>\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=\"33.135938\" y=\"136.321271\" transform=\"rotate(-0 33.135938 136.321271)\">70</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_6\">\n",
       "     <g id=\"line2d_16\">\n",
       "      <path d=\"M 39.135938 106.662863 \n",
       "L 707.130937 106.662863 \n",
       "\" clip-path=\"url(#p57b53acb8d)\" style=\"fill: none; stroke: #e3e4de; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_17\"/>\n",
       "     <g id=\"text_12\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: end; fill: #6f706a\" x=\"33.135938\" y=\"110.708863\" transform=\"rotate(-0 33.135938 110.708863)\">75</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_7\">\n",
       "     <g id=\"line2d_18\">\n",
       "      <path d=\"M 39.135938 81.050454 \n",
       "L 707.130937 81.050454 \n",
       "\" clip-path=\"url(#p57b53acb8d)\" style=\"fill: none; stroke: #e3e4de; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_19\"/>\n",
       "     <g id=\"text_13\">\n",
       "      <text style=\"font-size: 8.5px; font-family: 'Inter', 'Helvetica Neue', 'Helvetica', 'Arial', 'DejaVu Sans', sans-serif; text-anchor: end; fill: #6f706a\" x=\"33.135938\" y=\"85.096454\" transform=\"rotate(-0 33.135938 85.096454)\">80</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_8\">\n",
       "     <g id=\"line2d_20\">\n",
       "      <path d=\"M 39.135938 55.438046 \n",
       "L 707.130937 55.438046 \n",
       "\" clip-path=\"url(#p57b53acb8d)\" style=\"fill: none; stroke: #e3e4de; stroke-width: 0.8; stroke-linecap: round\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_21\"/>\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: end; fill: #6f706a\" x=\"33.135938\" y=\"59.484046\" transform=\"rotate(-0 33.135938 59.484046)\">85</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_15\">\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)\">Review cases/day</text>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path d=\"M 581.775858 243.3725 \n",
       "L 676.767528 243.3725 \n",
       "L 676.767528 29.925 \n",
       "L 581.775858 29.925 \n",
       "z\n",
       "\" clip-path=\"url(#p57b53acb8d)\" style=\"fill: #1a7f64; opacity: 0.1; stroke: #1a7f64; stroke-linejoin: miter\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_22\">\n",
       "    <path d=\"M 69.499347 184.976289 \n",
       "L 76.284466 152.207644 \n",
       "L 83.069585 142.63912 \n",
       "L 89.854705 155.45431 \n",
       "L 96.639824 198.489733 \n",
       "L 103.424943 233.670341 \n",
       "L 110.210063 205.987861 \n",
       "L 116.995182 179.067477 \n",
       "L 123.780301 145.487512 \n",
       "L 130.565421 133.139983 \n",
       "L 137.35054 153.094751 \n",
       "L 144.135659 178.090505 \n",
       "L 150.920779 204.431319 \n",
       "L 157.705898 201.088834 \n",
       "L 164.491017 176.721218 \n",
       "L 171.276137 146.488483 \n",
       "L 178.061256 124.631977 \n",
       "L 184.846376 134.871184 \n",
       "L 191.631495 182.412873 \n",
       "L 198.416614 205.076339 \n",
       "L 205.201734 189.601474 \n",
       "L 211.986853 176.877184 \n",
       "L 218.771972 132.121099 \n",
       "L 225.557092 114.960523 \n",
       "L 232.342211 132.183688 \n",
       "L 239.12733 178.133414 \n",
       "L 245.91245 192.957335 \n",
       "L 252.697569 185.335089 \n",
       "L 259.482688 146.799281 \n",
       "L 266.267808 133.155276 \n",
       "L 273.052927 106.991088 \n",
       "L 279.838046 149.476416 \n",
       "L 286.623166 195.337943 \n",
       "L 293.408285 195.861686 \n",
       "L 300.193404 190.088993 \n",
       "L 306.978524 138.668003 \n",
       "L 313.763643 107.773501 \n",
       "L 320.548763 118.130697 \n",
       "L 327.333882 118.107549 \n",
       "L 334.119001 171.592755 \n",
       "L 340.904121 183.356203 \n",
       "L 347.68924 176.546071 \n",
       "L 354.474359 139.299015 \n",
       "L 361.259479 99.020507 \n",
       "L 368.044598 91.92932 \n",
       "L 374.829717 116.032701 \n",
       "L 381.614837 147.495054 \n",
       "L 388.399956 170.39903 \n",
       "L 395.185075 172.787047 \n",
       "L 401.970195 140.649208 \n",
       "L 408.755314 105.05074 \n",
       "L 415.540433 86.182791 \n",
       "L 422.325553 115.008212 \n",
       "L 429.110672 123.052558 \n",
       "L 435.895791 176.523311 \n",
       "L 442.680911 170.45006 \n",
       "L 449.46603 118.25531 \n",
       "L 456.25115 78.497656 \n",
       "L 463.036269 78.946094 \n",
       "L 469.821388 96.711394 \n",
       "L 476.606508 125.197948 \n",
       "L 483.391627 161.921523 \n",
       "L 490.176746 166.598817 \n",
       "L 496.961866 124.407924 \n",
       "L 503.746985 76.130601 \n",
       "L 510.532104 91.745856 \n",
       "L 517.317224 97.759311 \n",
       "L 524.102343 130.044918 \n",
       "L 530.887462 157.019971 \n",
       "L 537.672582 137.435598 \n",
       "L 544.457701 105.835277 \n",
       "L 551.24282 54.938763 \n",
       "L 558.02794 63.432402 \n",
       "L 564.813059 97.17468 \n",
       "L 571.598178 131.223447 \n",
       "L 578.383298 155.134784 \n",
       "L 585.168417 127.921699 \n",
       "L 591.953537 110.421052 \n",
       "L 598.738656 72.269853 \n",
       "L 605.523775 54.935897 \n",
       "L 612.308895 91.171741 \n",
       "L 619.094014 121.304892 \n",
       "L 625.879133 158.307702 \n",
       "L 632.664253 141.596186 \n",
       "L 639.449372 103.258835 \n",
       "L 646.234491 60.119104 \n",
       "L 653.019611 43.213705 \n",
       "L 659.80473 76.777607 \n",
       "L 666.589849 108.447235 \n",
       "L 673.374969 130.551477 \n",
       "\" clip-path=\"url(#p57b53acb8d)\" style=\"fill: none; stroke: #171817; stroke-width: 1.8; stroke-linecap: round\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_23\">\n",
       "    <path d=\"M 585.168417 137.435598 \n",
       "L 591.953537 105.835277 \n",
       "L 598.738656 54.938763 \n",
       "L 605.523775 63.432402 \n",
       "L 612.308895 97.17468 \n",
       "L 619.094014 131.223447 \n",
       "L 625.879133 155.134784 \n",
       "L 632.664253 137.435598 \n",
       "L 639.449372 105.835277 \n",
       "L 646.234491 54.938763 \n",
       "L 653.019611 63.432402 \n",
       "L 659.80473 97.17468 \n",
       "L 666.589849 131.223447 \n",
       "L 673.374969 155.134784 \n",
       "\" clip-path=\"url(#p57b53acb8d)\" style=\"fill: none; stroke: #0969da; stroke-width: 1.8; stroke-linecap: round\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_24\">\n",
       "    <path d=\"M 585.168417 129.779795 \n",
       "L 591.953537 98.179475 \n",
       "L 598.738656 47.282961 \n",
       "L 605.523775 55.7766 \n",
       "L 612.308895 89.518878 \n",
       "L 619.094014 123.567645 \n",
       "L 625.879133 147.478982 \n",
       "L 632.664253 122.123993 \n",
       "L 639.449372 90.523673 \n",
       "L 646.234491 39.627159 \n",
       "L 653.019611 48.120798 \n",
       "L 659.80473 81.863075 \n",
       "L 666.589849 115.911843 \n",
       "L 673.374969 139.82318 \n",
       "\" clip-path=\"url(#p57b53acb8d)\" style=\"fill: none; stroke: #1a7f64; stroke-width: 1.8; stroke-linecap: round\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path d=\"M 39.135938 243.3725 \n",
       "L 39.135938 29.925 \n",
       "\" style=\"fill: none; stroke: #d1d2cb; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path d=\"M 39.135938 243.3725 \n",
       "L 707.130938 243.3725 \n",
       "\" style=\"fill: none; stroke: #d1d2cb; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"text_16\">\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=\"39.135938\" y=\"17.925\" transform=\"rotate(-0 39.135938 17.925)\">The same unseen future for both methods</text>\n",
       "   </g>\n",
       "   <g id=\"legend_1\">\n",
       "    <g id=\"line2d_25\">\n",
       "     <path d=\"M 46.785938 42.692 \n",
       "L 55.285938 42.692 \n",
       "L 63.785938 42.692 \n",
       "\" style=\"fill: none; stroke: #171817; stroke-width: 1.8; stroke-linecap: round\"/>\n",
       "    </g>\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: start; fill: #484945\" x=\"70.585938\" y=\"45.667\" transform=\"rotate(-0 70.585938 45.667)\">Synthetic observed volume</text>\n",
       "    </g>\n",
       "    <g id=\"line2d_26\">\n",
       "     <path d=\"M 46.785938 56.8445 \n",
       "L 55.285938 56.8445 \n",
       "L 63.785938 56.8445 \n",
       "\" style=\"fill: none; stroke: #0969da; stroke-width: 1.8; stroke-linecap: round\"/>\n",
       "    </g>\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: start; fill: #484945\" x=\"70.585938\" y=\"59.8195\" transform=\"rotate(-0 70.585938 59.8195)\">Weekly baseline</text>\n",
       "    </g>\n",
       "    <g id=\"line2d_27\">\n",
       "     <path d=\"M 46.785938 70.997 \n",
       "L 55.285938 70.997 \n",
       "L 63.785938 70.997 \n",
       "\" style=\"fill: none; stroke: #1a7f64; stroke-width: 1.8; stroke-linecap: round\"/>\n",
       "    </g>\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: start; fill: #484945\" x=\"70.585938\" y=\"73.972\" transform=\"rotate(-0 70.585938 73.972)\">Drift adjusted</text>\n",
       "    </g>\n",
       "    <g id=\"patch_6\">\n",
       "     <path d=\"M 46.785938 88.1245 \n",
       "L 63.785938 88.1245 \n",
       "L 63.785938 82.1745 \n",
       "L 46.785938 82.1745 \n",
       "z\n",
       "\" style=\"fill: #1a7f64; opacity: 0.1; stroke: #1a7f64; stroke-linejoin: miter\"/>\n",
       "    </g>\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: start; fill: #484945\" x=\"70.585938\" y=\"88.1245\" transform=\"rotate(-0 70.585938 88.1245)\">Holdout</text>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p57b53acb8d\">\n",
       "   <rect x=\"39.135938\" y=\"29.925\" width=\"667.995\" height=\"213.4475\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<Figure size 1000x400 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "**Observed in this execution:** Drift adjusted has the lowest MAE. This is not proof of general superiority."
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ]
  },
  {
   "id": "cell-09",
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## Turn a prediction into a decision\n",
    "\n",
    "Assume an unfilled case of capacity costs four units and unused capacity costs one. These are teaching assumptions, not dollars or validated savings. Predictions are clipped at zero for the capacity calculation, not for MAE.\n",
    "\n",
    "Across this 14-day holdout, the saved costs are **103.93 assumed units** for the weekly baseline and **44.74 assumed units** for the drift-adjusted candidate. Comparing forecast error with decision cost illustrates that these are separate objectives. A real decision would need an independently validated policy and an accountable human owner; this notebook performs no staffing change.\n"
   ]
  },
  {
   "id": "cell-10",
   "metadata": {},
   "cell_type": "code",
   "execution_count": 6,
   "source": [
    "costs = {}\n",
    "for name, values in predictions.items():\n",
    "    costs[name] = sum(4*max(actual-max(0,predicted),0) + max(max(0,predicted)-actual,0)\n",
    "                      for actual,predicted in zip(truth,values))\n",
    "    print(f'{name}: assumed cost = {costs[name]:.2f} units')\n",
    "display(Markdown('**Human review:** compare missed demand, unused capacity and the cost assumptions before proposing a pilot. No staffing change is performed.'))\n"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Weekly baseline: assumed cost = 103.93 units\n",
      "Drift adjusted: assumed cost = 44.74 units\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "**Human review:** compare missed demand, unused capacity and the cost assumptions before proposing a pilot. No staffing change is performed."
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ]
  },
  {
   "id": "cell-11",
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## Break it safely and transfer the idea\n",
    "\n",
    "The saved failure probe replaces one historical value with `NaN` and catches the expected `ValueError`. It demonstrates input rejection, not comprehensive validation of an operational system.\n",
    "\n",
    "For independent practice, introduce a trend reversal after the split and explain which method fails. Keep that counterfactual separate from the saved results below. Repeatedly tuning against this displayed holdout would make it unsuitable as unseen evaluation data.\n"
   ]
  },
  {
   "id": "cell-12",
   "metadata": {},
   "cell_type": "code",
   "execution_count": 7,
   "source": [
    "broken = train.copy()\n",
    "broken[10] = float('nan')\n",
    "try:\n",
    "    predict(broken, HORIZON)\n",
    "except ValueError as error:\n",
    "    print('EXPECTED REJECTION:', error)\n",
    "else:\n",
    "    raise AssertionError('Invalid input was accepted')\n"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "EXPECTED REJECTION: Missing or infinite observations need an explicit data-quality decision\n"
     ]
    }
   ]
  },
  {
   "id": "cell-13",
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## Limits and saved execution receipt\n",
    "\n",
    "This is an original synthetic example with no external dataset or pretrained checkpoint. The saved execution demonstrates these calculations on one generated series; it does not establish improved enterprise outcomes, service levels, or staffing savings. Model results never authorize production actions.\n",
    "\n",
    "The following JSON is preserved from the earlier execution, alongside the original saved outputs. It was not generated by the renderer or rerun for this editorial update. The source code below computes the receipt from the notebook's variables; no expected measurements have been substituted.\n"
   ]
  },
  {
   "id": "cell-14",
   "metadata": {
    "tags": [
     "vit-result"
    ]
   },
   "cell_type": "code",
   "execution_count": 8,
   "source": [
    "display(JSON({'observations': len(volume), 'holdout': len(truth), 'seed': SEED,\n",
    "              'provenance': 'original synthetic teaching data',\n",
    "              'model': 'transparent drift-adjusted baseline',\n",
    "              'mae': metrics, 'assumed_cost': costs}))\n"
   ],
   "outputs": [
    {
     "data": {
      "application/json": {
       "assumed_cost": {
        "Drift adjusted": 44.73828549629849,
        "Weekly baseline": 103.9272092056002
       },
       "holdout": 14,
       "mae": {
        "Drift adjusted": 1.8699052402514411,
        "Weekly baseline": 2.215922860645823
       },
       "model": "transparent drift-adjusted baseline",
       "observations": 90,
       "provenance": "original synthetic teaching data",
       "seed": 42
      },
      "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": [
    "workload-forecasting",
    "baseline-evaluation",
    "decision-cost-analysis"
   ],
   "implementations": [
    "Python standard library",
    "Matplotlib",
    "IPython"
   ],
   "evidenceStatus": "executed-example",
   "updatedDate": "2026-10-29"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
