Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions notebooks/kaplan_meier.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"id": "075dad06",
"metadata": {},
"outputs": [
Expand All @@ -30,7 +30,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"id": "6649f9d0",
"metadata": {},
"outputs": [],
Expand All @@ -53,7 +53,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"id": "09c2011b",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -124,14 +124,14 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"id": "f7c08980",
"metadata": {},
"outputs": [],
"source": [
"import cenreg.model.nonparametric\n",
"\n",
"dist = cenreg.model.nonparametric.kaplan_meier_estimator(df[\"time\"].values, df[\"event\"].values)"
"dist = cenreg.model.nonparametric.kaplan_meier_estimator(df[\"time\"].values.astype(float), df[\"event\"].values)"
]
},
{
Expand All @@ -144,7 +144,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"id": "7aebf393",
"metadata": {},
"outputs": [
Expand Down
19 changes: 5 additions & 14 deletions notebooks/li_watkins_yu.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,10 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 1,
"id": "458fd7ec",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
Expand All @@ -38,7 +29,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 2,
"id": "1615397c",
"metadata": {},
"outputs": [],
Expand All @@ -59,7 +50,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 3,
"id": "bf0a7543",
"metadata": {},
"outputs": [],
Expand All @@ -79,7 +70,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 4,
"id": "8c73dfeb",
"metadata": {},
"outputs": [
Expand Down
31 changes: 11 additions & 20 deletions notebooks/nn_ic_log.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,18 @@
},
{
"cell_type": "code",
"execution_count": 103,
"execution_count": 1,
"id": "34da57fc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": 104,
"execution_count": 2,
"id": "0371fda9",
"metadata": {},
"outputs": [],
Expand All @@ -57,7 +48,7 @@
},
{
"cell_type": "code",
"execution_count": 105,
"execution_count": 3,
"id": "cabba736",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -101,7 +92,7 @@
},
{
"cell_type": "code",
"execution_count": 106,
"execution_count": 4,
"id": "1385c74b",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -155,7 +146,7 @@
},
{
"cell_type": "code",
"execution_count": 107,
"execution_count": 5,
"id": "4c810bf4",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -215,7 +206,7 @@
},
{
"cell_type": "code",
"execution_count": 108,
"execution_count": 6,
"id": "65de15bf",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -247,7 +238,7 @@
},
{
"cell_type": "code",
"execution_count": 109,
"execution_count": 7,
"id": "d57af800",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -281,7 +272,7 @@
},
{
"cell_type": "code",
"execution_count": 110,
"execution_count": 8,
"id": "596ac944",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -330,7 +321,7 @@
},
{
"cell_type": "code",
"execution_count": 111,
"execution_count": 9,
"id": "2c9d35a4",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -361,7 +352,7 @@
},
{
"cell_type": "code",
"execution_count": 114,
"execution_count": 10,
"id": "a7f84c10",
"metadata": {},
"outputs": [
Expand Down
22 changes: 6 additions & 16 deletions notebooks/sc_net.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 10,
"id": "b050886e",
"metadata": {},
"outputs": [
Expand All @@ -361,20 +361,10 @@
"CJD-Brier 0.9616783072036734\n",
"CJD-Logarithmic 3.6927649835189023\n",
"CJD-KS 0.2863711858453328\n",
"NLL-SC 4.885996452186602\n",
"Cen-log 0.4838524\n",
"D-calibration 0.7879467415784499\n"
]
},
{
"ename": "AttributeError",
"evalue": "module 'cenreg.metric.cdf' has no attribute 'km_calibration'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mAttributeError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[12]\u001b[39m\u001b[32m, line 38\u001b[39m\n\u001b[32m 35\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33m\"\u001b[39m\u001b[33mD-calibration\u001b[39m\u001b[33m\"\u001b[39m, dcal)\n\u001b[32m 37\u001b[39m \u001b[38;5;66;03m# Compute KM-calibration\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m38\u001b[39m kmcal = \u001b[43mcenreg\u001b[49m\u001b[43m.\u001b[49m\u001b[43mmetric\u001b[49m\u001b[43m.\u001b[49m\u001b[43mcdf\u001b[49m\u001b[43m.\u001b[49m\u001b[43mkm_calibration\u001b[49m(list_t_dist[\u001b[32m1\u001b[39m], observed_times, events, bins_np)\n\u001b[32m 39\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33m\"\u001b[39m\u001b[33mKM-calibration\u001b[39m\u001b[33m\"\u001b[39m, kmcal)\n",
"\u001b[31mAttributeError\u001b[39m: module 'cenreg.metric.cdf' has no attribute 'km_calibration'"
"NLL-SC 4.8859964377774485\n",
"Cen-log 0.37202982911557014\n",
"D-calibration 0.0005720768376036918\n",
"KM-calibration 3.5778655806086626\n"
]
}
],
Expand Down Expand Up @@ -422,7 +412,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"id": "543f50f2",
"metadata": {},
"outputs": [
Expand Down
41 changes: 25 additions & 16 deletions notebooks/ts_brier.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,27 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 12,
"id": "5d7b84bc",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 13,
"id": "ae19496a",
"metadata": {},
"outputs": [],
Expand All @@ -48,7 +57,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 14,
"id": "d9d1e139",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -108,7 +117,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 15,
"id": "b4f78464",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -185,7 +194,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 16,
"id": "c8ba9e12",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -214,7 +223,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 17,
"id": "c4d5ce80",
"metadata": {},
"outputs": [],
Expand All @@ -230,16 +239,16 @@
"\n",
"# preparation for PyTorch training\n",
"sdm = SurvDataModule(128)\n",
"train_dataloader = sdm.train_dataloader(x_train, df_train[\"time\"].values, df_train[\"event\"].values)\n",
"train_dataloader = sdm.train_dataloader(x_train, df_train[\"time\"].values.astype(float), df_train[\"event\"].values)\n",
"num_bins = 32\n",
"bins = torch.tensor(cenreg.utils.create_bins(df[\"time\"].max(), 0.0, num_bins))\n",
"bins = torch.tensor(cenreg.utils.create_bins(df[\"time\"].max().astype(float), 0.0, num_bins))\n",
"loss_fn = Brier(bins, 2)\n",
"model = MLP(x_train.shape[1], num_bins*2, 64)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 18,
"id": "2e5f8205",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -285,7 +294,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 19,
"id": "3429b83c",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -321,7 +330,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 20,
"id": "62b4f42e",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -390,7 +399,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 21,
"id": "a3cbdc55",
"metadata": {},
"outputs": [
Expand All @@ -401,7 +410,7 @@
"CJD-Brier 0.6394180830320167\n",
"CJD-Logarithmic 2.379232\n",
"CJD-KS 0.1807599546171742\n",
"NLL-SC 6.258204767185328\n"
"NLL-SC 6.533535194080549\n"
]
}
],
Expand All @@ -411,7 +420,7 @@
"import cenreg.model.copula_np\n",
"\n",
"cjd_pred = cjd_pred.reshape(-1, num_bins * 2)\n",
"observed_times = df_test['time'].values\n",
"observed_times = df_test['time'].values.astype(float)\n",
"events = df_test[\"event\"].astype(bool).values\n",
"bins_np = bins.detach().cpu().numpy()\n",
"\n",
Expand All @@ -436,7 +445,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 22,
"id": "5a6a98f6",
"metadata": {},
"outputs": [
Expand Down
Loading