Advanced visualization techniques for time series analysis
By: Michaël Hoarau
Tags: Getting Started, Visualization Techniques, Editors Pick, Machine Learning, Time Series Analysis

Step 2: Build the Markov transition matrix

Once our signal is quantized, we can build a Markov transition matrix:

How to read the Markov transition matrix? Let’s have a look at the first row: | 465 | 86 | 1 | 0 | 0 | 0 | 0 | 0 | :

The first cell tells us that 465 points that are in the bin 0 (with values between 82.4 and 118.4) are followed by a value that stays in this very bin.

The second cell tells us that 86 points that are in bin 0 transition to the next bin (with a value between 118.4 and 137.4)

… and so on…

The eighth cell tells us that no point from bin 0 transition to the last bin

Let’s now have a look at the second row: | 80 | 405 | 63 | 2 | 0 | 2 | 0 | 0 | : the first cell tells us that 80 points that are in bin 1 (with a value between 118.4 and 137.4) are followed by a value that is in bin 0 (between 82.4 and 118.4).

Last but not least, the diagonal captures the frequency at which a quantile transitions to itself (self-transition frequency).

Step 3: Compute transition probabilities

We will now normalize each bin. This matrix contains now the transition probability on the magnitude axis:

The first column correspond to the probabilities that a given value (part of a given bin) transitions to bin 0. The second column are probabilities that a given value transitions to bin 1, etc. For instance, if a given value X[i] is equal to 130.0, it is between 118.42 and 137.42 and it's binned in bin 1. Given the matrix above, there is:

A 14.5% chance that the next value will be between 82.43 and 118.42 (bin 0)

chance that the next value will be between and (bin 0) A 73.4% chance to stay within the same range (between 118.42 and 137.42 , bin 1)

chance to stay within the same range (between and , bin 1) A 11.4% chance that the next value will be between 137.42 and 156.78 (bin 2)

chance that the next value will be between and (bin 2) … and so on…

Step 4: Compute the Markov transition field

The idea of the transition field is to represent the Markov transition probabilities sequentially to preserve the information in the time domain. The MTF generation process aligns each probability along the temporal order to build the MTF for the whole signal:

How to read the Markov transition field? MTF[i,j] denotes the transition probability from the quantile q[i] to the quantile q[j] . Let's have a look at a couple values in the second row of this field:

array([68.8, 68.8, 68.8, 68.8, 68.8, 68.8, 10.7, 10.7, 10.7, 10.7])

Let’s have a look at M[1,2] :

We look in which bin falls the signal at timestep x[1] : this is X_binned[1] = 2

: this is We also look in which bin falls the signal at timestep x[2] : this is X_binned[2] = 2

: this is We then look up into the Markov transition matrix to get the probability that a value from bin 2 stays into bin 2

This value is 68.8%, hence M[1,2] = 68.8%

What does this mean? Well, the transition that occurs between timestep x[1] and timestamp x[2] has an 68.8% chance from happening when looking at the whole signal.

Let’s now have a look at M[1,6] :

We look in which bin falls the signal at timestep x[1] : this is X_binned[1] = 2

: this is We also look in which bin falls the signal at timestep x[10] : this is X_binned[6] = 1

: this is We then look up into the Markov transition matrix to get the probability that a value from bin 2 transitions into bin 1

This value is 10.7%, hence M[1,6] = 10.7%

The transition that happens between timestep x[1] and x[6] has a 10.7% chance of happening when looking at the whole signal.

Let’s now plot the transition field we just computed:

High resolution MTF: pixel colors map to transition probabilities (image by the author)

Step 5: Compute an aggregated MTF

To make the image size manageable and computation more efficient (the above MTF is a matrix of dimension 4116 x 4116), we reduce the MTF size by averaging the pixels in each non-overlapping m x m patch with the blurring kernel 1/m² . m is the image size and we set it, arbitrarily, to 48. That is, we aggregate the transition probabilities in each subsequence of length m = 48 together. Let's compute an aggregated MTF accordingly: if the signal length can be divided by the chosen image size (48), which is the case here, we can just compute the aggregate MTF with this simple function:

Otherwise, we need to compute a piecewise aggregate approximation, but don’t worry, this is fully implemented and taken care for you in the pyts package! The image obtained is exactly the same than the one shown at the top of this article:

Ta da! (image by the author)

Step 6: Extracting meaningful metrics

The diagonal of the MTF contains probabilities for the self-transitions: