A Python Library with Fast Algorithms for Popular Entropy Definitions

George Manis1 and Roberto Sassi2
1University of Ioannina, Dept. of Computer Science and Engineering, 2Dipartimento di Informatica, Università degli Studi di Milano


Abstract

We present "fastEntropyLib", a set of Python functions, organized as a library, to facilitate the computation of popular definitions of entropy, used in biomedicine. Entropy estimation is a powerful tool in non-linear analysis of time series, especially for heart rate signals and electroencephalograms. However, the computation of the most common entropy metrics is time consuming, an inhibitor, especially when large amount of data is to be processed.

The library includes the most common definitions of entropy: Shannon Entropy, Renyi Entropy, Approximate Entropy, Sample Entropy, as well as the more recently proposed Bubble Entropy, an entropy almost free of parameters. What makes this library different from other similar Python libraries is the employment of fast algorithms for the implementation of Approximate, Sample Entropy and Bubble Entropy. For both Approximate and Sample Entropy, the Bucket Assisted and Lightweight algorithms have been employed. These two algorithms speed up the computation significantly by excluding similarity comparisons, which we know in advance they will fail. This is the first time code for these two algorithms becomes publicly available. It is also the first time that fast code becomes publicly available for Bubble Entropy. Even though bubble sort is a quadratic algorithm, the computation of Bubble Entropy is done in linear time, exploiting, in each step, already sorted vectors.

Since speed is the weak point of Python, we selected to implement all algorithms in C and add a Python wrapper on top of them. In this way, we exploit both the speed of C and the convenience and popularity of Python.