Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,63 +0,0 @@
|
|||
with Ada.Text_IO, Ada.Command_Line, Ada.Numerics.Float_Random,
|
||||
Ada.Numerics.Generic_Elementary_Functions;
|
||||
|
||||
procedure Basic_Stat is
|
||||
|
||||
package FRG renames Ada.Numerics.Float_Random;
|
||||
package TIO renames Ada.Text_IO;
|
||||
|
||||
type Counter is range 0 .. 2**31-1;
|
||||
type Result_Array is array(Natural range <>) of Counter;
|
||||
|
||||
package FIO is new TIO.Float_IO(Float);
|
||||
|
||||
procedure Put_Histogram(R: Result_Array; Scale, Full: Counter) is
|
||||
begin
|
||||
for I in R'Range loop
|
||||
FIO.Put(Float'Max(0.0, Float(I)/10.0 - 0.05),
|
||||
Fore => 1, Aft => 2, Exp => 0); TIO.Put("..");
|
||||
FIO.Put(Float'Min(1.0, Float(I)/10.0 + 0.05),
|
||||
Fore => 1, Aft => 2, Exp => 0); TIO.Put(": ");
|
||||
for J in 1 .. (R(I)* Scale)/Full loop
|
||||
Ada.Text_IO.Put("X");
|
||||
end loop;
|
||||
Ada.Text_IO.New_Line;
|
||||
end loop;
|
||||
end Put_Histogram;
|
||||
|
||||
procedure Put_Mean_Et_Al(Sample_Size: Counter;
|
||||
Val_Sum, Square_Sum: Float) is
|
||||
Mean: constant Float := Val_Sum / Float(Sample_Size);
|
||||
package Math is new Ada.Numerics.Generic_Elementary_Functions(Float);
|
||||
begin
|
||||
TIO.Put("Mean: ");
|
||||
FIO.Put(Mean, Fore => 1, Aft => 5, Exp => 0);
|
||||
TIO.Put(", Standard Deviation: ");
|
||||
FIO.Put(Math.Sqrt(abs(Square_Sum / Float(Sample_Size)
|
||||
- (Mean * Mean))), Fore => 1, Aft => 5, Exp => 0);
|
||||
TIO.New_Line;
|
||||
end Put_Mean_Et_Al;
|
||||
|
||||
N: Counter := Counter'Value(Ada.Command_Line.Argument(1));
|
||||
Gen: FRG.Generator;
|
||||
Results: Result_Array(0 .. 10) := (others => 0);
|
||||
X: Float;
|
||||
Val_Sum, Squ_Sum: Float := 0.0;
|
||||
|
||||
begin
|
||||
FRG.Reset(Gen);
|
||||
for I in 1 .. N loop
|
||||
X := FRG.Random(Gen);
|
||||
Val_Sum := Val_Sum + X;
|
||||
Squ_Sum := Squ_Sum + X*X;
|
||||
declare
|
||||
Index: Integer := Integer(X*10.0);
|
||||
begin
|
||||
Results(Index) := Results(Index) + 1;
|
||||
end;
|
||||
end loop;
|
||||
TIO.Put_Line("After sampling" & Counter'Image(N) & " random numnbers: ");
|
||||
Put_Histogram(Results, Scale => 600, Full => N);
|
||||
TIO.New_Line;
|
||||
Put_Mean_Et_Al(Sample_Size => N, Val_Sum => Val_Sum, Square_Sum => Squ_Sum);
|
||||
end Basic_Stat;
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
with Ada.Text_IO, Ada.Command_Line, Ada.Numerics.Float_Random,
|
||||
Ada.Numerics.Generic_Elementary_Functions;
|
||||
|
||||
procedure Long_Basic_Stat is
|
||||
|
||||
package FRG renames Ada.Numerics.Float_Random;
|
||||
package TIO renames Ada.Text_IO;
|
||||
|
||||
type Counter is range 0 .. 2**63-1;
|
||||
type Result_Array is array(Natural range <>) of Counter;
|
||||
type High_Precision is digits 15;
|
||||
|
||||
package FIO is new TIO.Float_IO(Float);
|
||||
|
||||
procedure Put_Histogram(R: Result_Array; Scale, Full: Counter) is
|
||||
begin
|
||||
for I in R'Range loop
|
||||
FIO.Put(Float'Max(0.0, Float(I)/10.0 - 0.05),
|
||||
Fore => 1, Aft => 2, Exp => 0); TIO.Put("..");
|
||||
FIO.Put(Float'Min(1.0, Float(I)/10.0 + 0.05),
|
||||
Fore => 1, Aft => 2, Exp => 0); TIO.Put(": ");
|
||||
for J in 1 .. (R(I)* Scale)/Full loop
|
||||
Ada.Text_IO.Put("X");
|
||||
end loop;
|
||||
Ada.Text_IO.New_Line;
|
||||
end loop;
|
||||
end Put_Histogram;
|
||||
|
||||
procedure Put_Mean_Et_Al(Sample_Size: Counter;
|
||||
Val_Sum, Square_Sum: Float) is
|
||||
Mean: constant Float := Val_Sum / Float(Sample_Size);
|
||||
package Math is new Ada.Numerics.Generic_Elementary_Functions(Float);
|
||||
begin
|
||||
TIO.Put("Mean: ");
|
||||
FIO.Put(Mean, Fore => 1, Aft => 5, Exp => 0);
|
||||
TIO.Put(", Standard Deviation: ");
|
||||
FIO.Put(Math.Sqrt(abs(Square_Sum / Float(Sample_Size)
|
||||
- (Mean * Mean))), Fore => 1, Aft => 5, Exp => 0);
|
||||
TIO.New_Line;
|
||||
end Put_Mean_Et_Al;
|
||||
|
||||
N: Counter := Counter'Value(Ada.Command_Line.Argument(1));
|
||||
Gen: FRG.Generator;
|
||||
Results: Result_Array(0 .. 10) := (others => 0);
|
||||
X: Float;
|
||||
Val_Sum, Squ_Sum: High_Precision := 0.0;
|
||||
|
||||
begin
|
||||
FRG.Reset(Gen);
|
||||
for Outer in 1 .. 1000 loop
|
||||
for I in 1 .. N/1000 loop
|
||||
X := FRG.Random(Gen);
|
||||
Val_Sum := Val_Sum + High_Precision(X);
|
||||
Squ_Sum := Squ_Sum + High_Precision(X)*High_Precision(X);
|
||||
declare
|
||||
Index: Integer := Integer(X*10.0);
|
||||
begin
|
||||
Results(Index) := Results(Index) + 1;
|
||||
end;
|
||||
end loop;
|
||||
if Outer mod 50 = 0 then
|
||||
TIO.New_Line(1);
|
||||
TIO.Put_Line(Integer'Image(Outer/10) &"% done; current results:");
|
||||
Put_Mean_Et_Al(Sample_Size => (Counter(Outer)*N)/1000,
|
||||
Val_Sum => Float(Val_Sum),
|
||||
Square_Sum => Float(Squ_Sum));
|
||||
else
|
||||
Ada.Text_IO.Put(".");
|
||||
end if;
|
||||
end loop;
|
||||
TIO.New_Line(4);
|
||||
TIO.Put_Line("After sampling" & Counter'Image(N) & " random numnbers: ");
|
||||
Put_Histogram(Results, Scale => 600, Full => N);
|
||||
TIO.New_Line;
|
||||
Put_Mean_Et_Al(Sample_Size => N,
|
||||
Val_Sum => Float(Val_Sum), Square_Sum => Float(Squ_Sum));
|
||||
end Long_Basic_Stat;
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
mean(v)={
|
||||
vecsum(v)/#v
|
||||
};
|
||||
stdev(v,mu="")={
|
||||
stdev(v,mu="")={ \\ This is the population standard deviation; for the sample standard deviation, replace #v with (#v-1) for Bessel's correction.
|
||||
if(mu=="",mu=mean(v));
|
||||
sqrt(sum(i=1,#v,(v[i]-mu)^2))/#v
|
||||
sqrt(sum(i=1,#v,(v[i]-mu)^2)/#v)
|
||||
};
|
||||
histogram(v,bins=16,low=0,high=1)={
|
||||
my(u=vector(bins),width=(high-low)/bins);
|
||||
|
|
|
|||
|
|
@ -1,36 +1,34 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">generate_statistics</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">hist</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">atom</span> <span style="color: #000000;">sum_r</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">sum_squares</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0.0</span>
|
||||
function generate_statistics(integer n)
|
||||
sequence hist = repeat(0,10)
|
||||
atom sum_r = 0,
|
||||
sum_squares = 0.0
|
||||
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">n</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #004080;">atom</span> <span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">rnd</span><span style="color: #0000FF;">()</span>
|
||||
<span style="color: #000000;">sum_r</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">r</span>
|
||||
<span style="color: #000000;">sum_squares</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">*</span><span style="color: #000000;">r</span>
|
||||
<span style="color: #000000;">hist</span><span style="color: #0000FF;">[</span><span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">10</span><span style="color: #0000FF;">*</span><span style="color: #000000;">r</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<span style="color: #004080;">atom</span> <span style="color: #000000;">mean</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">sum_r</span> <span style="color: #0000FF;">/</span> <span style="color: #000000;">n</span>
|
||||
<span style="color: #004080;">atom</span> <span style="color: #000000;">stddev</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sqrt</span><span style="color: #0000FF;">((</span><span style="color: #000000;">sum_squares</span> <span style="color: #0000FF;">/</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">-</span> <span style="color: #000000;">mean</span><span style="color: #0000FF;">*</span><span style="color: #000000;">mean</span><span style="color: #0000FF;">)</span>
|
||||
for i=1 to n do
|
||||
atom r = rnd()
|
||||
sum_r += r
|
||||
sum_squares += r*r
|
||||
hist[floor(10*r)+1] += 1
|
||||
end for
|
||||
atom mean = sum_r / n
|
||||
atom stddev = sqrt((sum_squares / n) - mean*mean)
|
||||
|
||||
<span style="color: #008080;">return</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">mean</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">stddev</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">hist</span><span style="color: #0000FF;">}</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
return {n, mean, stddev, hist}
|
||||
end function
|
||||
|
||||
<span style="color: #008080;">procedure</span> <span style="color: #000000;">display_statistics</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">x</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">atom</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">mean</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">stddev</span>
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">hist</span>
|
||||
<span style="color: #0000FF;">{</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">mean</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">stddev</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">hist</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">x</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"-- Stats for sample size %d\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">n</span><span style="color: #0000FF;">})</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"mean: %g\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">mean</span><span style="color: #0000FF;">})</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"sdev: %g\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">stddev</span><span style="color: #0000FF;">})</span>
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">hist</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">cnt</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">hist</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
|
||||
<span style="color: #004080;">string</span> <span style="color: #000000;">bars</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'='</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cnt</span><span style="color: #0000FF;">*</span><span style="color: #000000;">300</span><span style="color: #0000FF;">/</span><span style="color: #000000;">n</span><span style="color: #0000FF;">))</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%.1f: %s %d\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">i</span><span style="color: #0000FF;">/</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #000000;">bars</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cnt</span><span style="color: #0000FF;">})</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
|
||||
procedure display_statistics(sequence x)
|
||||
atom n, mean, stddev
|
||||
sequence hist
|
||||
{n, mean, stddev, hist} = x
|
||||
printf(1,"-- Stats for sample size %d\n",{n})
|
||||
printf(1,"mean: %g\n",{mean})
|
||||
printf(1,"sdev: %g\n",{stddev})
|
||||
for i=1 to length(hist) do
|
||||
integer cnt = hist[i]
|
||||
string bars = repeat('=',floor(cnt*300/n))
|
||||
printf(1,"%.1f: %s %d\n",{i/10,bars,cnt})
|
||||
end for
|
||||
end procedure
|
||||
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span> <span style="color: #008080;">to</span> <span style="color: #000000;">5</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #000000;">display_statistics</span><span style="color: #0000FF;">(</span><span style="color: #000000;">generate_statistics</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">power</span><span style="color: #0000FF;">(</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">+(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">5</span><span style="color: #0000FF;">))))</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<!--
|
||||
for n=2 to 5 do
|
||||
display_statistics(generate_statistics(power(10,n+(n=5))))
|
||||
end for
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue