Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,56 +0,0 @@
|
|||
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Strings.Unbounded,
|
||||
Ada.Strings.Unbounded.Text_IO, Ada.Numerics.Long_Elementary_Functions,
|
||||
Ada.Long_Float_Text_IO;
|
||||
use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Strings.Unbounded,
|
||||
Ada.Strings.Unbounded.Text_IO, Ada.Numerics.Long_Elementary_Functions,
|
||||
Ada.Long_Float_Text_IO;
|
||||
|
||||
procedure Fibonacci_Words is
|
||||
|
||||
function Entropy (S : Unbounded_String) return Long_Float is
|
||||
CF : array (Character) of Natural := (others => 0);
|
||||
Len : constant Natural := Length (S);
|
||||
H : Long_Float := 0.0;
|
||||
Ratio : Long_Float;
|
||||
begin
|
||||
for I in 1 .. Len loop
|
||||
CF (Element (S, I)) := CF (Element (S, I)) + 1;
|
||||
end loop;
|
||||
for C in Character loop
|
||||
Ratio := Long_Float (CF (C)) / Long_Float (Len);
|
||||
if Ratio /= 0.0 then
|
||||
H := H - Ratio * Log (Ratio, 2.0);
|
||||
end if;
|
||||
end loop;
|
||||
return H;
|
||||
end Entropy;
|
||||
|
||||
procedure Print_Line (Word : Unbounded_String; Number : Integer) is
|
||||
begin
|
||||
Put (Number, 4);
|
||||
Put (Length (Word), 10);
|
||||
Put (Entropy (Word), 2, 15, 0);
|
||||
if Length (Word) < 35 then
|
||||
Put (" " & Word);
|
||||
end if;
|
||||
New_Line;
|
||||
end Print_Line;
|
||||
|
||||
First, Second, Result : Unbounded_String;
|
||||
|
||||
begin
|
||||
Set_Col (4); Put ("N");
|
||||
Set_Col (9); Put ("Length");
|
||||
Set_Col (16); Put ("Entropy");
|
||||
Set_Col (35); Put_Line ("Word");
|
||||
First := To_Unbounded_String ("1");
|
||||
Print_Line (First, 1);
|
||||
Second := To_Unbounded_String ("0");
|
||||
Print_Line (Second, 2);
|
||||
for N in 3 .. 37 loop
|
||||
Result := Second & First;
|
||||
Print_Line (Result, N);
|
||||
First := Second;
|
||||
Second := Result;
|
||||
end loop;
|
||||
end Fibonacci_Words;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
entropy: function [s][
|
||||
if 1 >= size s -> return 0.0
|
||||
strlen: to :floating size s
|
||||
count0: to :floating size match s "0"
|
||||
count0: to :floating match.count s "0"
|
||||
count1: strlen - count0
|
||||
return neg add (count0/strlen) * log count0/strlen 2 (count1/strlen) * log count1/strlen 2
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
func log2 x .
|
||||
return log10 x / log10 2
|
||||
.
|
||||
func entropy s$ .
|
||||
l = len s$
|
||||
if l <= 1 : return 0
|
||||
|
|
@ -8,7 +5,7 @@ func entropy s$ .
|
|||
cnt0 += if v$ = "0"
|
||||
.
|
||||
cnt1 = l - cnt0
|
||||
return -(cnt0 / l * log2 (cnt0 / l) + cnt1 / l * log2 (cnt1 / l))
|
||||
return -(cnt0 / l * log (cnt0 / l) 2 + cnt1 / l * log (cnt1 / l) 2)
|
||||
.
|
||||
a$ = ""
|
||||
b$ = ""
|
||||
|
|
|
|||
|
|
@ -1,14 +1,5 @@
|
|||
# Build the string recursively.
|
||||
F ← |1 memo⟨⟨⊂∩F-1.-1|"0"◌⟩=2.|"1"◌⟩=1.
|
||||
# General entropy formula - quite slow for this task.
|
||||
Egen ← /+(¯×ₙ2.)÷/+.≡(⧻⊚=)⊃◴¤
|
||||
# Specific entropy formula for a binary string.
|
||||
E ← ⍥(0◌)=NaN.+∩(¯×ₙ2.)⟜(¯-1)÷⊃⧻(⧻⊚="1")
|
||||
# Nothing clever, just do the maths, super fast :-)
|
||||
Fx ← |1 memo⨬(⨬(+˜∩Fx⊸-₁-1|⋅1_0)⊸=₂|⋅0_1)⊸=₁
|
||||
Ex ← ⍥⋅0⊸=NaN/+(¯×⊸⌝˜ⁿ2)÷⊸/+
|
||||
|
||||
# Much faster approach -- don't even build the string, just count
|
||||
# how many "0"s and "1"s the string will have.
|
||||
Fx ← |1 memo⟨⟨+∩Fx-1.-1|[1 0]◌⟩=2.|[0 1]◌⟩=1.
|
||||
Ex ← ⍥(0◌)=NaN./+(¯×ₙ2.)÷/+.
|
||||
|
||||
# Print and time it
|
||||
⍜now(≡(⇌[⊃/+ (⍜(×1e8)⁅Ex)Fx.])+1⇡37)
|
||||
≡(⇌[⊃/+(⁅₈Ex)⊸Fx])+1⇡37
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue