StringTools - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Names and Strings : StringTools Package : Statistics : StringTools/Entropy

StringTools

  

Entropy

  

compute the Entropy of a string

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

Entropy( s )

Parameters

s

-

Maple string

Description

• 

The Entropy(s) command returns the Shannon entropy of the string s. A floating-point number, the entropy of the string, is returned.

• 

Shannon's entropy is defined as -add( P( ch ) * log[ 2 ]( P( ch ) ), ch = Support( s ) ), where Pch=CountCharacterOccurrencess,chlengths. It is a measure of the information content of the string, and can be interpreted as the number of bits required to encode each character of the string given perfect compression. The entropy is maximal when each character is equally likely. For arbitrary non-null characters, this maximal value is log[2]255=7.99435.

  

(The null byte, with code point 0, cannot appear in a Maple string. If all 256 single byte code points could appear, then the maximal entropy would be log[2]256=8, which is the number of bits per byte).

• 

Note that the entropy is computed as a floating-point number, at hardware (double) precision.

Examples

useStringToolsinEntropyMathematicsend use

3.09579525500093355

(1)

withStringTools:

Entropyaaaaaaaaaaaaaaaaaaaaaaaaaa

0.

(2)

EntropyaaaaaaaaaaaaaaaaaaaaaaaaaaB

0.228538143953528006

(3)

EntropyΙ1,255

7.99435343685886934

(4)

EntropyRandom1000000

7.99417106407216149

(5)

evalflog[2]255

7.994353436

(6)

EntropyRandom1000000,'lower'

4.70042263084046397

(7)

evalflog[2]26

4.700439718

(8)

EntropyRepeatab,100

1.

(9)

EntropyRepeatabc,100

1.58496250072115585

(10)

EntropyRepeatabcde,100

2.32192809488736218

(11)

EntropyRepeatRandom10,10000

3.32192809488736218

(12)

The following steps illustrate the definition of Entropy.

sRandom30,'lower'

s:=rbygsggdjijjtiqelzxehfnojeorwr

(13)

occseqCountCharacterOccurrencess,ch,ch=Supports

occ:=1,1,3,1,3,1,2,4,1,1,2,1,3,1,1,1,1,1,1

(14)

Lmap`/`,occ,lengths

L:=130,130,110,130,110,130,115,215,130,130,115,130,110,130,130,130,130,130,130

(15)

Umapp→evalfplog[2]p,L

U:=0.1635630199,0.1635630199,0.3321928095,0.1635630199,0.3321928095,0.1635630199,0.2604593730,0.3875854127,0.1635630199,0.1635630199,0.2604593730,0.1635630199,0.3321928095,0.1635630199,0.1635630199,0.1635630199,0.1635630199,0.1635630199,0.1635630199

(16)

convertU,'`+`'

4.031401848

(17)

Entropys

4.03140184539217117

(18)

See Also

add

convert

evalf

length

log

map

seq

string

StringTools

StringTools[CountCharacterOccurrences]

StringTools[Iota]

StringTools[Random]

StringTools[Repeat]

StringTools[Support]

with

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam