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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ coverage.xml
.hypothesis/
.pytest_cache/
cover/

.idea
# Translations
*.mo
*.pot
Expand Down Expand Up @@ -99,7 +99,7 @@ ipython_config.py
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
# https://python-potrain_observablesetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
Expand Down
126 changes: 99 additions & 27 deletions docs/examples/ala2_nys_tutorial.ipynb

Large diffs are not rendered by default.

257 changes: 226 additions & 31 deletions docs/examples/context_windows.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ContextWindow <context_length=19, data=['t', 'h', 'e', '_', 'q', 'u', 'i', 'c', 'k', '_', 'b', 'r', 'o', 'w', 'n', '_', 'f', 'o', 'x']>\n"
]
}
],
"source": [
"from kooplearn.abc import ContextWindow\n",
"\n",
Expand All @@ -55,9 +63,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"19"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"context_window.context_length"
]
Expand All @@ -77,9 +96,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Lookback window: ['t', 'h', 'e', '_', 'q', 'u', 'i', 'c', 'k', '_']\n",
"Lookforward window: ['b', 'r', 'o', 'w', 'n', '_', 'f', 'o', 'x']\n"
]
}
],
"source": [
"lookback_length = 10\n",
"\n",
Expand All @@ -101,9 +129,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Shifted lookback window: ['q', 'u', 'i', 'c', 'k', '_', 'b', 'r', 'o', 'w']\n",
"ValueError: Invalid slide_by = 15 for lookback_length = 10 and Context of length = 19. It should be 0 <= slide_by <= context_length - lookback_length\n"
]
}
],
"source": [
"# Skip the first 4 elements\n",
"shifted_lb_window = context_window.lookback(lookback_length, slide_by=4) \n",
Expand All @@ -128,9 +165,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Arbitrary slice: ['e', 'q', 'i', 'k', 'b', 'o', 'n']\n"
]
}
],
"source": [
"slice_obj = slice(2, 16, 2) # (start, stop, step) \n",
"context_slice = context_window.slice(slice_obj)\n",
Expand All @@ -148,9 +193,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ContextWindowDataset <item_count=3, context_length=5, data=[[1, 2, 3, 4, 5], ['a', 'b', 'c', 'd', 'e'], ['a', 1.0, True, 'd', 5]]>\n"
]
}
],
"source": [
"from kooplearn.abc import ContextWindowDataset\n",
" \n",
Expand All @@ -173,9 +226,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Lookback window: [[1, 2], ['a', 'b'], ['a', 1.0]]\n",
"Lookforward window: [[3, 4, 5], ['c', 'd', 'e'], [True, 'd', 5]]\n",
"Shifted lookback window: [[3, 4], ['c', 'd'], [True, 'd']]\n",
"Arbitrary slice: [[2, 3, 4], ['b', 'c', 'd'], [1.0, True, 'd']]\n"
]
}
],
"source": [
"lookback_length = 2\n",
"\n",
Expand All @@ -202,9 +266,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ContextWindow <context_length=5, data=[1, 2, 3, 4, 5]>\n",
"ContextWindow <context_length=5, data=['a', 'b', 'c', 'd', 'e']>\n",
"ContextWindow <context_length=5, data=['a', 1.0, True, 'd', 5]>\n"
]
}
],
"source": [
"for ctx in contexts:\n",
" print(ctx)"
Expand All @@ -221,9 +295,62 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TensorContextDataset <item_count=3, context_length=5, data=[[[[0.63696169 0.26978671]\n",
" [0.04097352 0.01652764]]\n",
"\n",
" [[0.81327024 0.91275558]\n",
" [0.60663578 0.72949656]]\n",
"\n",
" [[0.54362499 0.93507242]\n",
" [0.81585355 0.0027385 ]]\n",
"\n",
" [[0.85740428 0.03358558]\n",
" [0.72965545 0.17565562]]\n",
"\n",
" [[0.86317892 0.54146122]\n",
" [0.29971189 0.42268722]]]\n",
"\n",
"\n",
" [[[0.02831967 0.12428328]\n",
" [0.67062441 0.64718951]]\n",
"\n",
" [[0.61538511 0.38367755]\n",
" [0.99720994 0.98083534]]\n",
"\n",
" [[0.68554198 0.65045928]\n",
" [0.68844673 0.38892142]]\n",
"\n",
" [[0.13509651 0.72148834]\n",
" [0.52535432 0.31024188]]\n",
"\n",
" [[0.48583536 0.88948783]\n",
" [0.93404352 0.3577952 ]]]\n",
"\n",
"\n",
" [[[0.57152983 0.32186939]\n",
" [0.59430003 0.33791123]]\n",
"\n",
" [[0.391619 0.89027435]\n",
" [0.22715759 0.62318714]]\n",
"\n",
" [[0.08401534 0.83264415]\n",
" [0.78709831 0.23936944]]\n",
"\n",
" [[0.87648423 0.05856803]\n",
" [0.33611706 0.15027947]]\n",
"\n",
" [[0.45033937 0.79632427]\n",
" [0.23064221 0.0520213 ]]]]>\n"
]
}
],
"source": [
"import numpy as np\n",
"import torch\n",
Expand Down Expand Up @@ -252,9 +379,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The original data is of type <class 'numpy.ndarray'>\n",
"The data in complex_torch_contexts is of type <class 'torch.Tensor'>\n",
"The original dtype is float64\n",
"The data in complex_torch_contexts is of dtype torch.complex64\n"
]
}
],
"source": [
"complex_torch_contexts = TensorContextDataset(np_raw_contexts, backend='torch', dtype=torch.cfloat)\n",
"\n",
Expand All @@ -281,9 +419,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0. 1. 2. 3. 4. 5.]\n",
"TrajectoryContextDataset <item_count=3, context_length=4, data=[[[0.]\n",
" [1.]\n",
" [2.]\n",
" [3.]]\n",
"\n",
" [[1.]\n",
" [2.]\n",
" [3.]\n",
" [4.]]\n",
"\n",
" [[2.]\n",
" [3.]\n",
" [4.]\n",
" [5.]]]>\n"
]
}
],
"source": [
"from kooplearn.data import TrajectoryContextDataset\n",
"\n",
Expand All @@ -303,9 +463,51 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Lookback window: [[[0.]\n",
" [1.]]\n",
"\n",
" [[1.]\n",
" [2.]]\n",
"\n",
" [[2.]\n",
" [3.]]]\n",
"Lookforward window: [[[2.]\n",
" [3.]]\n",
"\n",
" [[3.]\n",
" [4.]]\n",
"\n",
" [[4.]\n",
" [5.]]]\n",
"Shifted lookback window: [[[2.]\n",
" [3.]]\n",
"\n",
" [[3.]\n",
" [4.]]\n",
"\n",
" [[4.]\n",
" [5.]]]\n",
"Arbitrary slice: [[[1.]\n",
" [2.]\n",
" [3.]]\n",
"\n",
" [[2.]\n",
" [3.]\n",
" [4.]]\n",
"\n",
" [[3.]\n",
" [4.]\n",
" [5.]]]\n"
]
}
],
"source": [
"lookback_length = 2\n",
"\n",
Expand All @@ -322,13 +524,6 @@
"print(f\"Shifted lookback window: {shifted_lb_window}\") \n",
"print(f\"Arbitrary slice: {context_slice}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
81 changes: 44 additions & 37 deletions docs/examples/kernel_methods.ipynb

Large diffs are not rendered by default.

Loading