Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Time series Visualization #34

Merged
merged 6 commits into from
Feb 5, 2025
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
238 changes: 238 additions & 0 deletions examples/uastl.ipynb

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion uadapy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .distribution import Distribution
from .timeseries import TimeSeries, CorrelatedDistributions

__all__ = ['Distribution']
__all__ = ['Distribution','TimeSeries', 'CorrelatedDistributions']
48 changes: 47 additions & 1 deletion uadapy/data/data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from sklearn import datasets
import numpy as np
from uadapy import Distribution
from uadapy import Distribution, TimeSeries
from scipy import stats

def load_iris_normal():
"""
Expand All @@ -23,3 +24,48 @@ def load_iris():
for c in np.unique(iris.target):
dist.append(Distribution(np.array(iris.data[iris.target == c])))
return dist

def generate_synthetic_timeseries(timesteps=200):
"""
Generates synthetic time series data by modeling a combination of trend,
periodic patterns, and noise using a multivariate normal distribution
with an exponential quadratic kernel for covariance.

Parameters
----------
timesteps : int
The time steps of the time series.
Default value is 200.

Returns
-------
timeseries : Timeseries object
An instance of the TimeSeries class, which represents a univariate time series.
"""
np.random.seed(0)
t = np.arange(1, timesteps + 1)
trend = t / 10
periodic = 10 * np.sin(2 * np.pi * t / 100)
noise = 2 * (np.random.rand(timesteps) - 0.5)
mu = trend + periodic + noise
sigma2 = 20 * np.ones(timesteps)
sigma_sq = np.sqrt(sigma2)
sigma = np.zeros((timesteps, timesteps))

def ex_qu_kernel(x, y, sigma_i, sigma_j, l):
return sigma_i * sigma_j * np.exp(-0.5 * np.linalg.norm(x - y)**2 / l**2)

for i in range(timesteps):
for j in range(timesteps):
sigma[i, j] = ex_qu_kernel(t[i], t[j], sigma_sq[i], sigma_sq[j], 5)

# Ensure symmetry
sigma = (sigma + sigma.T) / 2

# Ensure positive definiteness
epsilon = 1e-6
sigma += np.eye(sigma.shape[0]) * epsilon
model = stats.multivariate_normal(mu, sigma)
timeseries = TimeSeries(model, timesteps)

return timeseries
Loading