# Bidimensional Entropies¶

## Functions for estimating the entropy of a two-dimensional univariate matrix.¶

While EntropyHub functions primarily apply to time series data, with the following bidimensional entropy functions one can estimate the entropy of two-dimensional (2D) matrices. Hence, bidimensional entropy functions are useful for applications such as image analysis.

Danger

`IMPORTANT: Locked Matrix Size`

Each bidimensional entropy function (`SampEn2D`, `FuzzEn2D`, `DistEn2D`) has an important keyword argument - `Lock`. Bidimensional entropy functions are “locked” by default (`Lock == true`) to only permit matrices with a maximum size of 128 x 128.

The reason for this is because there are hundreds of millions of pairwise calculations performed in the estimation of bidimensional entropy, so memory errors often occur when storing data on RAM.

e.g. For a matrix of size [200 x 200], an embedding dimension (`m`) = 3, and a time delay (`tau`) = 1, there are 753,049,836 pairwise matrix comparisons (6,777,448,524 elemental subtractions). To pass matrices with sizes greater than [128 x 128], set Lock = false.

`CAUTION: unlocking the permitted matrix size may cause your Julia IDE to crash.`

These functions are directly available when EntropyHub is imported:

```import EntropyHub as EH

dir(EH)
```

`DistEn2D`(Mat, m=None, tau=1, Bins='Sturges', Logx=2, Norm=2, Lock=True)

DistEn2D Estimates the bidimensional distribution entropy of a data matrix.

```Dist2D = DistEn2D(Mat)
```

Returns the bidimensional distribution entropy estimate (`Dist2D`) estimated for the data matrix (`Mat`) using the default parameters: time delay = 1, binning method = ‘sturges’, logarithm = natural, matrix template size = [floor(H/10) floor(W/10)] (where H and W represent the height (rows) and width (columns) of the data matrix `Mat`) * The minimum dimension size of `Mat` must be > 10.

```Dist2D = DistEn2D(Mat, keyword = value, ...)
```

Returns the bidimensional distribution entropy (`Dist2D`) estimate for the data matrix (Mat) using the specified ‘keyword’ arguments:

m
• Template submatrix dimensions, an integer scalar (for sub-matrix with same height and width) or a two-element tuple of integers [height, width] with a minimum value > 1. (default: [floor(H/10) floor(W/10)])

tau
• Time Delay, a positive integer (default: 1)

Bins
• Histogram bin selection method for distance distribution, one of the following:

• an integer > 1 indicating the number of bins,

• or one of the following strings {`'sturges'`, `'sqrt'`, `'rice'`, `'doanes'`} [default: ‘sturges’]

Logx
• Logarithm base, a positive scalar (enter 0 for natural log)

Norm
• Normalisation of Dist2D value, one of the following integers:

•  no normalisation.

•  normalises values of data matrix (Mat) to range [0 1].

•  normalises values of data matrix (Mat) to range [0 1], and normalises the distribution entropy value (`Dist2D`) w.r.t the number of histogram bins. [default]

•  normalises the distribution entropy value (`Dist2D`) w.r.t the number of histogram bins, without normalising data matrix values.

Lock
• By default, `DistEn2D` only permits matrices with a maximum size of 128 x 128 to prevent RAM overload.

e.g. For `Mat` = [200 x 200], `m` = 3, and `tau` = 1, `DistEn2D` creates a vector of 753049836 elements. To enable matrices greater than [128 x 128] elements, set `Lock = False` (default: True)

`CAUTION: unlocking the permitted matrix size may cause memory` `errors that could lead your Python IDE to crash.`

`DistEn`, `XDistEn`, `SampEn2D`, `FuzzEn2D`, `MSEn`

References
 Hamed Azami, Javier Escudero and Anne Humeau-Heurtier,

“Bidimensional distribution entropy to analyze the irregularity of small-sized textures.” IEEE Signal Processing Letters 24.9 (2017): 1338-1342.

`FuzzEn2D`(Mat, m=None, tau=1, r=None, Fx='default', Logx=numpy.exp, Lock=True)

FuzzEn2D estimates the bidimensional fuzzy entropy of a data matrix.

```Fuzz2D = FuzzEn2D(Mat)
```

