Skip to content

Commit

Permalink
Merge branch 'main' into transformer-explainer
Browse files Browse the repository at this point in the history
  • Loading branch information
emptymalei authored Nov 7, 2024
2 parents dbeb9a8 + 9835179 commit 9ccd207
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 1 deletion.
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.14
2 changes: 2 additions & 0 deletions dl/notebooks/hierarchical_forecasting_mint.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def visualize_s_p(self, w_elements, ax):
# + id="nmCgX4OWAud0"



# + [markdown] id="C416Q_Zn7sJD"
# ## Load data
#
Expand Down Expand Up @@ -469,3 +470,4 @@ def visualize_s_p(self, w_elements, ax):
reconciliator_mint_cov.transform(ts_pred)[ca_columns].plot(linestyle="--")

# + id="uTOQnpE9Vdt7"

98 changes: 98 additions & 0 deletions dl/notebooks/time-series-data-generation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# ---
# jupyter:
# jupytext:
# text_representation:
# extension: .py
# format_name: light
# format_version: '1.5'
# jupytext_version: 1.15.2
# kernelspec:
# display_name: .venv
# language: python
# name: python3
# ---

# # Time Series Data Generation

# +
import numpy as np
import pandas as pd

import plotly.express as px


# +
def profile_sin(
t: np.ndarray,
lambda_min: float,
lambda_max: float
) -> np.ndarray:
"""generate a sin wave profile for
the expected number of visitors
in every 10min for each hour during a day
:param t: time in minutes
:param lambda_min: minimum number of visitors
:param lambda_max: maximum number of visitors
"""
amplitude = (lambda_max - lambda_min)
t_rescaled = (t - t.min())/t.max() * np.pi

return amplitude * np.sin(t_rescaled) + lambda_min


class KioskVisitors:
"""generate number of visitors for a kiosk store
:param daily_profile: expectations of visitors
in every 10min for each hour during a day
"""
def __init__(self, daily_profile: np.ndarray):
self.daily_profile = daily_profile
self.daily_segments = len(daily_profile)

def __call__(self, n_days: int) -> pd.DataFrame:
"""generate number of visitors for n_days
:param n_days: number of days to generate visitors
"""
visitors = np.concatenate([
np.random.poisson(self.daily_profile)
for _ in range(n_days)
])

df = pd.DataFrame({
"visitors": visitors,
"time": np.arange(len(visitors)),
"expectation": np.tile(self.daily_profile, n_days)
})

return df



# -

# Create a sin profile

# +
t = np.arange(0, 12 * 60/5, 1)

daily_profile = profile_sin(
t, lambda_min=0.5, lambda_max=10
)
# -

# Generate a time series data representing the number of visitors to a Kiosk.

kiosk_visitors = KioskVisitors(daily_profile=daily_profile)

df_visitors = kiosk_visitors(n_days=10)

px.line(
df_visitors,
x="time",
y=["visitors", "expectation"],
)


4 changes: 3 additions & 1 deletion dl/notebooks/tree_darts_boosted_tree.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ---
# jupyter:
# jupytext:
# formats: ipynb,py
# formats: ipynb,py:light
# text_representation:
# extension: .py
# format_name: light
Expand Down Expand Up @@ -301,6 +301,7 @@ def find_linear_trend(
# + id="HHAeUz4zSs-5"



# + [markdown] id="76W-UUf4wYGt"
# ### Metrics

Expand Down Expand Up @@ -380,3 +381,4 @@ def benchmark_predictions(
# metric_chart_grid.fig.tight_layout(w_pad=1)

# + id="tsk_WtuCW2JD"

1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ nav:
- "Forecasting with RNN": notebooks/rnn_timeseries.py
- "Forecasting with Transformer": notebooks/transformer_timeseries_univariate.py
- "Forecasting with NeuralODE": notebooks/neuralode_timeseries.py
- "Generate Time Series Using Statistics": notebooks/time-series-data-generation.py
- "Small Yet Powerful Concepts":
- concepts/index.md
- "Entropy": concepts/entropy.md
Expand Down

0 comments on commit 9ccd207

Please sign in to comment.