Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,28 @@
with Ada.Text_IO, Ada.Float_Text_IO, Ada.Numerics.Elementary_Functions;
procedure Count_Entropy is
package TIO renames Ada.Text_IO;
Count: array(Character) of Natural := (others => 0);
Sum: Natural := 0;
Line: String := "1223334444";
begin
for I in Line'Range loop -- count the characters
Count(Line(I)) := Count(Line(I))+1;
Sum := Sum + 1;
end loop;
declare -- compute the entropy and print it
function P(C: Character) return Float is (Float(Count(C)) / Float(Sum));
use Ada.Numerics.Elementary_Functions, Ada.Float_Text_IO;
Result: Float := 0.0;
begin
for Ch in Character loop
Result := Result -
(if P(Ch)=0.0 then 0.0 else P(Ch) * Log(P(Ch), Base => 2.0));
end loop;
Put(Result, Fore => 1, Aft => 5, Exp => 0);
end;
end Count_Entropy;

View file

@ -0,0 +1,14 @@
scope # Show the Shannon entropy of a string
# the Agena strings.shannon library routine returns three values:
# the normalised specific Shannon entropy, the specific Shannon entropy and
# the total information entropy
# the middle value appears to be the one required for the task
local proc shannon( s :: string ) :: number
local nse, se, tie := strings.shannon( s );
return se
end;
print( shannon( "1223334444" ) )
epocs

View file

@ -0,0 +1,40 @@
(defun entropy (str / log2 eCalc strList len ent cnt n new end cPrev)
(defun log2 (x)
(if (> x 0)
(/ (log x) (log 2.0))
)
)
(defun eCalc (cnt len / p)
(setq p (/ (float cnt) len))
(* p (log2 p))
)
(setq
strList (acad_strlsort (mapcar 'chr (vl-string->list str)))
len (length strList)
ent 0.0
cnt 0
n 0
)
(foreach c strList
(setq
n (1+ n)
new (and cPrev (not (eq c cPrev)))
end (= n len)
)
(if (or new end)
(setq
cnt (if (and end (not new)) (1+ cnt) cnt)
ent (+ ent (eCalc cnt len))
cnt 0
)
)
(if (and new end)
(setq ent (+ ent (eCalc 1 len)))
)
(setq
cnt (1+ cnt)
cPrev c
)
)
(* -1 ent)
)

View file

@ -0,0 +1,15 @@
(defun shannon-entropy (input)
(let ((freq-table (make-hash-table))
(entropy 0)
(length (+ (length input) 0.0)))
(mapcar (lambda (x)
(puthash x
(+ 1 (gethash x freq-table 0))
freq-table))
input)
(maphash (lambda (k v)
(set 'entropy (+ entropy
(* (/ v length)
(log (/ v length) 2)))))
freq-table)
(- entropy)))

View file

@ -0,0 +1,2 @@
(shannon-entropy "1223334444")
1.8464393446710154

View file

@ -0,0 +1,11 @@
H[x] :=
{
N = length[x]
sum = 0
for [symbol, count] = countToDict[charList[x]]
sum = sum + count/N log[count/N, 2]
return negate[sum]
}
println[H["1223334444"]]

View 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

View file

@ -0,0 +1,9 @@
function entropy ($string) {
$n = $string.Length
$string.ToCharArray() | group | foreach{
$p = $_.Count/$n
$i = [Math]::Log($p,2)
-$p*$i
} | measure -Sum | foreach Sum
}
entropy "1223334444"