# Shannon wavelet entropy

**URL:** <https://discourse.julialang.org/t/shannon-wavelet-entropy/114319>\
**Category:** New to Julia\
**Tags:** question, package, matlab\
**Created:** [May 15, 2024, 7:50pm UTC](https://discourse.julialang.org/t/shannon-wavelet-entropy/114319 "2024-05-15T19:50:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahrensma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahrensma/32/209243_2.png) [@ahrensma](https://discourse.julialang.org/u/ahrensma)\
**Post date:** [May 15, 2024, 7:50pm UTC](https://discourse.julialang.org/t/shannon-wavelet-entropy/114319/1 "2024-05-15T19:50:59Z")

</div>

Hello,

I look for a function similar to the _wentropy_ function in the Wavelet Toolbox of Matlab. In an older code I used to following form:

`H = -wentropy( DataArray , 'shannon' );`

I look in several packages (Wavelet.jl, WaveletsExt.jl, Entropies.jl), finally in ComplexityMeasures.jl and found a similar approach ([ComplexityMeasures.Shannon](https://docs.juliahub.com/General/ComplexityMeasures/stable/autodocs/#ComplexityMeasures.Shannon)) but no example that I can understand how to use the function.

Does anyone know an approach to implement the Matlab function in Julia?

Kind regards,

Martin

---

<div class="post-metadata">

**Author:** ![cmarcotte](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@cmarcotte](https://discourse.julialang.org/u/cmarcotte)\
**Post date:** [May 16, 2024, 7:13am UTC](https://discourse.julialang.org/t/shannon-wavelet-entropy/114319/2 "2024-05-16T07:13:47Z")

</div>

I think you want the `entropy()` function in ComplexityMeasures, using the Shannon measure. The relevant documentation is [around here](https://juliadynamics.github.io/DynamicalSystemsDocs.jl/complexitymeasures/stable/tutorial/#Beyond-Shannon:-more-entropies).

---

<div class="post-metadata">

**Author:** ![ahrensma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahrensma/32/209243_2.png) [@ahrensma](https://discourse.julialang.org/u/ahrensma)\
**Post date:** [May 22, 2024, 12:36pm UTC](https://discourse.julialang.org/t/shannon-wavelet-entropy/114319/3 "2024-05-22T12:36:37Z")

</div>

Hello,

thanks for the hint, I checked it and it works well for time series ( H = entropy(WaveletOverlap(), DATA) ) , what I need is this for 2D (image) data. One approach could be to calculate it line by line, but this is very slow. Is there a faster implementation available. I looked in [`SpatialDispersion`](https://juliadynamics.github.io/ComplexityMeasures.jl/stable/probabilities/#ComplexityMeasures.SpatialDispersion) and [`SpatialOrdinalPatterns`](https://juliadynamics.github.io/ComplexityMeasures.jl/stable/probabilities/#ComplexityMeasures.SpatialOrdinalPatterns) but stencil parameters seems to be not senseful in my case.

/Martin

---

<div class="post-metadata">

**Author:** ![cmarcotte](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@cmarcotte](https://discourse.julialang.org/u/cmarcotte)\
**Post date:** [May 23, 2024, 7:31am UTC](https://discourse.julialang.org/t/shannon-wavelet-entropy/114319/4 "2024-05-23T07:31:31Z")

</div>

I don’t know enough about your problem to say how it should map to the SpatialDispersion calculation.

Having a look at `wentropy` in Matlab tells me they’re doing something substantially less sophisticated than `ComplexityMeasures.jl`: they compute the probability distribution of the input pixels (with bins depending on pixel type) and then returning `-sum(p.*log2(p))`. This is considerably simpler than what I steered you toward.

The way to match Matlab’s `wentropy` is to start with [StatsBase.Histogram](https://juliastats.org/StatsBase.jl/stable/empirical/#Histograms-1), choosing the normalization. The rest should be trivial.
