Exemplo n.º 1
0
def joint_recurrence_plot(df, threshold_val, percentage_val):
    """[summary]
    Input: dataframe 

    Args:
        df ([type]): [description]
    """
    result = df.copy()
    for area in tqdm_notebook(result.keys(), desc="to image"):
        X = result[area]
        X[np.isnan(X)] = -1
        X = X.to_numpy()

        arr = np.array(X[0:24].T)
        # arr = np.append(arr,arr,axis=0)
        a = int(len(X) / 24)
        for col in range(1, a):
            # print(col)
            arr = np.append(arr, X[24 * col:24 * col + 24].T, axis=0)
        X = arr.reshape(-1, 9, 24)
        # Recurrence plot transformation
        jrp = JointRecurrencePlot(threshold=threshold_val,
                                  percentage=percentage_val)
        X_jrp = jrp.fit_transform(X)
        result[area] = X_jrp

    return result
Exemplo n.º 2
0
class TSToJRP(Transform):
    r"""Transforms a time series batch to a 4d TSImage (bs, n_vars, size, size) by applying Joint Recurrence Plot"""
    order = 98

    def __init__(self, size=224, cmap=None, **kwargs):
        self.size,self.cmap = size,cmap
        self.encoder = JointRecurrencePlot(**kwargs)

    def encodes(self, o: TSTensor):
        o = to3d(o)
        bs, *_, seq_len = o.shape
        size = ifnone(self.size, seq_len)
        if size != seq_len: o = F.interpolate(o, size=size, mode='linear', align_corners=False)
        output = self.encoder.fit_transform(o.cpu().numpy()).reshape(bs, -1, size, size)
        if self.cmap and output.shape[1] == 1:
            output = TSImage(plt.get_cmap(self.cmap)(output)[..., :3]).squeeze(1).permute(0,3,1,2)
        else: output = TSImage(output)
        return output.to(device=o.device)
Exemplo n.º 3
0
def test_shapes(params, shape_desired):
    """Test that the shape of the output is the expected one."""
    transformer = JointRecurrencePlot(**params)
    assert transformer.fit(X).transform(X).shape == shape_desired
    assert transformer.fit_transform(X).shape == shape_desired
Exemplo n.º 4
0
=====================

A joint recurrence plot is an extension of recurrence plots (
implemented as :class:`pyts.image.RecurrencePlot`) for multivariate time
series. A recurrence plot is built for each feature of the multivariate
time series, then the set of recurrence plots is reduced to one single
recurrence plot using the Hadamard product.
This example illustrates this transformation. It is implemented as
:class:`pyts.multivariate.image.JointRecurrencePlot`.
"""

# Author: Johann Faouzi <*****@*****.**>
# License: BSD-3-Clause

import matplotlib.pyplot as plt
from pyts.multivariate.image import JointRecurrencePlot
from pyts.datasets import load_basic_motions

X, _, _, _ = load_basic_motions(return_X_y=True)

# Recurrence plot transformation
jrp = JointRecurrencePlot(threshold='point', percentage=50)
X_jrp = jrp.fit_transform(X)

# Show the results for the first time series
plt.figure(figsize=(5, 5))
plt.imshow(X_jrp[0], cmap='binary', origin='lower')
plt.title('Joint Recurrence Plot', fontsize=18)
plt.tight_layout()
plt.show()