Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
14
Task/Random-numbers/DuckDB/random-numbers.duckdb
Normal file
14
Task/Random-numbers/DuckDB/random-numbers.duckdb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# The Box-Muller method
|
||||
create or replace function rnv(mean, sd, u, v) as
|
||||
(select ( sqrt(-2 * ln(u)) * cos(2 * pi() * v) * sd) + mean);
|
||||
|
||||
create or replace table t as
|
||||
(with rows as (select random() as u, random() as v from unnest(range(0,1000)))
|
||||
select rnv(0, 0.5, u, v) as rnv from rows);
|
||||
|
||||
from t limit 5;
|
||||
|
||||
select avg(rnv) as average,
|
||||
stddev_samp(rnv) as 'sample stddev',
|
||||
stddev_pop(rnv) as 'population stddev'
|
||||
from t;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
-- 8 May 2025
|
||||
-- 28 Jul 2025
|
||||
include Settings
|
||||
|
||||
say 'RANDOM NUMBERS'
|
||||
|
|
@ -19,53 +19,53 @@ call Timer
|
|||
exit
|
||||
|
||||
GetUniform:
|
||||
procedure expose glob. work.
|
||||
procedure expose Memo. Work.
|
||||
arg xx
|
||||
say 'Get' xx 'uniform distributed Random numbers...'
|
||||
work. = 0
|
||||
Work. = 0
|
||||
do n = 1 to xx
|
||||
work.n = Randu()
|
||||
Work.n = Randu()
|
||||
end
|
||||
work.0 = xx
|
||||
Work.0 = xx
|
||||
say 'Done'
|
||||
say
|
||||
return
|
||||
|
||||
GetNormal:
|
||||
procedure expose glob. work.
|
||||
procedure expose Memo. Work.
|
||||
arg xx
|
||||
say 'Get' xx 'normal(1,1/2) distributed Random numbers...'
|
||||
work. = 0
|
||||
Work. = 0
|
||||
do n = 1 to xx
|
||||
work.n = Randn(1,0.5)
|
||||
Work.n = Randn(1,0.5)
|
||||
end
|
||||
work.0 = xx
|
||||
Work.0 = xx
|
||||
say 'Done'
|
||||
say
|
||||
return
|
||||
|
||||
ShowFirst:
|
||||
procedure expose work.
|
||||
procedure expose Work.
|
||||
say 'First 5 items...'
|
||||
do i = 1 to 5
|
||||
call CharOut ,work.i/1' '
|
||||
call CharOut ,Work.i/1' '
|
||||
end
|
||||
say; say
|
||||
return
|
||||
|
||||
ShowStats:
|
||||
procedure expose work.
|
||||
say 'Statistics for' work.0 'items...'
|
||||
procedure expose Memo. Work.
|
||||
say 'Statistics for' Work.0 'items...'
|
||||
sum = 0
|
||||
do n = 1 to work.0
|
||||
sum = sum+work.n
|
||||
do n = 1 to Work.0
|
||||
sum = sum+Work.n
|
||||
end
|
||||
avg = sum/work.0
|
||||
avg = sum/Work.0
|
||||
sum = 0
|
||||
do n = 1 to work.0
|
||||
sum = sum+(work.n-avg)**2
|
||||
do n = 1 to Work.0
|
||||
sum = sum+(Work.n-avg)**2
|
||||
end
|
||||
varia = sum/work.0; stdev = SqRt(varia)/1
|
||||
varia = sum/Work.0; stdev = SqRt(varia)/1
|
||||
say 'Average ' Std(avg)
|
||||
say 'Deviation' Std(stdev)
|
||||
say 'Variance ' Std(varia)
|
||||
|
|
@ -73,7 +73,7 @@ say
|
|||
return
|
||||
|
||||
ShowExact:
|
||||
procedure expose work.
|
||||
procedure expose Memo.
|
||||
say 'Exact statistics for infinite items...'
|
||||
say 'Average ' 1/2 '(1/2)'
|
||||
say 'Deviation' Std(SqRt(1/12)) '(SqRt(1/12))'
|
||||
|
|
@ -81,7 +81,4 @@ say 'Variance ' 1/12 '(1/12)'
|
|||
say
|
||||
return
|
||||
|
||||
include Functions
|
||||
include Constants
|
||||
include Helper
|
||||
include Abend
|
||||
include Math
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue