{
  "nbformat": 4,
  "nbformat_minor": 5,
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.10"
    }
  },
  "cells": [
    {
      "id": "scope",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# kernel reproduction check\n",
        "Run in the extracted bundle folder. Read README.md for provenance, prerequisites, and limitations. This is not full-paper replication.\n"
      ]
    },
    {
      "id": "check",
      "cell_type": "code",
      "metadata": {},
      "execution_count": null,
      "outputs": [],
      "source": [
        "\"\"\"Check a two-dimensional kernel worked example; no ECG training.\"\"\"\n",
        "import json\n",
        "import math\n",
        "from pathlib import Path\n",
        "\n",
        "ROOT = Path(__file__).resolve().parent if \"__file__\" in globals() else Path.cwd()\n",
        "\n",
        "\n",
        "def reproduce():\n",
        "    source = json.loads((ROOT / \"source.json\").read_text(encoding=\"utf-8\"))\n",
        "    x = math.radians(source[\"x_degrees\"]) / 2\n",
        "    y = math.radians(source[\"y_degrees\"]) / 2\n",
        "    alpha = source[\"fidelity_weight\"]\n",
        "    fidelity = math.cos(x - y) ** 2\n",
        "    reference_gap = (math.cos(x) - math.cos(y)) ** 2\n",
        "    return {\"fidelity\": fidelity, \"reference_gap\": reference_gap,\n",
        "            \"combined_kernel\": alpha * fidelity + (1 - alpha) * reference_gap}\n",
        "\n",
        "\n",
        "if __name__ == \"__main__\":\n",
        "    result = reproduce()\n",
        "    expected = json.loads((ROOT / \"expected.json\").read_text(encoding=\"utf-8\"))\n",
        "    for key, value in expected.items():\n",
        "        assert math.isclose(result[key], value, rel_tol=0, abs_tol=1e-12), key\n",
        "    print(json.dumps(result, indent=2))\n",
        "    print(\"PASS: kernel worked example checked; no ECG model trained.\")\n"
      ]
    }
  ]
}
