0

I want to calculate the entropy of a time series, but I found that in the way, there are some infinities arising from a log(0). In this particular case, those zeros represent a frequency with amplitude zero. That's just a bit of context. What I really want to know is the following:

What is the proper way to deal with infinities or zeros propagating through calculations in scientific programming? I have seen that sometimes a very small quantity is added to avoid this issue. Is this a general solution? I think there could be some issues when requiring a very precise calculation. Are there other solutions?

Charles
  • 50,943
  • 13
  • 104
  • 142
r_31415
  • 8,752
  • 17
  • 74
  • 121
  • 3
    There is no general solution to this problem. It depends on what infinity means in the context of your calculation, and how the method to avoid it influences non-zero answers. I suspect that there's an error in your entropy calculation, though. How does a frequency with zero amplitude appear in the data? Zero amplitude means the mode has no impact upon the data. – sfstewman Aug 19 '13 at 05:00
  • @sfstewman Thank you for your answer. Maybe there is an error, but in this case, it's only the real part of the fft that is zero. In general, I'm not sure frequencies shouldn't be zero; DC components are usually zero and there is nothing wrong with that. – r_31415 Aug 19 '13 at 05:06
  • Are you saying that some of the frequencies are zero or imaginary? Is this a physical entropy or information entropy? – sfstewman Aug 19 '13 at 05:16
  • After calculating the fft, most frequencies don't produce infinities. However, the ones that do, have a zero real component and a non-zero imaginary component. After that, I calculated the normalized power spectrum and finally its Information entropy. – r_31415 Aug 19 '13 at 05:29
  • 2
    If your problem arises from calculating p*log(p) when p is zero, I'd recommend defining a function xlogx that returns 0 when it's argument p is zero and p*log(p) otherwise. – dmuir Oct 02 '13 at 11:02

0 Answers0