Skip to main content

Time Warp Edit Distance (TWED) Library

A high-performance Python library for computing the Time Warp Edit Distance (TWED) between time series [*]. This implementation leverages Numba for just-in-time (JIT) compilation, offering significant speed-ups for dynamic programming and backtracking operations. The library supports both NumPy arrays and pandas DataFrames.

Features

  • TWED Calculation: Compute the TWED between two time series using dynamic programming.
  • Edit Path Recovery: Retrieve the optimal sequence of operations (matches or deletions) that align the two time series.
  • Multi-format Support: Works with both NumPy arrays (time stamps provided as NumPy arrays or inferred by default) and pandas DataFrames (using DataFrame indices as time stamps).
  • Performance Optimizations:
    • Utilizes Numba JIT for accelerated computation.
    • Minimizes per-iteration memory allocations by replacing array operations with scalar variable comparisons.
    • Optional parallelization with Numba’s prange for large-scale time series.

Installation

  1. Clone the repository:

    git clone git@github.com:sashakolpakov/fast-twed.git
    cd fast-twed
    
  2. Create a virtual environment (optional but recommended):

    python -m venv env
    source env/bin/activate  # On Windows: env\Scripts\activate
    
  3. Install the package:

    pip install --upgrade pip # Optional
    pip install -e .
    

Example usage with Numpy arrays

import numpy as np
from twed import twed 

# Create example time series data
a = np.array([[1.0], [2.0], [3.0]])
b = np.array([[1.5], [2.5], [3.5]])

# Optionally, provide custom time stamps; otherwise, default sequential indices will be used.
ts_a = np.array([0.0, 1.0, 2.0])
ts_b = np.array([0.0, 1.0, 2.0])

# Compute TWED without the edit path
distance = twed(a, b, ts_a=ts_a, ts_b=ts_b, nu=0.001, lam=1.0)
print("TWED:", distance)

Example usage with Pandas DataFrames

import pandas as pd
from twed import twed

# Create example DataFrames; index will be used as time stamps
df_a = pd.DataFrame({'value': [1.0, 2.0, 3.0]}, index=[0.0, 1.0, 2.0])
df_b = pd.DataFrame({'value': [1.5, 2.5, 3.5]}, index=[0.0, 1.0, 2.0])

# Compute TWED and also get the optimal edit path
distance, edit_path = twed(df_a, df_b, nu=0.001, lam=1.0, path_out=True)
print("TWED:", distance)
print("Edit Path:", edit_path)

References

[*] Marteau, Pierre-François. "Time warp edit distance with stiffness adjustment for time series matching." IEEE transactions on pattern analysis and machine intelligence 31.2 (2008): 306-318; http://dx.doi.org/10.1109/TPAMI.2008.76.

Metadata

Release files for fast-twed 0.0.1.post1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fast-twed 0.0.1.post1
File Size Uploaded Provenance
fast_twed-0.0.1.post1.tar.gz 9.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for fast-twed 0.0.1.post1
File Interpreter ABI Platform
fast_twed-0.0.1.post1-py3-none-any.whl Python 3 none any Details

Total release size: 19.8 kB

Release files / fast_twed-0.0.1.post1.tar.gz

Download URL fast_twed-0.0.1.post1.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e66cbf6f577eab1d74885bf621f389b9e79cced5820f27ebc2182059663f6481
BLAKE2b-256 checksum
How to use checksums
04dc67084451636b89bfa41d86d296683e4a11e534396fb4ad470c376af1dd88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Release files / fast_twed-0.0.1.post1-py3-none-any.whl

Download URL fast_twed-0.0.1.post1-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0ee0a1d5a8ea72251a761c26a8ce1129b3821f46c932ae884b464a18f178097
BLAKE2b-256 checksum
How to use checksums
b0b8f2b7880f4ab0a446e63bd2a04120534e05984a66ba087fbb958c6d5e9684
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Security for fast-twed 0.0.1.post1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page