Tchanders / InformationMeasures.jl

Entropy, mutual information and higher order measures from information theory, with various estimators and discretisation methods.
Other
66 stars 14 forks source link

Zeros Vector Breaks Execution #25

Open Sinansi opened 4 years ago

Sinansi commented 4 years ago

Hello,

I am running an application that loops over InformationMeasures.get_mutual_information. If you pass a vector with all elements containing zero (example, Base.zeros()) to this function, the execution of the loop breaks and an error is displayed on the screen.

I suggest if a zeros vector is passed to this function, it just returns a mutual information of 0.0 instead of interrupting the execution of the loop/application.

Thank you!

KalelR commented 4 years ago

This actually happens whenever a vector contains equal elements: could be zeros, ones, or tens, for example. For a vector named vec, you can check if all elements are equal by using the following function: allequal(vec) = all(y->y==vec[1],vec)

This is taken from https://stackoverflow.com/questions/47564825/check-if-all-the-elements-of-a-julia-array-are-equal/47578613.