Skip to main content

A package for unsupervised representation and principal component analysis of irregularly sampled time series with variable size relying on the shape analysis literature.

Project description

PCA for time series

Authors: Samuel Gruffaz, Thibaut Germain

This repository gathers the functions developed in the paper “Shape Analysis for Time Series”, located in the src directory.

It is possible to represent irregularly sampled time series of different lengths and to apply kernel PCA to these representations in order to identify the main modes of shape variation in the time series.

These methods work particularly well when the analyzed dataset is homogeneous in terms of shapes, for example when each time series corresponds to:

  • a heartbeat recording,
  • a respiratory cycle,
  • an electricity consumption pattern,
  • or a heating load curve.

Dataset format

The main requirement is to represent the time series dataset as a collection of time series graphs. Each time series graph should be an array T of shape (n_samples, d+1), where T[:, 0] contains the time points, and T[:, 1:] contains the time series values of dimension d.

The full dataset should be an array of fixed shape (n_time_series, n_samples_max, d+1) along with a corresponding mask of shape (n_time_series, n_samples_max, 1), where n_samples_max is the maximum number of samples among all time series. This accommodates the fact that each time series may have a different number of samples.

Default parameters work well when the distance between two consecutive time points is approximately 1.

TS-PCA: Basic Usage Example

This example demonstrates the basic workflow of using the TS-PCA package to analyze time-series data using TS-LDDMM representations and Kernel PCA.

# Import or generate a toy dataset,
N = 8
dataset, dataset_mask, graph_ref, graph_ref_mask = generate_easy_dataset(N=N)

#dataset is an array of shape (8,200,2) and dataset mask an array of shape (8,200,1)

# Initialize the TS-PCA class
class_test = TS_PCA_()

# Step 1: Fit TS-LDDMM representations
# This learns the temporal-shape embeddings of the dataset.
# Set learning_graph_ref=True to learn the reference graph; here we keep it fixed.
class_test.fit_TS_LDDMM_representations(
    dataset,
    dataset_mask,
    learning_graph_ref=False,
    graph_ref=graph_ref,
    graph_ref_mask=graph_ref_mask
)

# Step 2: Fit Kernel PCA on the learned representations
class_test.fit_kernel_PCA()

# Step 3: Visualize the principal components
class_test.plot_components()

The Docs directory contains the files used to build the package documentation.

The pages directory contains the pages used to launch a Streamlit application from the menu, allowing users to test the different building blocks of the code.

Coming next:

  • Complete documentation
  • New kernels

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ts_pca-0.0.4.tar.gz (27.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ts_pca-0.0.4-py3-none-any.whl (30.2 kB view details)

Uploaded Python 3

File details

Details for the file ts_pca-0.0.4.tar.gz.

File metadata

  • Download URL: ts_pca-0.0.4.tar.gz
  • Upload date:
  • Size: 27.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for ts_pca-0.0.4.tar.gz
Algorithm Hash digest
SHA256 d58cf344a5fbb14079d4abf26499aea6ff31d70b63fc541a8b7ce329c06891f5
MD5 4cb4bfbdd347361ee28aa7d8954ca514
BLAKE2b-256 95b2f1919b35aaf49986e7c1496b862de8b57bba4eaeb60f64407c3071c188c8

See more details on using hashes here.

File details

Details for the file ts_pca-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: ts_pca-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 30.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for ts_pca-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c8823debf79d3c7e22b4d2b7f53cf618adcaf338449f274cd51699a0fdc28b57
MD5 b01d516c296e0a869430899759379644
BLAKE2b-256 0fa2b0d795197829b179045d052b4659cf05f0b1db592ac43436c0e2b6a4485f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page