Skip to content

Commit

Permalink
Tested CI with typechecking
Browse files Browse the repository at this point in the history
  • Loading branch information
iuliivasilev committed Aug 4, 2024
1 parent 7f143e4 commit 630acff
Showing 1 changed file with 66 additions and 21 deletions.
87 changes: 66 additions & 21 deletions demonstration/Articles/Refactoring.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"cell_type": "code",
"execution_count": 78,
"id": "374b961a",
"id": "49b2156d",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -14,7 +14,7 @@
{
"cell_type": "code",
"execution_count": 3,
"id": "9a9f032a",
"id": "2a46605a",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -110,7 +110,7 @@
{
"cell_type": "code",
"execution_count": 22,
"id": "17768980",
"id": "75e8e27c",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -158,8 +158,8 @@
},
{
"cell_type": "code",
"execution_count": 79,
"id": "eb902005",
"execution_count": 98,
"id": "9847863b",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -199,8 +199,53 @@
},
{
"cell_type": "code",
"execution_count": 80,
"id": "3e4acf25",
"execution_count": null,
"id": "8ad4da3a",
"metadata": {},
"outputs": [],
"source": [
"@njit\n",
"def get_pairs(T, P, E):\n",
" n = len(T)\n",
" concordant_pairs = 0\n",
" total_pairs = 0\n",
" for i in range(n):\n",
" for j in range(i + 1, n):\n",
" if E[i] == 1 and T[i] <= T[j]:\n",
" total_pairs += 1\n",
" if P[i] < P[j]:\n",
" concordant_pairs += 1\n",
" elif P[i] == P[j]:\n",
" concordant_pairs += 0.5\n",
" return concordant_pairs, total_pairs\n",
"\n",
"def concordance_index_self(T, P, E):\n",
" \"\"\"\n",
" Calculates the concordance index (C-index) for survival analysis.\n",
"\n",
" Args:\n",
" T: Array of true event times.\n",
" P: Array of predicted event times.\n",
" E: Array of event indicators (1 if event occurred, 0 if censored).\n",
"\n",
" Returns:\n",
" The concordance index.\n",
" \"\"\"\n",
" order = np.argsort(T)\n",
" P = np.array(P)[order]\n",
" T = np.array(T)[order]\n",
" E = np.array(E)[order]\n",
" concordant_pairs, total_pairs = get_pairs(T, P, E)\n",
" \n",
" if total_pairs == 0:\n",
" return 0\n",
" return concordant_pairs / total_pairs\n"
]
},
{
"cell_type": "code",
"execution_count": 93,
"id": "051083de",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -212,12 +257,12 @@
},
{
"cell_type": "code",
"execution_count": 71,
"id": "7ab1c5b3",
"execution_count": 99,
"id": "7f5b0643",
"metadata": {},
"outputs": [],
"source": [
"for i in range(1000):\n",
"for i in range(10000):\n",
" a = np.random.rand(100)*100\n",
" b = np.random.rand(100)*100\n",
" e = np.round(np.random.rand(100))\n",
Expand All @@ -227,8 +272,8 @@
},
{
"cell_type": "code",
"execution_count": 81,
"id": "6995ee3e",
"execution_count": 95,
"id": "d6fdf195",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -244,15 +289,15 @@
},
{
"cell_type": "code",
"execution_count": 82,
"id": "64fde2e0",
"execution_count": 89,
"id": "d7ba9fdc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"672 ms ± 2.16 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
"667 ms ± 2.49 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
]
}
],
Expand All @@ -262,15 +307,15 @@
},
{
"cell_type": "code",
"execution_count": 83,
"id": "85e2e7b0",
"execution_count": 100,
"id": "3efaefab",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"22.9 ms ± 197 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
"22.9 ms ± 84.8 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
Expand All @@ -281,7 +326,7 @@
{
"cell_type": "code",
"execution_count": 84,
"id": "91add654",
"id": "2da0a02b",
"metadata": {},
"outputs": [
{
Expand All @@ -302,7 +347,7 @@
{
"cell_type": "code",
"execution_count": 52,
"id": "08d95f7f",
"id": "623deba5",
"metadata": {},
"outputs": [
{
Expand All @@ -325,7 +370,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "69e4e1bf",
"id": "0defdd05",
"metadata": {},
"outputs": [],
"source": []
Expand Down

0 comments on commit 630acff

Please sign in to comment.