Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
11
Task/Entropy/F-Sharp/entropy.fs
Normal file
11
Task/Entropy/F-Sharp/entropy.fs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
open System
|
||||
|
||||
let ld x = Math.Log x / Math.Log 2.
|
||||
|
||||
let entropy (s : string) =
|
||||
let n = float s.Length
|
||||
Seq.groupBy id s
|
||||
|> Seq.map (fun (_, vals) -> float (Seq.length vals) / n)
|
||||
|> Seq.fold (fun e p -> e - p * ld p) 0.
|
||||
|
||||
printfn "%f" (entropy "1223334444")
|
||||
Loading…
Add table
Add a link
Reference in a new issue