Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
22
Task/Entropy/Pluto/entropy.pluto
Normal file
22
Task/Entropy/Pluto/entropy.pluto
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
do -- Shannon entropy - translated from the Lua sample
|
||||
|
||||
local function log2 ( x : number ) : number return math.log(x) / math.log(2) end
|
||||
|
||||
local function entropy ( X : string ) : number
|
||||
local N, count, sum, i = X:len(), {}, 0
|
||||
for char = 1, N do
|
||||
i = X[char]
|
||||
if count[i] then
|
||||
count[i] += 1
|
||||
else
|
||||
count[i] = 1
|
||||
end
|
||||
end
|
||||
for n_i, count_i in pairs(count) do
|
||||
sum += count_i / N * log2(count_i / N)
|
||||
end
|
||||
return -sum
|
||||
end
|
||||
|
||||
print( entropy( "1223334444" ) )
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue