Python implementation of GRAIL
Project description
GRAIL
A Python implementation of GRAIL, a generic framework to learn compact time series representations.
Requirements
- Python 3.6+
numpy
scipy
tslearn
Installation
Installation using pip:
pip install grailts
To install from the source:
python setup.py install
Main Contributors
Karhan Kayan (karhan@uchicago.edu)
Usage
Full Example
Here is an example where we load a UCR dataset and run approximate k-nearest neighbors on its GRAIL representations:
from GRAIL.TimeSeries import TimeSeries
from GRAIL.Representation import GRAIL
from GRAIL.kNN import kNN
TRAIN, train_labels = TimeSeries.load("ECG200_TRAIN", "UCR")
TEST, test_labels = TimeSeries.load("ECG200_TEST", "UCR")
representation = GRAIL(kernel="SINK", d = 100, gamma = 5)
repTRAIN, repTEST = representation.get_rep_train_test(TRAIN, TEST, exact=True)
neighbors, _, _ = kNN(repTRAIN, repTEST, method="ED", k=5, representation=None,
pq_method='opq')
print(neighbors)
Loading Datasets
To load UCR type datasets:
TRAIN, train_labels = TimeSeries.load("ECG200_TRAIN", "UCR")
TEST, test_labels = TimeSeries.load("ECG200_TEST", "UCR")
In this package, we assume that each row of the datasets is a time series.
Fetch GRAIL Representations
To fetch exact GRAIL representations of a training and a test dataset:
representation = GRAIL(kernel="SINK", d = 100, gamma = 5)
repTRAIN, repTEST = representation.get_rep_train_test(TRAIN, TEST, exact=True)
Here d
specifies the number of landmark series, and gamma
specifies the hyperparameter used for the SINK kernel. If gamma
is not specified, it will be tuned by the algorithm.
If a single dataset is used instead:
repX = representation.get_representation(X)
Get Approximate k-Nearest-Neighbors
To get the approximate k-Nearest-Neighbors of TEST
in TRAIN
use:
neighbors, correlations, return_time = kNN(repTRAIN, repTEST, method="ED", k=5, representation=None,
pq_method='opq')
Note that Euclidean Distance in the GRAIL representation space estimates the SINK correlation in the original space.
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
Built Distribution
File details
Details for the file grailts-0.1.0.tar.gz
.
File metadata
- Download URL: grailts-0.1.0.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8c5c831b9fd2b28bccf5ebf98fbce55cacba6615df41f398d69fe1dbe774ef8 |
|
MD5 | 52adae1c279e6b9f652c0146dbaa0cb8 |
|
BLAKE2b-256 | 50c6a46c9ec0580ab65b98a73f5b9851b6443c3fc06dbae7cad13ee5f8fc7b63 |
File details
Details for the file grailts-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: grailts-0.1.0-py3-none-any.whl
- Upload date:
- Size: 21.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfef2626dfd8ac6077348a42002a8c09989981791f10c10b20a9c3ec24f8546d |
|
MD5 | d0792e4e9ebe1ddfb69c85e4ed61af86 |
|
BLAKE2b-256 | 25fe2354bd3059c8469d7a827ba9ca7943b8a083fda7d4ae597621a4bd192f4e |