0

In the following paper,

[Ponce-Flores, M., Frausto-Solís, J., Santamaría-Bonfil, G., Pérez-Ortega, J., & González-Barbosa, J. J. (2020). Time series complexities and their relationship to forecasting performance. Entropy, 22(1), 89.][1]

several quantities have been used to express the computational hardness of timeseries forecasting, for example:

  1. Spectral Entropy (internally the definition uses Autocovariance Function and Autocorrelation Function)
  2. Permutation Entropy (internally the definition uses Phase Space Reconstruction and Permutation Distribution)

What is the best way to express Spectral Entropy and Permutation Entropy in terms of Cumulative distribution function (CDF) of the time series?

1 Answers1

0

You can use inverse transform sampling on the spectral and permutation entropy functions.

Here is a pseudo code for the spectral entropy:

import numpy as np
import scipy.stats
import spectral_entropy
from numpy.random import random
from scipy import interpolate
import matplotlib.pyplot as plt
import cProfile

#Spectral entropy function
def f(x):
    # does not need to be normalized
    entropy = []
    for i in range(0,len(x)):
    spectrum = spectral_entropy.clean_spectrum(x[i])
    entropy.append(scipy.stats.entropy(spectrum[:, 1]))
    return entropy

def sample(g):
    x = [[-2,2,5],[3,5,9],[1,-3,6]]
    y = g(x)                        # probability density function, pdf
    cdf_y = np.cumsum(y)            # cumulative distribution function, cdf
    cdf_y = cdf_y/cdf_y.max()       # takes care of normalizing cdf to 1.0
    inverse_cdf = interpolate.interp1d(cdf_y,x)    # this is a function
    return inverse_cdf

def return_samples(N=1e6):
    # let's generate some samples according to the chosen pdf, f(x)
    uniform_samples = random(int(N))
    required_samples = sample(f)(uniform_samples)
    return required_samples

cProfile.run('return_samples()')

## plot
x = np.linspace(-3,3,1e4)
fig,ax = plt.subplots()
ax.set_xlabel('x')
ax.set_ylabel('probability density')
ax.plot(x,f(x)/np.sum(f(x)*(x[1]-x[0])) )
ax.hist(return_samples(1e6),bins='auto',normed=True,range=(x.min(),x.max()))
plt.show() 

Please let me know if it works.

Source: https://gist.github.com/amarvutha/c2a3ea9d42d238551c694480019a6ce1

Nicolas Martin
  • 4,509
  • 1
  • 6
  • 15