Skip to content

Commit

Permalink
update vae to hydra config
Browse files Browse the repository at this point in the history
  • Loading branch information
thatgeeman committed Nov 24, 2024
1 parent 9b47006 commit 8759987
Show file tree
Hide file tree
Showing 10 changed files with 993 additions and 745 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ verify_ssl = true
name = "downloadpytorch"

[packages]
numpy = "*"
numpy = "==1.26"
pandas = "*"
nbdev = "*"
fastcore = "*"
Expand Down
382 changes: 186 additions & 196 deletions Pipfile.lock

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,27 @@ defaults:
base_dir: ..
model_dir: ${base_dir}/models
num_workers: 4
device: cuda

# dataset and dataloader params
n_lag: 48
n_signals: 1
test_split: 0.2
batch_sz: 8
drop_last: true

# VAE params
latent_dim: 24
num_hidden_units: 512
kernel_size: 5 # kernel size would be (kernel_size, n_signals)
stride: 2 # stride would be (stride, n_signals)
# training
lr: 1e-3
epochs: 50
wd: 1e-6
# scheduler
patience: 10
factor: 0.9

# LSTM params
lstm: 1
1,039 changes: 580 additions & 459 deletions nbs/01_vae.ipynb

Large diffs are not rendered by default.

82 changes: 53 additions & 29 deletions nbs/10_concepts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@
"outputs": [],
"source": [
"# | export\n",
"import numpy as np"
"import numpy as np\n",
"from sklearn.utils import check_array"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"# | hide\n",
"from nbdev.showdoc import *"
"from nbdev.showdoc import *\n"
]
},
{
Expand Down Expand Up @@ -115,7 +116,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -131,15 +132,20 @@
" start_step = end_step - window_size\n",
" indices = np.asarray(range(0, len(x))) if indices is None else indices\n",
" if return_indices:\n",
" return indices[start_step:end_step]\n",
" window = indices[start_step:end_step]\n",
" else:\n",
" return x[indices[start_step:end_step], :]\n",
" # x of shape (num_features, feature_len)"
" window = x[indices[start_step:end_step]]\n",
"\n",
" # x of shape (num_features, feature_len)\n",
" try:\n",
" return check_array(window, ensure_2d=True)\n",
" except ValueError:\n",
" return window.reshape(-1, 1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 29,
"metadata": {},
"outputs": [
{
Expand All @@ -148,7 +154,7 @@
"(100, 1)"
]
},
"execution_count": null,
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -159,16 +165,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([90, 91, 92, 93, 94, 95, 96, 97, 98, 99])"
"array([[90],\n",
" [91],\n",
" [92],\n",
" [93],\n",
" [94],\n",
" [95],\n",
" [96],\n",
" [97],\n",
" [98],\n",
" [99]])"
]
},
"execution_count": null,
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -190,7 +205,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 31,
"metadata": {},
"outputs": [
{
Expand All @@ -199,7 +214,7 @@
"90"
]
},
"execution_count": null,
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -211,16 +226,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 32,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
"array([[0],\n",
" [1],\n",
" [2],\n",
" [3],\n",
" [4],\n",
" [5],\n",
" [6],\n",
" [7],\n",
" [8],\n",
" [9]])"
]
},
"execution_count": null,
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -238,7 +262,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -254,22 +278,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 34,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"time series index starting at 0 and ending at 9 has label 1\n",
"time series index starting at 10 and ending at 19 has label 0\n",
"time series index starting at 20 and ending at 29 has label 0\n",
"time series index starting at 30 and ending at 39 has label 0\n",
"time series index starting at 40 and ending at 49 has label 0\n",
"time series index starting at 50 and ending at 59 has label 0\n",
"time series index starting at 60 and ending at 69 has label 0\n",
"time series index starting at 70 and ending at 79 has label 0\n",
"time series index starting at 80 and ending at 89 has label 0\n"
"time series index starting at [0] and ending at [9] has label 1\n",
"time series index starting at [10] and ending at [19] has label 0\n",
"time series index starting at [20] and ending at [29] has label 0\n",
"time series index starting at [30] and ending at [39] has label 0\n",
"time series index starting at [40] and ending at [49] has label 0\n",
"time series index starting at [50] and ending at [59] has label 0\n",
"time series index starting at [60] and ending at [69] has label 0\n",
"time series index starting at [70] and ending at [79] has label 0\n",
"time series index starting at [80] and ending at [89] has label 0\n"
]
}
],
Expand Down Expand Up @@ -304,7 +328,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
Expand Down
1 change: 1 addition & 0 deletions ts_vae_lstm/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@
'ts_vae_lstm.vae.VAE': ('vae.html#vae', 'ts_vae_lstm/vae.py'),
'ts_vae_lstm.vae.VAE.__init__': ('vae.html#vae.__init__', 'ts_vae_lstm/vae.py'),
'ts_vae_lstm.vae.VAE.forward': ('vae.html#vae.forward', 'ts_vae_lstm/vae.py'),
'ts_vae_lstm.vae.as_df': ('vae.html#as_df', 'ts_vae_lstm/vae.py'),
'ts_vae_lstm.vae.evaluate_reconstruction': ('vae.html#evaluate_reconstruction', 'ts_vae_lstm/vae.py'),
'ts_vae_lstm.vae.validate_epoch': ('vae.html#validate_epoch', 'ts_vae_lstm/vae.py')}}}
2 changes: 2 additions & 0 deletions ts_vae_lstm/ad_complete.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Fill in a module description here"""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/03_ad_complete.ipynb.

# %% auto 0
Expand Down
12 changes: 10 additions & 2 deletions ts_vae_lstm/concepts.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"""Fill in a module description here"""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/10_concepts.ipynb.

# %% auto 0
__all__ = ['get_window']

# %% ../nbs/10_concepts.ipynb 2
import numpy as np
from sklearn.utils import check_array

# %% ../nbs/10_concepts.ipynb 8
def get_window(x, window_size=10, end_step=100, indices=None, return_indices=True):
Expand All @@ -16,7 +19,12 @@ def get_window(x, window_size=10, end_step=100, indices=None, return_indices=Tru
start_step = end_step - window_size
indices = np.asarray(range(0, len(x))) if indices is None else indices
if return_indices:
return indices[start_step:end_step]
window = indices[start_step:end_step]
else:
return x[indices[start_step:end_step], :]
window = x[indices[start_step:end_step]]

# x of shape (num_features, feature_len)
try:
return check_array(window, ensure_2d=True)
except ValueError:
return window.reshape(-1, 1)
2 changes: 2 additions & 0 deletions ts_vae_lstm/lstm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Fill in a module description here"""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/02_lstm.ipynb.

# %% auto 0
Expand Down
Loading

0 comments on commit 8759987

Please sign in to comment.