johannfaouzi / pyts

A Python package for time series classification
https://pyts.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.77k stars 165 forks source link

JointRecurrencePlot return zero #134

Open ramdhan1989 opened 2 years ago

ramdhan1989 commented 2 years ago

Hi, I have 5 features and 100 timesteps. JoinRecurrentPlot return all values equal to zeroes. is there anything wrong in my data?

johannfaouzi commented 2 years ago

Hi,

A joint recurrence plot is the Hadamard (element-wise) product of all the individual recurrence plots (one for each feature). Thus, for each "pixel", a zero for at least one feature will result in a zero in the joint recurrence plot. To tackle this, you can decrease the number of zeros in any recurrence plot by increasing the threshold used to binarize the distance between the trajectories.

Here is an example on a toy dataset:

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

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

With a small number of ones in each recurrence plot, there are almost only zeros in the joint recurrence plot:

jrp_1 = JointRecurrencePlot(threshold='point', percentage=5)
X_jrp_1 = jrp_1.transform(X)
plt.imshow(X_jrp_1[0], cmap='binary', origin='lower')
Capture d’écran 2022-09-04 à 14 36 51

You can increase the number of ones in each recurrence plot, which results in many more ones in the joint recurrence plot:

jrp_2 = JointRecurrencePlot(threshold='point', percentage=50)
X_jrp_2 = jrp_2.transform(X)
plt.imshow(X_jrp_2[0], cmap='binary', origin='lower')
Capture d’écran 2022-09-04 à 14 36 59

You can also specify different thresholds for different features:

jrp_3 = JointRecurrencePlot(threshold='point', percentage=[50, 10, 70, 60, 50, 40])
X_jrp_3 = jrp_3.transform(X)
plt.imshow(X_jrp_3[0], cmap='binary', origin='lower')
Capture d’écran 2022-09-04 à 14 37 07

Hope this helps you a bit.