A Numba version of TWED
Project description
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 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
prangefor large-scale time series.
Installation
-
Clone the repository:
git clone https://github.com/yourusername/twed-library.git cd twed-library
-
Create a virtual environment (optional but recommended):
python -m venv env source env/bin/activate # On Windows: env\Scripts\activate
-
Install the required dependencies:
pip install numpy pandas numba
Example usage with Numpy arrays
import numpy as np
from twed import twed # assuming the main file is named twed.py
# 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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fast_twed-0.0.0.tar.gz.
File metadata
- Download URL: fast_twed-0.0.0.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4cf8429f147e739d2a692ff1dfab8ab09b0510acba6e39e8356b542e2811b02d
|
|
| MD5 |
c1d41f4eb44e853ac11302d02763007b
|
|
| BLAKE2b-256 |
5be75ee5fead060d1b69d4ade2ac7843c2d1ac0e8ff86179205f30310f3e8c2f
|
File details
Details for the file fast_twed-0.0.0-py3-none-any.whl.
File metadata
- Download URL: fast_twed-0.0.0-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
267baa6dd35e255bf19e8cc2b1884f609d5a5cc2ce8c1b06771cae49b528731f
|
|
| MD5 |
f104bf180190c22f497c1171aca49563
|
|
| BLAKE2b-256 |
a24e3f42ea51d3e75c64eaf679aaa5dfb31cbd505f3fca27ef597270910b3656
|