Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
minor fixes
  • Loading branch information
NimaSarajpoor committed Nov 27, 2023
commit 53f73469d1385e6da98aad5e2a0fc119af224f38
77 changes: 35 additions & 42 deletions docs/Tutorial_DAMP.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"id": "c9564cff",
"metadata": {},
"outputs": [],
Expand All @@ -69,7 +69,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 18,
"id": "409dad09",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -128,14 +128,14 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"id": "c21c4587",
"metadata": {},
"outputs": [],
"source": [
"def next_pow2(val):\n",
" \"\"\"\n",
" Compute the smallest \"power of two\" number that is greater than/ equal to `v`\n",
" Compute the smallest \"power of two\" number that is greater than/ equal to `val`\n",
" \n",
" Parameters\n",
" ----------\n",
Expand All @@ -152,7 +152,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 19,
"id": "dd1f7b3d",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -214,15 +214,15 @@
" out.append([max(chunk_start, start), chunk_stop])\n",
" chunk_stop = chunk_start + m - 1\n",
" \n",
" if chunk_start <= 0:\n",
" if chunk_start <= start:\n",
" break\n",
" \n",
" return np.array(out)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 20,
"id": "5e45d72c",
"metadata": {},
"outputs": [
Expand All @@ -235,7 +235,7 @@
" [ 0, 56]])"
]
},
"execution_count": 6,
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -256,7 +256,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"id": "79663447",
"metadata": {},
"outputs": [],
Expand All @@ -269,8 +269,8 @@
" M_T, \n",
" Σ_T, \n",
" T_subseq_isconstant, \n",
" chunks_range,\n",
" bsf,\n",
" chunks_range=None,\n",
"):\n",
" \"\"\"\n",
" Compute the (approximate) distance between the subsequence `T[query_idx:query_idx+m]`\n",
Expand Down Expand Up @@ -300,13 +300,13 @@
" A numpy boolean array whose i-th element indicates whether the subsequence\n",
" `T[i : i+m]` is constant (True)\n",
" \n",
" bsf : float\n",
" The best-so-far discord distance\n",
" \n",
" chunks_range : numpy.ndarray, default None\n",
" chunks_range : numpy.ndarray\n",
" A 2D numpy array consisting of rows, each represents\n",
" the (start, stop) range of a chunk\n",
" \n",
" bsf : float\n",
" The best-so-far discord distance\n",
" \n",
" Returns\n",
" -------\n",
" nn_distance : float\n",
Expand All @@ -316,11 +316,6 @@
" bsf : float\n",
" The best-so-far discord distance \n",
" \"\"\"\n",
" if chunks_range is None:\n",
" # The avoid the trivial (left) neighbors of `T[query_idx : query_idx+m]`,\n",
" # the stop index of non-trivial subsequences is `query_idx - excl_zone + m`\n",
" chunks_range = naive_get_range_damp(query_idx - excl_zone + m, m, start=0)\n",
" \n",
" nn_distance = np.inf\n",
" for (start, stop) in chunks_range:\n",
" QT = core.sliding_dot_product(\n",
Expand Down Expand Up @@ -350,7 +345,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 21,
"id": "c76317b5",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -429,7 +424,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 32,
"id": "769bddad",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -470,7 +465,6 @@
" \n",
" excl_zone = int(math.ceil(m / stumpy.core.config.STUMPY_EXCL_ZONE_DENOM))\n",
" chunks_range = get_damp_range(split_idx - excl_zone + m, m, start=0)\n",
" \n",
" last_chunk_size = chunks_range[-1, 1] - chunks_range[-1, 0]\n",
" last_chunk_size_cutoff = next_pow2(last_chunk_size)\n",
" \n",
Expand All @@ -487,14 +481,13 @@
" excl_zone, \n",
" M_T, \n",
" Σ_T, \n",
" T_subseq_isconstant, \n",
" bsf, \n",
" chunks_range=chunks_range\n",
" T_subseq_isconstant, \n",
" chunks_range,\n",
" bsf,\n",
" )\n",
" _foreward_process(T, m, excl_zone, M_T, Σ_T, T_subseq_isconstant, i, lookahead, PL)\n",
" \n",
" chunks_range = chunks_range + 1 \n",
" # make a decision on whether to create new chunk or not for the subsequence [0, m]\n",
" chunks_range[:] = chunks_range + 1 \n",
" if last_chunk_size < last_chunk_size_cutoff:\n",
" chunks_range[-1, 0] = 0 \n",
" last_chunk_size += 1\n",
Expand All @@ -521,7 +514,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 23,
"id": "2cfbc771",
"metadata": {},
"outputs": [],
Expand All @@ -536,7 +529,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 24,
"id": "a935f31f",
"metadata": {},
"outputs": [
Expand All @@ -546,7 +539,7 @@
"text": [
"discord_dist: 8.500883427933504\n",
"discord_index: 209\n",
"running time [sec]: 5.248243093490601\n"
"running time [sec]: 4.881464958190918\n"
]
}
],
Expand All @@ -566,7 +559,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 25,
"id": "2b461592",
"metadata": {},
"outputs": [
Expand All @@ -576,7 +569,7 @@
"text": [
"discord_dist: 8.500883427933504\n",
"discord_index: 209\n",
"running time [sec]: 2.2584328651428223\n"
"running time [sec]: 2.2210960388183594\n"
]
}
],
Expand Down Expand Up @@ -605,7 +598,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 26,
"id": "d8e9fa63",
"metadata": {},
"outputs": [],
Expand All @@ -620,7 +613,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 27,
"id": "263bca9c",
"metadata": {},
"outputs": [
Expand All @@ -630,7 +623,7 @@
"text": [
"discord_dist: 7.606279752022369\n",
"discord_index: 8109\n",
"running time [sec]: 5.100044012069702\n"
"running time [sec]: 4.996989965438843\n"
]
}
],
Expand All @@ -651,7 +644,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 28,
"id": "78d09bda",
"metadata": {},
"outputs": [
Expand All @@ -661,7 +654,7 @@
"text": [
"discord_dist: 7.606279752022363\n",
"discord_index: 8109\n",
"running time [sec]: 6.70897912979126\n"
"running time [sec]: 6.67956805229187\n"
]
}
],
Expand Down Expand Up @@ -690,7 +683,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 33,
"id": "6d64f488",
"metadata": {},
"outputs": [],
Expand All @@ -705,7 +698,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 34,
"id": "159e03dc",
"metadata": {},
"outputs": [
Expand All @@ -715,7 +708,7 @@
"text": [
"discord_dist: 29.42331306408431\n",
"discord_index: 6110\n",
"running time [sec]: 5.572257995605469\n"
"running time [sec]: 5.483174085617065\n"
]
}
],
Expand All @@ -736,7 +729,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 35,
"id": "9ef28e10",
"metadata": {},
"outputs": [
Expand All @@ -746,7 +739,7 @@
"text": [
"discord_dist: 29.423313064084333\n",
"discord_index: 6110\n",
"running time [sec]: 55.545814990997314\n"
"running time [sec]: 55.60335397720337\n"
]
}
],
Expand Down