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
The Shannon Entropy of the string "aabc" should be 1.5.
The manual calculation should also be 1.5.
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.
We see that StringTools:-Entropy cannot operate on a matrix as the input must be a string.
Error, (in StringTools:-Entropy) argument must be a string
Therefore, the custom ShannonEntropy procedure is used.
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).
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.
Error, (in ImageTools:-Create) unable to store '"a"' when datatype=float[8]
A new matrix composed of floats is used to test the ImagesTools:-Entropy procedure.
It seems that the values in the matrix must be within 0..1.0 for the ImageTools package to work.
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.
2. Normalize the vector.
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.
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?
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
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
The Shannon Entropy of the string "aabc" should be 1.5.
The manual calculation should also be 1.5.
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.
We see that StringTools:-Entropy cannot operate on a matrix as the input must be a string.
Error, (in StringTools:-Entropy) argument must be a string
Therefore, the custom ShannonEntropy procedure is used.
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).
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.
Error, (in ImageTools:-Create) unable to store '"a"' when datatype=float[8]
A new matrix composed of floats is used to test the ImagesTools:-Entropy procedure.
It seems that the values in the matrix must be within 0..1.0 for the ImageTools package to work.
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.
2. Normalize the vector.
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.
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?
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
Copy this code into any posting to share this file with other users
2 hours 45 min ago
2 hours 46 min ago
2 hours 54 min ago
4 hours 17 min ago
4 hours 32 min ago
6 hours 54 min ago
7 hours 18 min ago
7 hours 52 min ago
7 hours 57 min ago
8 hours 1 min ago