Distance measures for time series
Project description
Experimental library for time series distances used in the DTAI Research Group.
Installation
The library can be used as a pure Python implementation. If you need a faster version of the algorithms you can make use of the included C algorithms. You might need to run make build or python setup.py build_ext --inplace to compile the included library first.
Usage
Dynamic Time Warping (DTW) Distance
from dtaidistance import dtw s1 = np.array([0., 0, 1, 2, 1, 0, 1, 0, 0, 2, 1, 0, 0]) s2 = np.array([0., 1, 2, 3, 1, 0, 0, 0, 2, 1, 0, 0, 0]) dtw.plot_warping(s1, s2)
DTW Distance Between Two Series
Only the distance based on two sequences of numbers:
from dtaidistance import dtw s1 = [0, 0, 1, 2, 1, 0, 1, 0, 0] s2 = [0, 1, 2, 0, 0, 0, 0, 0, 0] distance = dtw.distance(s1, s2) print(distance)
Check the __doc__ for information about the available arguments:
print(dtw.distance.__doc__)
If, next to the distance, you also want the full distance matrix:
from dtaidistance import dtw s1 = [0, 0, 1, 2, 1, 0, 1, 0, 0] s2 = [0, 1, 2, 0, 0, 0, 0, 0, 0] distance, matrix = dtw.distances(s1, s2) print(distance) print(matrix)
The fastest version (30-300 times) uses c directly but requires an array as input (with the double type):
from dtaidistance import dtw s1 = array.array('d',[0, 0, 1, 2, 1, 0, 1, 0, 0]) s2 = array.array('d',[0, 1, 2, 0, 0, 0, 0, 0, 0]) d = dtw.distance_fast(s1, s2)
Or you can use a numpy array (with dtype double or float):
from dtaidistance import dtw s1 = np.array([0, 0, 1, 2, 1, 0, 1, 0, 0], dtype=np.double) s2 = np.array([0.0, 1, 2, 0, 0, 0, 0, 0, 0]) d = dtw.distance_fast(s1, s2)
DTW Distances Between Set of Series
To compute the DTW distances between all sequences in a list of sequences, use the method dtw.distance_matrix. You can set variables to use more or less c code (use_c and use_nogil) and parallel or serial execution (parallel).
The distance_matrix method expects a list of lists/arrays or a matrix (in case all series have the same length).
from dtaidistance import dtw series = [ np.array([0, 0, 1, 2, 1, 0, 1, 0, 0], dtype=np.double), np.array([0.0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0]), np.array([0.0, 0, 1, 2, 1, 0, 0, 0])] ds = dtw.distance_matrix_fast(s) from dtaidistance import dtw series = np.matrix([ [0.0, 0, 1, 2, 1, 0, 1, 0, 0], [0.0, 1, 2, 0, 0, 0, 0, 0, 0], [0.0, 0, 1, 2, 1, 0, 0, 0, 0]]) ds = dtw.distance_matrix_fast(s)
Dependencies
Development: - pytest - pytest-benchmark
Contact
References
Mueen, A and Keogh, E, Extracting Optimal Performance from Dynamic Time Warping, Tutorial, KDD 2016
License
DTAI distance code. Copyright 2016 KU Leuven, DTAI Research Group Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
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
File details
Details for the file dtaidistance-0.1.4.tar.gz
.
File metadata
- Download URL: dtaidistance-0.1.4.tar.gz
- Upload date:
- Size: 139.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 613f18e83fb28dd2baffb35a7585b6adb48760cd79b3e5dbba691263407dc173 |
|
MD5 | f2acf448bf2c5727a88358cfd968fa00 |
|
BLAKE2b-256 | 1a07d9dafa9b2e2fa0a9ef80a711adb7ce2b5d851ad58669e558746cc9da4b89 |
File details
Details for the file dtaidistance-0.1.4-cp36-cp36m-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: dtaidistance-0.1.4-cp36-cp36m-macosx_10_12_x86_64.whl
- Upload date:
- Size: 92.9 kB
- Tags: CPython 3.6m, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f459b87cb3902a37e3702b0f0423aaa328dd939f83b04b18cd9032c4f8fd5a3 |
|
MD5 | 640a464707413af707788d5709399d8f |
|
BLAKE2b-256 | 768ecb938dab02e0bcafc7b567c806a87e764f7872f1662e2cc6a268af943157 |