arthurpessa / ordpy

A Python package for data analysis with permutation entropy and ordinal network methods.
MIT License
81 stars 16 forks source link

Ordinal distribution issues for higher dimensions #2

Closed marcosacero closed 2 years ago

marcosacero commented 2 years ago

I've encountered an issue regarding the ordinal_distribution function when trying to change the embedding dimension of the ordinal patterns.

When we are dealing with 3 dimensional ordinal patterns, we see that the decreasing pattern "2 1 0" doesn't exist in the logistic map. However, for 4 dimensional patterns, it suddenly appears, which doesn't make sense. If "2 1 0" isn't present, then "1 3 2 0" shouldn't be either. Nevertheless, if we add up all the probabilities together, they do equal 1. Also, if we calculate the permutation entropy using 4 dimensional ordinal patterns, the result is consistent with other papers. So, if I had to guess, for embedding dimensions greater than 3, the probabilities calculated are in fact correct, but they are getting assigned to the wrong ordinal pattern.

I can't seem to find where in the code this problem is occurring, but perhaps since you know your code better, you may have an idea of how to fix this problem. I'd like to investigate Bandt's up-down symmetry using 4 dimensional patterns and want to see if you can help me out.

I also wanted to let you know that I made a couple modifications of my own to this section of your code since the way the arrays were getting generated from ordinal_distribution caused occasional shifting in the order of the arrays. This feature caused issues in graphing ordinal patterns and permutation entropy as a function of the parameter r. It seems like this problem occurred because when certain patterns weren't appearing, they were moved to the end of the array, which doesn't preserve the original array order. If we adjust for this issue, however, the graphs will look as they should.

arthurpessa commented 2 years ago

Good afternoon, Mr. Sacero.

Concerning the first paragraph of the open issue, taking into account the way we analyze amplitude relations in series windows, if the pattern "210" is not present, then patterns "2103", "2130", "2310" and "3210" would not appear when dx = 4. This can be seen if we consider a four-element window such as (9, 8, 7, x), for x must obey one of the four inequalities:

                                        7 < 8 < 9 < x -- (2, 1, 0, 3);
                                        7 < 8 < x < 9 -- (2, 1, 3, 0);
                                        7 < x < 8 < 9 -- (2, 3, 1, 0);
                                        x < 7 < 8 < 9 -- (3, 2, 1, 0).

Concerning the fourth paragraph, the way we return the ordinal patterns and their probabilities was a choice we made that permits us to more readily use the ordinal distribution for calculation purposes. We may add new functionalities in the future to return the ordinal patterns "in order", independently of their occurring or not in a given time series.

If our explanations were not clear or sufficient, please feel free to continue writing to us.