Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
10
Task/Entropy/Zkl/entropy.zkl
Normal file
10
Task/Entropy/Zkl/entropy.zkl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
fcn entropy(text){
|
||||
text.pump(Void,fcn(c,freq){ c=c.toAsc(); freq[c]+=1; freq }
|
||||
.fp1( (0).pump(256,List,0.0).copy() )) // array[256] of 0.0
|
||||
.filter() // remove all zero entries from array
|
||||
.apply('/(text.len())) // (num of char)/len
|
||||
.apply(fcn(p){-p*p.log()}) // |p*ln(p)|
|
||||
.sum(0.0)/(2.0).log(); // sum * ln(e)/ln(2) to convert to log2
|
||||
}
|
||||
|
||||
entropy("1223334444").println(" bits");
|
||||
Loading…
Add table
Add a link
Reference in a new issue