Returns the bidimensional fuzzy entropy estimate (`Fuzz2D`) estimated for the data matrix (`Mat`) using the default parameters: time delay = 1, fuzzy function (`Fx`) = `'default'`, fuzzy function parameters (`r`) = (0.2, 2, logarithm = natural, matrix template size = [floor(H/10) floor(W/10)] (where H and W represent the height (rows) and width (columns) of the data matrix `'Mat'`) ** The minimum number of rows and columns of Mat must be > 10.

```Fuzz2D = FuzzEn2D(Mat, keyword = value, ...)
```

Returns the bidimensional fuzzy entropy (`Fuzz2D`) estimates for the data matrix (`Mat`) using the specified ‘keyword’ arguments:

m
• Template submatrix dimensions, an integer (for sub-matrix with same height and width) or a two-element vector of integers [height, width] with a minimum value > 1. (default: [floor(H/10) floor(W/10)])

tau
• Time Delay, a positive integer (default: 1)

Fx
• Fuzzy funtion name, one of the following:

{`'sigmoid'`, `'modsampen'`, `'default'`, `'gudermannian'`, `'linear'`}

r
• Fuzzy function parameters, a 1 element scalar or a 2 element vector of positive values.

The `r` parameters for each fuzzy function are defined as follows:

• sigmoid:

r(1) = divisor of the exponential argument r(2) = value subtracted from argument (pre-division)

• modsampen:

r(1) = divisor of the exponential argument r(2) = value subtracted from argument (pre-division)

• default:

r(1) = divisor of the exponential argument r(2) = argument exponent (pre-division)

• gudermannian:

r = a scalar whose value is the numerator of argument to gudermannian function: GD(x) = atan(tanh(r/x)). GD(x) is normalised to have a maximum value of 1.

• linear:

r = an integer value. When r = 0, the argument of the exponential function is normalised between [0 1]. When r = 1, the minimuum value of the exponential argument is set to 0.

Logx
• Logarithm base, a positive scalar (default: natural)

Lock
• By default, `FuzzEn2D` only permits matrices with a maximum size of 128 x 128 to prevent RAM overload.

e.g. For `Mat` = [200 x 200], `m` = 3, and `tau` = 1, `FuzzEn2D` creates a vector of 753049836 elements. To enable matrices greater than [128 x 128] elements, set `Lock = False` (default: True)

`CAUTION: unlocking the permitted matrix size may cause memory` `errors that could lead your Python IDE to crash.`

`SampEn2D`, `DistEn2D`, `FuzzEn`, `XFuzzEn`, `XMSEn`

References
 Luiz Fernando Segato Dos Santos, et al.,

“Multidimensional and fuzzy sample entropy (SampEnMF) for quantifying H&E histological images of colorectal cancer.” Computers in biology and medicine 103 (2018): 148-160.

 Mirvana Hilal and Anne Humeau-Heurtier,

“Bidimensional fuzzy entropy: Principle analysis and biomedical applications.” 41st Annual International Conference of the IEEE (EMBC) Society 2019.

`SampEn2D`(Mat, m=None, tau=1, r=None, Logx=numpy.exp, Lock=True)

SampEn2D Estimates the bidimensional sample entropy of a data matrix.

```SE2D, Phi1, Phi2 = SampEn2D(Mat)
```

Returns the bidimensional sample entropy estimate (`SE2D`) and the number of matched sub-matricess (`m: Phi1`, `m+1: Phi2`) estimated for the data matrix (Mat) using the default parameters: time delay = 1, radius distance threshold = 0.2*SD(`Mat`), logarithm = natural matrix template size = [floor(H/10) floor(W/10)] (where H and W represent the height (rows) and width (columns) of the data matrix `Mat`) * The minimum dimension size of Mat must be > 10.

```SE2D, Phi1, Phi2 = SampEn2D(Mat, keyword = value, ...)
```

Returns the bidimensional sample entropy (`SE2D`) estimates for the data matrix (`Mat`) using the specified ‘keyword’ arguments:

m
• Template submatrix dimensions, an integer scalar (for sub-matrix with same height and width) or a two-element tuple of integers (height, width) with a minimum value > 1. (default: [floor(H/10) floor(W/10)])

tau
• Time Delay, a positive integer > 1 (default: 1)

r
• Distance Threshold, a positive scalar (default: 0.2*SD(`Mat`))

Logx
• Logarithm base, a positive scalar (default: natural)

Lock
• By default, `SampEn2D` only permits matrices with a maximum size of 128 x 128 to prevent RAM overload.

e.g. For `Mat` = [200 x 200], `m` = 3, and `tau` = 1, `SampEn2D` creates a vector of 753049836 elements. To enable matrices greater than [128 x 128] elements, set `Lock = False` (default: True) `CAUTION: unlocking the permitted matrix size may cause memory` `errors that could lead your Python IDE to crash.`

`SampEn`, `FuzzEn2D`, `DistEn2D`, `XSampEn`, `MSEn`