Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,25 +1,37 @@
|
|||
begin
|
||||
|
||||
long real sum, sum2;
|
||||
integer n;
|
||||
record CSD ( long real sumof, sum2of, sdof; integer countof );
|
||||
|
||||
long real procedure sd (long real value x) ;
|
||||
long real procedure sample ( reference(CSD) value sdv; long real value x) ;
|
||||
begin
|
||||
sum := sum + x;
|
||||
sum2 := sum2 + (x*x);
|
||||
n := n + 1;
|
||||
if n = 0 then 0 else longsqrt(sum2/n - sum*sum/n/n)
|
||||
end sd;
|
||||
long real sum, sum2;
|
||||
integer n;
|
||||
|
||||
sum := sum2 := n := 0;
|
||||
countof(sdv) := countof(sdv) + 1;
|
||||
sum := sumof(sdv);
|
||||
sum2 := sum2of(sdv);
|
||||
n := countof(sdv);
|
||||
sum := sum + x;
|
||||
sum2 := sum2 + (x*x);
|
||||
sdof(sdv) := if n = 0 then 0 else longsqrt(sum2/n - sum*sum/n/n);
|
||||
sumof(sdv) := sum;
|
||||
sum2of(sdv) := sum2;
|
||||
sdof(sdv)
|
||||
end sample;
|
||||
|
||||
r_format := "A"; r_w := 14; r_d := 6; % set output to fixed point format %
|
||||
reference(CSD) procedure NewCSD; CSD( 0, 0, 0, 0 );
|
||||
|
||||
for i := 2,4,4,4,5,5,7,9
|
||||
do begin
|
||||
long real val;
|
||||
val := i;
|
||||
write(val, sd(val))
|
||||
end for_i
|
||||
begin
|
||||
reference(CSD) sd;
|
||||
|
||||
sd := NewCSD;
|
||||
r_format := "A"; r_w := 14; r_d := 6; % set output to fixed point format %
|
||||
i_w := 6; s_w := 0; % also set integer and separator format %
|
||||
for i := 2,4,4,4,5,5,7,9 do begin
|
||||
long real val, newSd;
|
||||
val := i;
|
||||
newSd := sample( sd, val );
|
||||
write( countof(sd), ": ", val, " -> ", newSd )
|
||||
end for_i
|
||||
end
|
||||
end.
|
||||
|
|
|
|||
|
|
@ -1,35 +0,0 @@
|
|||
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;
|
||||
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
|
||||
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
|
||||
|
||||
procedure Test_Deviation is
|
||||
type Sample is record
|
||||
N : Natural := 0;
|
||||
Sum : Float := 0.0;
|
||||
SumOfSquares : Float := 0.0;
|
||||
end record;
|
||||
procedure Add (Data : in out Sample; Point : Float) is
|
||||
begin
|
||||
Data.N := Data.N + 1;
|
||||
Data.Sum := Data.Sum + Point;
|
||||
Data.SumOfSquares := Data.SumOfSquares + Point ** 2;
|
||||
end Add;
|
||||
function Deviation (Data : Sample) return Float is
|
||||
begin
|
||||
return Sqrt (Data.SumOfSquares / Float (Data.N) - (Data.Sum / Float (Data.N)) ** 2);
|
||||
end Deviation;
|
||||
|
||||
Data : Sample;
|
||||
Test : array (1..8) of Integer := (2, 4, 4, 4, 5, 5, 7, 9);
|
||||
begin
|
||||
for Index in Test'Range loop
|
||||
Add (Data, Float(Test(Index)));
|
||||
Put("N="); Put(Item => Index, Width => 1);
|
||||
Put(" ITEM="); Put(Item => Test(Index), Width => 1);
|
||||
Put(" AVG="); Put(Item => Float(Data.Sum)/Float(Index), Fore => 1, Aft => 3, Exp => 0);
|
||||
Put(" STDDEV="); Put(Item => Deviation (Data), Fore => 1, Aft => 3, Exp => 0);
|
||||
New_line;
|
||||
end loop;
|
||||
end Test_Deviation;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
arr: new []
|
||||
arr: []
|
||||
loop [2 4 4 4 5 5 7 9] 'value [
|
||||
'arr ++ value
|
||||
print [value "->" deviation arr]
|
||||
|
|
|
|||
|
|
@ -1,71 +0,0 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. run-stddev.
|
||||
environment division.
|
||||
input-output section.
|
||||
file-control.
|
||||
select input-file assign to "input.txt"
|
||||
organization is line sequential.
|
||||
data division.
|
||||
file section.
|
||||
fd input-file.
|
||||
01 inp-record.
|
||||
03 inp-fld pic 9(03).
|
||||
working-storage section.
|
||||
01 filler pic 9(01) value 0.
|
||||
88 no-more-input value 1.
|
||||
01 ws-tb-data.
|
||||
03 ws-tb-size pic 9(03).
|
||||
03 ws-tb-table.
|
||||
05 ws-tb-fld pic s9(05)v9999 comp-3 occurs 0 to 100 times
|
||||
depending on ws-tb-size.
|
||||
01 ws-stddev pic s9(05)v9999 comp-3.
|
||||
PROCEDURE DIVISION.
|
||||
move 0 to ws-tb-size
|
||||
open input input-file
|
||||
read input-file
|
||||
at end
|
||||
set no-more-input to true
|
||||
end-read
|
||||
perform
|
||||
test after
|
||||
until no-more-input
|
||||
add 1 to ws-tb-size
|
||||
move inp-fld to ws-tb-fld (ws-tb-size)
|
||||
call 'stddev' using by reference ws-tb-data
|
||||
ws-stddev
|
||||
display 'inp=' inp-fld ' stddev=' ws-stddev
|
||||
read input-file at end set no-more-input to true end-read
|
||||
end-perform
|
||||
close input-file
|
||||
stop run.
|
||||
end program run-stddev.
|
||||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. stddev.
|
||||
data division.
|
||||
working-storage section.
|
||||
01 ws-tbx pic s9(03) comp.
|
||||
01 ws-tb-work.
|
||||
03 ws-sum pic s9(05)v9999 comp-3 value +0.
|
||||
03 ws-sumsq pic s9(05)v9999 comp-3 value +0.
|
||||
03 ws-avg pic s9(05)v9999 comp-3 value +0.
|
||||
linkage section.
|
||||
01 ws-tb-data.
|
||||
03 ws-tb-size pic 9(03).
|
||||
03 ws-tb-table.
|
||||
05 ws-tb-fld pic s9(05)v9999 comp-3 occurs 0 to 100 times
|
||||
depending on ws-tb-size.
|
||||
01 ws-stddev pic s9(05)v9999 comp-3.
|
||||
PROCEDURE DIVISION using ws-tb-data ws-stddev.
|
||||
compute ws-sum = 0
|
||||
perform test before varying ws-tbx from 1 by +1 until ws-tbx > ws-tb-size
|
||||
compute ws-sum = ws-sum + ws-tb-fld (ws-tbx)
|
||||
end-perform
|
||||
compute ws-avg rounded = ws-sum / ws-tb-size
|
||||
compute ws-sumsq = 0
|
||||
perform test before varying ws-tbx from 1 by +1 until ws-tbx > ws-tb-size
|
||||
compute ws-sumsq = ws-sumsq
|
||||
+ (ws-tb-fld (ws-tbx) - ws-avg) ** 2.0
|
||||
end-perform
|
||||
compute ws-stddev = ( ws-sumsq / ws-tb-size) ** 0.5
|
||||
goback.
|
||||
end program stddev.
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
sample output:
|
||||
inp=002 stddev=+00000.0000
|
||||
inp=004 stddev=+00001.0000
|
||||
inp=004 stddev=+00000.9427
|
||||
inp=004 stddev=+00000.8660
|
||||
inp=005 stddev=+00000.9797
|
||||
inp=005 stddev=+00001.0000
|
||||
inp=007 stddev=+00001.3996
|
||||
inp=009 stddev=+00002.0000
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
(defun running-std (items)
|
||||
(let ((running-sum 0)
|
||||
(running-len 0)
|
||||
(running-squared-sum 0)
|
||||
(result 0))
|
||||
(dolist (item items)
|
||||
(setq running-sum (+ running-sum item))
|
||||
(setq running-len (1+ running-len))
|
||||
(setq running-squared-sum (+ running-squared-sum (* item item)))
|
||||
(setq result (sqrt (- (/ running-squared-sum (float running-len))
|
||||
(/ (* running-sum running-sum)
|
||||
(float (* running-len running-len))))))
|
||||
(message "%f" result))
|
||||
result))
|
||||
|
||||
(running-std '(2 4 4 4 5 5 7 9))
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
(let ((x '(2 4 4 4 5 5 7 9)))
|
||||
(string-to-number (calc-eval "sqrt(vpvar($1))" nil (append '(vec) x))))
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
;; lexical-binding: t
|
||||
(require 'generator)
|
||||
|
||||
(iter-defun std-dev-gen (lst)
|
||||
(let ((sum 0)
|
||||
(avg 0)
|
||||
(tmp '())
|
||||
(std 0))
|
||||
(dolist (i lst)
|
||||
(setq i (float i))
|
||||
(push i tmp)
|
||||
(setq sum (+ sum i))
|
||||
(setq avg (/ sum (length tmp)))
|
||||
(setq std 0)
|
||||
(dolist (j tmp)
|
||||
(setq std (+ std (expt (- j avg) 2))))
|
||||
(setq std (/ std (length tmp)))
|
||||
(setq std (sqrt std))
|
||||
(iter-yield std))))
|
||||
|
||||
(let* ((test-data '(2 4 4 4 5 5 7 9))
|
||||
(generator (std-dev-gen test-data)))
|
||||
(dolist (i test-data)
|
||||
(message "with %d: %f" i (iter-next generator))))
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
using Lambda;
|
||||
|
||||
class Main {
|
||||
static function main():Void {
|
||||
var nums = [2, 4, 4, 4, 5, 5, 7, 9];
|
||||
for (i in 1...nums.length+1)
|
||||
Sys.println(sdev(nums.slice(0, i)));
|
||||
}
|
||||
|
||||
static function average<T:Float>(nums:Array<T>):Float {
|
||||
return nums.fold(function(n, t) return n + t, 0) / nums.length;
|
||||
}
|
||||
|
||||
static function sdev<T:Float>(nums:Array<T>):Float {
|
||||
var store = [];
|
||||
var avg = average(nums);
|
||||
for (n in nums) {
|
||||
store.push((n - avg) * (n - avg));
|
||||
}
|
||||
|
||||
return Math.sqrt(average(store));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
|
||||
|
||||
<span style="color: #004080;">atom</span> <span style="color: #000000;">sdn</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">sdsum</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">sdsumsq</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
|
||||
|
||||
<span style="color: #008080;">procedure</span> <span style="color: #000000;">sdadd</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;">sdn</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
|
||||
<span style="color: #000000;">sdsum</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">n</span>
|
||||
<span style="color: #000000;">sdsumsq</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: #008080;">end</span> <span style="color: #008080;">procedure</span>
|
||||
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">sdavg</span><span style="color: #0000FF;">()</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">sdsum</span><span style="color: #0000FF;">/</span><span style="color: #000000;">sdn</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">sddev</span><span style="color: #0000FF;">()</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #7060A8;">sqrt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">sdsumsq</span><span style="color: #0000FF;">/</span><span style="color: #000000;">sdn</span> <span style="color: #0000FF;">-</span> <span style="color: #7060A8;">power</span><span style="color: #0000FF;">(</span><span style="color: #000000;">sdsum</span><span style="color: #0000FF;">/</span><span style="color: #000000;">sdn</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">))</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
|
||||
<span style="color: #000080;font-style:italic;">--test code:</span>
|
||||
<span style="color: #008080;">constant</span> <span style="color: #000000;">testset</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">}</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">ti</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;">testset</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #000000;">ti</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">testset</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
|
||||
<span style="color: #000000;">sdadd</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ti</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;">"N=%d Item=%d Avg=%5.3f StdDev=%5.3f\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ti</span><span style="color: #0000FF;">,</span><span style="color: #000000;">sdavg</span><span style="color: #0000FF;">(),</span><span style="color: #000000;">sddev</span><span style="color: #0000FF;">()})</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<!--
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
function Get-StandardDeviation {
|
||||
begin {
|
||||
$avg = 0
|
||||
$nums = @()
|
||||
}
|
||||
process {
|
||||
$nums += $_
|
||||
$avg = ($nums | Measure-Object -Average).Average
|
||||
$sum = 0;
|
||||
$nums | ForEach-Object { $sum += ($avg - $_) * ($avg - $_) }
|
||||
[Math]::Sqrt($sum / $nums.Length)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +1,12 @@
|
|||
dim sdSave$(100) 'can call up to 100 versions
|
||||
'holds (space-separated) number of data , sum of values and sum of squares
|
||||
sd$ = "2,4,4,4,5,5,7,9"
|
||||
|
||||
for num = 1 to 8
|
||||
stdData = val(word$(sd$,num,","))
|
||||
stdData = val(word$(sd$,num,","))
|
||||
sumVal = sumVal + stdData
|
||||
sumSqs = sumSqs + stdData^2
|
||||
|
||||
' standard deviation = square root of (the average of the squares less the square of the average)
|
||||
' standard deviation = square root of (the average of the squares less the square of the average)
|
||||
standDev =((sumSqs / num) - (sumVal /num) ^ 2) ^ 0.5
|
||||
|
||||
sdSave$(num) = str$(num);" ";str$(sumVal);" ";str$(sumSqs)
|
||||
print num;" value in = ";stdData; " Stand Dev = "; using("###.######", standDev)
|
||||
|
||||
next num
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
data = Array(2,4,4,4,5,5,7,9)
|
||||
|
||||
For i = 0 To UBound(data)
|
||||
WScript.StdOut.Write "value = " & data(i) &_
|
||||
" running sd = " & sd(data,i)
|
||||
WScript.StdOut.WriteLine
|
||||
Next
|
||||
|
||||
Function sd(arr,n)
|
||||
mean = 0
|
||||
variance = 0
|
||||
For j = 0 To n
|
||||
mean = mean + arr(j)
|
||||
Next
|
||||
mean = mean/(n+1)
|
||||
For k = 0 To n
|
||||
variance = variance + ((arr(k)-mean)^2)
|
||||
Next
|
||||
variance = variance/(n+1)
|
||||
sd = FormatNumber(Sqr(variance),6)
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue