pyEntropy
pyEntropy copied to clipboard
issue about the example
when I install it, and test it with your example code, it got a warning: RuntimeWarning: invalid value encountered in true_divide, does it mean the example data is wrong or I make some mistake?
I'm having the same issue. To provide more detail:
Running this:
from pyentrp import entropy as ent
import numpy as np
x = np.random.rand(3000)
ts = [1, 4, 5, 1, 7, 3, 1, 2, 5, 8, 9, 7, 3, 7, 9, 5, 4, 3]
for values in [ts, x]:
std_ts = np.std(values)
sample_entropy = ent.sample_entropy(values, 5, 0.2 * std_ts)
multiscale_entropy = ent.multiscale_entropy(values, sample_length=5)
permutation_entropy = ent.permutation_entropy(values, order=5, normalize=True)
print(sample_entropy)
print(multiscale_entropy)
print(permutation_entropy)
Produces this output:
/usr/local/anaconda3/envs/plutus/lib/python3.7/site-packages/pyentrp/entropy.py:163: RuntimeWarning: invalid value encountered in true_divide
sampen = - np.log(Ntemp[1:] / Ntemp[:-1])
/usr/local/anaconda3/envs/plutus/lib/python3.7/site-packages/pyentrp/entropy.py:163: RuntimeWarning: divide by zero encountered in log
sampen = - np.log(Ntemp[1:] / Ntemp[:-1])
[2.95099638 2.07944154 inf nan nan]
[nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan]
0.5512400796500767
[2.18821295 2.18706536 2.1974189 2.19977194 2.11596861]
[3.11351531 2.07944154 2.7080502 ... nan nan nan]
0.9960386507116764
It appears to be specific to sample lengths greater than 2. No warnings, inf
, or nan
are produced when the sample length is 2 or 1, but the problem arrises when the sample length is 3 or greater.
Multiscale is built on top of sample, so naturally it suffers the same issue. Permutation entropy appears to be fine.
Is it possibly a function of the length of the input series? The sample_entropy sample_length=5
does not produce any warnings, nan
s, or inf
s on the longer sequence of 3000 random values, although multiscale still produces nans even on the 3000-length input.
pyentrp 0.6. numpy 1.19.4.
This error is related to division by 0. Most probably it is because of the input: at some scale this operation appears and that's why there are nans/inf in the result