Details for 8408_ShannonEntropy-RegressionTest.mw

Download file: 8408_ShannonEntropy-RegressionTest.mw (View Live Worksheet on MapleNet)
Uploaded by OptimusMaplePrime(Maple Rating 1 18) (View other files uploaded by OptimusMaplePrime)

The HTML version of this file is shown below. To use the contents of this file in a posting, click here to get the source code


Test the ShannonEntropy procedure.

Don Pellegrino
May 7, 2008

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Examine the Shannon Entropy of a String

The Shannon Entropy of the string "aabc" should be 1.5.

Maple Equation

Maple Equation

The manual calculation should also be 1.5.

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Calculate the Shannon Entropy of a Matrix

A matrix is treated like a string. The matrix is a container of elements analogous to the way that a string is a container of characters. A matrix with the same contents as a string should therefore have the same entropy value.

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

We see that StringTools:-Entropy cannot operate on a matrix as the input must be a string.

Maple Equation

Error, (in StringTools:-Entropy) argument must be a string

Maple Equation

Therefore, the custom ShannonEntropy procedure is used.

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Faster, Simpler

This section is an exploration of the faster, simpler version of the algorithm as presented by acer on MaplePrimes:

(http://www.mapleprimes.com/blog/optimusmapleprime/calculateshannonentropymatrix).

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

ImageTools:-Entropy

Joe Riel on MaplePrimes points out that the ImageTools:-Entropy procedure can be used on a matrix by way of the ImageTools:-Create procedure:

(http://www.mapleprimes.com/blog/optimusmapleprime/calculateshannonentropymatrix).

It seems that this procedure will not work when the matrix holds characters.

Maple Equation

Error, (in ImageTools:-Create) unable to store '"a"' when datatype=float[8]

Maple Equation

A new matrix composed of floats is used to test the ImagesTools:-Entropy procedure.

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

It seems that the values in the matrix must be within 0..1.0 for the ImageTools package to work.

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Maple Equation

Normalization of the matrix might be sufficient to use ImageTools:-Entropy on numeric data however the LinearAlgebra:-Normalize procedure wants a vector rather than a matrix. The entropy calculation as implemented here treats the matrix as a generic container. Shannon's Entropy calculation treats the input as symmetric; the order of the elements does not effect the result. Therefore it should be possible to restructure the elements into a list or vector and then use the ImageTools procedures. ImageTools:-Create then wants a matrix rather than a vector so another conversion is needed. A possible algorithm would be:

1. Convert the matrix to a vector.

2. Normalize the vector with LinearAlgebra:-Normalize.

3. Convert the normalized vector to a matrix.

4. Run the ImageTools:-Create procedure on the matrix.

5. Run the ImageTools:-Entropy procedure on the image.

1. Convert the matrix to a vector.

Maple Equation

Maple Equation

2. Normalize the vector.

Maple Equation

Maple Equation

3. Convert the normalized vector to a matrix.

Maple Equation

4. Run the ImageTools:-Create procedure on the matrix.

Maple Equation

5. Run the ImageTools:-Entropy procedure on the image.

Maple Equation

Maple Equation

So this algorithm seems to work for processing a matrix of numeric data, however it will not work when the matrix contains character or string data. Could this algorithm be adapted so that ImageTools:-Entropy or StringTools:-Entropy could be used on a matrix containing those datatypes as well? How about a matrix with both numeric and string columns?

Maple Equation

This post was generated using the MaplePrimes File Manager

View 8408_ShannonEntropy-RegressionTest.mw on MapleNet or Download 8408_ShannonEntropy-RegressionTest.mw
View file details


HTML Source Code

Copy this code into any posting to insert this file into a posting on MaplePrimes

IMPORTANT INFORMATION

When pasting this code into a post on MaplePrimes, make sure that you choose the Worksheet HTML input format

Download Link Code

Copy this code into any posting to share this file with other users

}