Skip to content

Commit

Permalink
Update notebooks and add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarandas committed Oct 27, 2021
1 parent 9f3a332 commit aa2ca93
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 101 deletions.
63 changes: 18 additions & 45 deletions notebooks/Query search - 1D.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,10 @@
"metadata": {},
"outputs": [],
"source": [
"tq, query = np.loadtxt(\"query_ecg_2.txt\")\n",
"ts, sequence = np.loadtxt(\"sequence_ecg_2.txt\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# sequence = sequence[:-500]\n",
"# ts = ts[:-500]"
"dict_ecg = tssearch.load_ecg_example()\n",
"\n",
"tq, query = dict_ecg['tq'], dict_ecg['query']\n",
"ts, sequence = dict_ecg['ts'], dict_ecg['sequence']"
]
},
{
Expand All @@ -48,7 +40,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -84,7 +76,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand All @@ -96,7 +88,7 @@
" 'parameters': ''}}}"
]
},
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -135,7 +127,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"metadata": {
"scrolled": false
},
Expand Down Expand Up @@ -180,36 +172,17 @@
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"from scipy.signal import find_peaks\n",
"\n",
"# sequence - change T wave\n",
"pks = find_peaks(sequence, height=25)\n",
"sequence_copy = sequence.copy()\n",
"for pk in pks[0][1:-1:2]:\n",
" miu = np.random.choice(np.arange(0,20))\n",
" sequence_copy[pk-5:pk+5] = np.random.normal(miu, 7, 10)\n",
"\n",
"# query weight\n",
"weight = 1 - np.exp(-((np.arange(len(query)) - 40) / 5) ** 2)\n",
"weight[weight < 0.1] = 0.1"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"\n"
"sequence_copy = dict_ecg['sequence_noise'] \n",
"weight = dict_ecg['weight']"
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -240,7 +213,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand All @@ -252,7 +225,7 @@
" <AxesSubplot:xlabel='Distance'>], dtype=object)]"
]
},
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -289,7 +262,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -346,7 +319,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -357,7 +330,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -366,7 +339,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 12,
"metadata": {},
"outputs": [
{
Expand Down
65 changes: 16 additions & 49 deletions notebooks/Query search - Steps.ipynb

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions notebooks/Segmentation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
"metadata": {},
"outputs": [],
"source": [
"tq, query = np.loadtxt(\"query_ecg_2.txt\")\n",
"ts, sequence = np.loadtxt(\"sequence_ecg_2.txt\")"
"dict_ecg = tssearch.load_ecg_example()\n",
"\n",
"tq, query = dict_ecg['tq'], dict_ecg['query']\n",
"ts, sequence = dict_ecg['ts'], dict_ecg['sequence']"
]
},
{
Expand Down Expand Up @@ -100,7 +102,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down
2 changes: 0 additions & 2 deletions notebooks/query_ecg_2.txt

This file was deleted.

2 changes: 0 additions & 2 deletions notebooks/sequence_ecg_2.txt

This file was deleted.

1 change: 1 addition & 0 deletions tssearch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from tssearch.utils import *
from tssearch.search import *
from tssearch.distances import *
from tssearch.examples import *
1 change: 1 addition & 0 deletions tssearch/examples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from tssearch.examples.ecg_example_data import *
Binary file added tssearch/examples/ecg.pickle
Binary file not shown.
12 changes: 12 additions & 0 deletions tssearch/examples/ecg_example_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import tssearch
import pickle
import numpy as np


def load_ecg_example():

filename = tssearch.__path__[0] + '/examples/ecg.pickle'
with open(filename, 'rb') as handle:
data = pickle.load(handle)

return data

0 comments on commit aa2ca93

Please sign in to comment.