Open Wusir2018 opened 2 years ago
Hi! All the calculations are detailed in the notebook: I would recommend your replace the input of the notebook with your time series. Under the MTF Overview, replace X with your timeseries:
mtf = MarkovTransitionField(image_size=48, n_bins=n_bins, strategy=strategy)
tag_mtf = mtf.fit_transform(X)
And then under Process decomposition you find all the different steps to go from a time series to an MTF ("the mathematical calculation"):
Hope this helps!
Hey @michaelhoarau , thank you for your reply! I read your notebook and I know how to use your code to process my data. But I would like to know the mathematics of this, what is the formula to get the result of each step, I would like to know the principle of this. Could you tell me?
reference: Liu, Lu.; Wang, Zhiguang (2018) Encoding temporal Markov dynamics in graph for visualizing and mining time series Arxiv.
Best wishes!
Hi, I think there's a misunderstanding. There isn't a simple mathematical "formula" to go from each point in the time series to a point in the matrix. For instance, when I write "Discretize the timeseries along the different values it can take", it means exactly this: you need to discretize your signals which I do with this line of code:
X_binned, bin_edges = tsia.markov.discretize(tag_df)
This line actually takes your timeseries and discretizes it (you can read the definition of this function here). The second step is then generated the Markov transition matrix which I do with this line, using this function:
X_mtm = tsia.markov.markov_transition_matrix(X_binned)
If you look into this function, you will see that the matrix is just defined like this, by using the discretized signal as the input:
# 0-initialize the Markov transition matrix:
n_bins = np.max(X_binned) + 1
X_mtm = np.zeros((n_bins, n_bins))
# We loop through each timestamp:
n_timestamps = X_binned.shape[0]
for j in prange(n_timestamps - 1):
# For each timestamp 'j', we count the transition from the bin
# associated to the current timestamp to the bin associated to
# the next timestamp 'j+1':
X_mtm[X_binned[j], X_binned[j + 1]] += 1
return X_mtm
I could continue like this for the other steps, by I'm afraid I won't have any added value compared to Lu Liu's paper: my code just implemented this paper and the latter explains everything in much details and even gives the appropriate equations when they're needed.
If my notebook and my Medium blog post is not enough and you still want to understand the whole process down to the nitty gritty details, I highly encourage you to read the code from the tsia
and pyts
python modules along with the paper. This is how I did it when I wrote the tsia
module, the blog post and the notebook.
Ok,thank you very much ! :)
Hello, Thank you for the open code. I read two references of MTF and your code, but I still don't understand how to get MTF. Could you help me by listing mathematical calculations? Could you explain the mathematical calculation of MTF to me by a short time series like [2,2,3,4,8,10,12,16]?
Thank you very much! Best wishes! :)