Skip to main content

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

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

grailts-0.0.3.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

grailts-0.0.3-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file grailts-0.0.3.tar.gz.

File metadata

  • Download URL: grailts-0.0.3.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for grailts-0.0.3.tar.gz
Algorithm Hash digest
SHA256 08120c50c4c1ef71092790abf3da85aea3b88ae340e1f212a8da26fa16b3bec6
MD5 176f105890a6382f30f27bd8a4d8a055
BLAKE2b-256 f31ce12b9b3f4e695c34e4042afbd49493e6fcf49306e17cd71d8831fe0647e3

See more details on using hashes here.

File details

Details for the file grailts-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: grailts-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 22.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for grailts-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7fc00bcfa76e9fd37aa746b3508e77e47d93a6392a5ae7268c1d1af6dc75ed32
MD5 9b985159008818e4db65659e32b9886a
BLAKE2b-256 958d15fb27adcbb592ba56f868ba0c412de7fb3ce57f891c9f0528d879107015

See more details on using hashes here.

Supported by

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