Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
4
Task/Statistics-Basic/Zkl/statistics-basic-1.zkl
Normal file
4
Task/Statistics-Basic/Zkl/statistics-basic-1.zkl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
fcn mean(ns) { ns.sum(0.0)/ns.len() }
|
||||
fcn stdDev(ns){
|
||||
m:=mean(ns); (ns.reduce('wrap(p,n){ x:=(n-m); p+x*x },0.0)/ns.len()).sqrt()
|
||||
}
|
||||
9
Task/Statistics-Basic/Zkl/statistics-basic-2.zkl
Normal file
9
Task/Statistics-Basic/Zkl/statistics-basic-2.zkl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
reg ns;
|
||||
foreach n in (T(100,1000,10000)){
|
||||
ns=(0).pump(n,List,(0.0).random.fp(1.0));
|
||||
println("N:%,6d mean:%.5f std dev:%.5f".fmt(n,mean(ns),stdDev(ns)));
|
||||
}
|
||||
foreach r in ([0.0 .. 0.9, 0.1]){ // using the last data set (10000 randoms)
|
||||
n:=ns.filter('wrap(x){ r<=x<(r+0.1) }).len();
|
||||
println("%.2f..%.2f:%4d%s".fmt(r,r+0.1,n,"*"*(n/20)));
|
||||
}
|
||||
13
Task/Statistics-Basic/Zkl/statistics-basic-3.zkl
Normal file
13
Task/Statistics-Basic/Zkl/statistics-basic-3.zkl
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
var pipe=Thread.Pipe(); // used to connect the two threads
|
||||
fcn{ while(1){ pipe.write((0.0).random(1.0)) } }.launch(); // generator
|
||||
fcn{ // consumer/calculator
|
||||
N:=0; M:=SD:=sum:=ssum:=0.0;
|
||||
while(1){
|
||||
x:=pipe.read(); N+=1; sum+=x; ssum+=x*x;
|
||||
M=sum/N; SD=(ssum/N - M*M).sqrt();
|
||||
if(0==N%100000)
|
||||
println("N:%,10d mean:%.5f std dev:%.5f".fmt(N,M,SD));
|
||||
}
|
||||
}.launch();
|
||||
|
||||
Atomic.sleep(60*60); // wait because exiting the VM kills the threads
|
||||
Loading…
Add table
Add a link
Reference in a new issue