Kaynağa Gözat

Rerun stuff.

Martin Horvat 1 gün önce
ebeveyn
işleme
2838fd8b40

Dosya farkı çok büyük olduğundan ihmal edildi
+ 135 - 135
notebooks/logit_all_models.ipynb


+ 63 - 90
notebooks/logit_review_boots.ipynb

@@ -22,8 +22,8 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 1,
-   "id": "7aea473c",
+   "execution_count": null,
+   "id": "3e49303c",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -39,7 +39,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 2,
+   "execution_count": null,
    "id": "063c7f0a",
    "metadata": {},
    "outputs": [],
@@ -56,7 +56,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "c3028cad",
+   "id": "89f6c3ba",
    "metadata": {},
    "source": [
     "## Data"
@@ -64,8 +64,8 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 3,
-   "id": "ec16d25e",
+   "execution_count": 2,
+   "id": "d679e87e",
    "metadata": {},
    "outputs": [
     {
@@ -93,7 +93,7 @@
          "type": "integer"
         }
        ],
-       "ref": "0af80a19-b7c6-4b14-adf0-ba42b59dcf4d",
+       "ref": "60c072e3-2d98-40c6-80d2-643b56a43a26",
        "rows": [
         [
          "0",
@@ -840,7 +840,7 @@
        "57          58  1.439417  0"
       ]
      },
-     "execution_count": 3,
+     "execution_count": 2,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -871,15 +871,13 @@
     "y = df_xy['y'].to_numpy(dtype=int)\n",
     "\n",
     "n_boots = 10_000\n",
-    "# Reproducibility: derive all stochastic calculations from one fixed seed.\n",
-    "random_seed = logistic.DEFAULT_RANDOM_SEED\n",
     "df_xy"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 4,
-   "id": "f9715e44",
+   "execution_count": 3,
+   "id": "5f40f218",
    "metadata": {},
    "outputs": [
     {
@@ -925,7 +923,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "4ddf0526",
+   "id": "69c7fcff",
    "metadata": {},
    "source": [
     "## Fit and asymptotic uncertainty"
@@ -933,15 +931,15 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 5,
-   "id": "a8dcfb7b",
+   "execution_count": null,
+   "id": "38b574fa",
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "{'theta': array([-11.68387205,   5.68696544]), 'cost': np.float64(7.3941950513638925), 'success': True, 'message': 'CONVERGENCE: RELATIVE REDUCTION OF F <= FACTR*EPSMCH', 'nit': 4}\n",
+      "{'pars': array([-11.68387205,   5.68696545]), 'cost': np.float64(7.394195051363892), 'success': True, 'message': 'CONVERGENCE: NORM OF PROJECTED GRADIENT <= PGTOL', 'nit': 4}\n",
       "covariance matrix:\n",
       " [[12.32303702 -6.71291913]\n",
       " [-6.71291913  3.81878393]]\n"
@@ -972,19 +970,19 @@
          "type": "float"
         }
        ],
-       "ref": "5748fc65-6a20-485c-9df3-90afa8d4ed4c",
+       "ref": "9a26be77-8ece-495e-b19d-aa26391bdd50",
        "rows": [
         [
          "b0",
-         "-11.68387204779878",
-         "-18.564165591914772",
-         "-4.803578503682786"
+         "-11.683872048612786",
+         "-18.564165593323825",
+         "-4.803578503901749"
         ],
         [
          "b1",
-         "5.6869654445521",
-         "1.8568608506533293",
-         "9.51707003845087"
+         "5.686965445003518",
+         "1.8568608508060875",
+         "9.517070039200949"
         ]
        ],
        "shape": {
@@ -1039,14 +1037,14 @@
        "b1   5.686965   1.856861  9.517070"
       ]
      },
-     "execution_count": 5,
+     "execution_count": 4,
      "metadata": {},
      "output_type": "execute_result"
     }
    ],
    "source": [
     "logit = logistic.LogisticPolyRegression(degree=1)\n",
-    "res_fit = logit.fit(x, y, method='diff_evol', seed=random_seed)\n",
+    "res_fit = logit.fit(x, y, method='diff_evol')\n",
     "if not res_fit['success']:\n",
     "    raise RuntimeError(f\"Logistic fit failed: {res_fit}\")\n",
     "\n",
@@ -1066,8 +1064,8 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 6,
-   "id": "1d28f481",
+   "execution_count": null,
+   "id": "01c94f2e",
    "metadata": {},
    "outputs": [
     {
@@ -1100,21 +1098,16 @@
          "type": "float"
         },
         {
-         "name": "deviance",
+         "name": "chi2",
          "rawType": "float64",
          "type": "float"
         },
         {
-         "name": "p-value(deviance_bootstrap)",
+         "name": "p-value(chi2)",
          "rawType": "float64",
          "type": "float"
         },
         {
-         "name": "deviance_bootstrap_samples",
-         "rawType": "int64",
-         "type": "integer"
-        },
-        {
          "name": "n",
          "rawType": "int64",
          "type": "integer"
@@ -1130,24 +1123,23 @@
          "type": "integer"
         }
        ],
-       "ref": "b9f3e3b1-8f4d-4c13-9e7d-cafdfb95e867",
+       "ref": "6a60656c-a27d-4a81-a68a-d1725d9c323e",
        "rows": [
         [
          "0",
-         "-7.3941950513638925",
-         "18.788390102727785",
-         "22.909276123820625",
+         "-7.394195051363892",
+         "18.78839010272778",
+         "22.90927612382062",
          "0.9655172413793104",
-         "14.788390102727785",
-         "0.3946053946053946",
-         "1000",
+         "23.103221367618744",
+         "0.9999706242978951",
          "58",
          "2",
          "56"
         ]
        ],
        "shape": {
-        "columns": 10,
+        "columns": 9,
         "rows": 1
        }
       },
@@ -1174,9 +1166,8 @@
        "      <th>AIC</th>\n",
        "      <th>BIC</th>\n",
        "      <th>A</th>\n",
-       "      <th>deviance</th>\n",
-       "      <th>p-value(deviance_bootstrap)</th>\n",
-       "      <th>deviance_bootstrap_samples</th>\n",
+       "      <th>chi2</th>\n",
+       "      <th>p-value(chi2)</th>\n",
        "      <th>n</th>\n",
        "      <th>k</th>\n",
        "      <th>dof</th>\n",
@@ -1189,9 +1180,8 @@
        "      <td>18.78839</td>\n",
        "      <td>22.909276</td>\n",
        "      <td>0.965517</td>\n",
-       "      <td>14.78839</td>\n",
-       "      <td>0.394605</td>\n",
-       "      <td>1000</td>\n",
+       "      <td>23.103221</td>\n",
+       "      <td>0.999971</td>\n",
        "      <td>58</td>\n",
        "      <td>2</td>\n",
        "      <td>56</td>\n",
@@ -1201,28 +1191,26 @@
        "</div>"
       ],
       "text/plain": [
-       "        LLF       AIC        BIC         A  deviance  \\\n",
-       "0 -7.394195  18.78839  22.909276  0.965517  14.78839   \n",
+       "        LLF       AIC        BIC         A       chi2  p-value(chi2)   n  k  \\\n",
+       "0 -7.394195  18.78839  22.909276  0.965517  23.103221       0.999971  58  2   \n",
        "\n",
-       "   p-value(deviance_bootstrap)  deviance_bootstrap_samples   n  k  dof  \n",
-       "0                     0.394605                        1000  58  2   56  "
+       "   dof  \n",
+       "0   56  "
       ]
      },
-     "execution_count": 6,
+     "execution_count": 5,
      "metadata": {},
      "output_type": "execute_result"
     }
    ],
    "source": [
-    "pd.DataFrame([\n",
-    "    logit.goodness_of_fit(x, y, theta, bootstrap_seed=random_seed)\n",
-    "])"
+    "pd.DataFrame([logit.goodness_of_fit(x, y, theta)])"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 7,
-   "id": "ed8167bb",
+   "execution_count": null,
+   "id": "50095607",
    "metadata": {},
    "outputs": [
     {
@@ -1245,16 +1233,9 @@
     "\n",
     "ax.plot(xp, logit.model(xp, theta), color='black', label='logistic fit', zorder=4)\n",
     "\n",
-    "quantile_methods = {\n",
-    "    'normal': lambda xgrid: logit.get_model_quantiles_normal(\n",
-    "        xgrid, probs, theta, cov_theta, seed=random_seed\n",
-    "    ),\n",
-    "    'delta': lambda xgrid: logit.get_model_quantiles_delta(\n",
-    "        xgrid, probs, theta, cov_theta\n",
-    "    ),\n",
-    "}\n",
-    "for label, color in [('normal', 'tab:red'), ('delta', 'tab:green')]:\n",
-    "    lo, hi = quantile_methods[label](xp)\n",
+    "for label, method, color in [('normal', logit.get_model_quantiles_normal, 'tab:red'),\n",
+    "                             ('delta', logit.get_model_quantiles_delta, 'tab:green')]:\n",
+    "    lo, hi = method(xp, probs, theta, cov_theta)\n",
     "    ax.fill_between(xp, lo, hi, color=color, alpha=0.18, label=f'95% CI ({label})')\n",
     "\n",
     "ax.set(xlabel='maximum SUV percentile across visits', \n",
@@ -1269,7 +1250,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "ea737bf6",
+   "id": "64da8c2f",
    "metadata": {},
    "source": [
     "## Bootstrap parameter samples"
@@ -1277,8 +1258,8 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 9,
-   "id": "ee951c08",
+   "execution_count": null,
+   "id": "77320617",
    "metadata": {},
    "outputs": [
     {
@@ -1293,23 +1274,17 @@
     "# Each method returns exactly n_boots bootstrap estimates. The original-data\n",
     "# MLE is used as the initial point for fitting each replicate but is not\n",
     "# included as a row in the returned bootstrap array.\n",
-    "btheta_nonpar = logit.get_nonparam_boots_theta(\n",
-    "    x, y, n_boots, seed=random_seed\n",
-    ")\n",
-    "btheta_nonpar_strat = logit.get_nonparam_stratified_boots_theta(\n",
-    "    x, y, n_boots, seed=random_seed + 1\n",
-    ")\n",
-    "btheta_param = logit.get_parametric_boots_theta(\n",
-    "    x, y, n_boots, seed=random_seed + 2\n",
-    ")\n",
+    "btheta_nonpar = logit.get_nonparam_boots_theta(x, y, n_boots, seed=1977)\n",
+    "btheta_nonpar_strat = logit.get_nonparam_stratified_boots_theta(x, y, n_boots, seed=1978)\n",
+    "btheta_param = logit.get_parametric_boots_theta(x, y, n_boots, seed=1979)\n",
     "\n",
     "print(btheta_nonpar.shape, btheta_nonpar_strat.shape, btheta_param.shape)"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 10,
-   "id": "cf651adb",
+   "execution_count": null,
+   "id": "7b38615a",
    "metadata": {},
    "outputs": [
     {
@@ -1354,8 +1329,8 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 11,
-   "id": "2008c950",
+   "execution_count": null,
+   "id": "ad4ff783",
    "metadata": {},
    "outputs": [
     {
@@ -1503,7 +1478,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "35aecc30",
+   "id": "90a08ec8",
    "metadata": {},
    "source": [
     "## Comparison of confidence bands\n",
@@ -1513,8 +1488,8 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 12,
-   "id": "1ca796d8",
+   "execution_count": null,
+   "id": "8d2de35f",
    "metadata": {},
    "outputs": [
     {
@@ -1540,9 +1515,7 @@
     "ax.plot(xp, logit.model(xp, theta), color='black', lw=2, label='logistic fit', zorder=5)\n",
     "\n",
     "bands = [\n",
-    "    ('normal', logit.get_model_quantiles_normal(\n",
-    "        xp, probs, theta, cov_theta, seed=random_seed\n",
-    "    ), 'tab:red'),\n",
+    "    ('normal', logit.get_model_quantiles_normal(xp, probs, theta, cov_theta), 'tab:red'),\n",
     "    ('delta', logit.get_model_quantiles_delta(xp, probs, theta, cov_theta), 'tab:green'),\n",
     "    ('non-parametric bootstrap', bootstrap_band(xp, btheta_nonpar, probs), 'tab:blue'),\n",
     "    ('stratified bootstrap', bootstrap_band(xp, btheta_nonpar_strat, probs), 'tab:purple'),\n",

BIN
results/logit_all_models/cubic_monotonic/logit_mono_asymptotic_fit.pdf


BIN
results/logit_all_models/cubic_monotonic/logit_mono_ci_comparison.pdf


BIN
results/logit_all_models/cubic_unconstrained/logit_cubic_nonmono_fit.pdf


BIN
results/logit_all_models/linear/logit_linear_fit.pdf


Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor