Data update

This commit is contained in:
Ingy döt Net 2024-11-04 20:28:54 -08:00
parent 52a6ef48dd
commit 157b70a810
604 changed files with 14253 additions and 2100 deletions

View file

@ -1,4 +1,4 @@
{{task heading}}
;Task
Write a stateful function, class, generator or co-routine that takes a series of floating point numbers, ''one at a time'', and returns the running [[wp:Standard Deviation|standard deviation]] of the series.

View file

@ -38,10 +38,8 @@ PROC stat object = (LONG REAL v, ACTION action)LONG REAL:
ESAC
);
[]LONG REAL v = ( 2,4,4,4,5,5,7,9 );
main:
(
# main # (
[]LONG REAL v = ( 2,4,4,4,5,5,7,9 );
LONG REAL sd;
FOR i FROM LWB v TO UPB v DO

View file

@ -27,13 +27,15 @@ OP +:= = (REF STAT lhs, LONG REAL rhs)VOID: # some syntatic sugar #
stddev OF class stat := (REF STAT self)LONG REAL:
long sqrt((variance OF class stat)(self));
OP STDDEV = ([]LONG REAL value)LONG REAL: ( # more syntatic sugar #
REF STAT stat = INIT LOC STAT;
FOR i FROM LWB value TO UPB value DO
stat +:= value[i]
OD;
(stddev OF class stat)(stat)
);
# could define STDDEV as an operator for more syntatic sugar
OP STDDEV = ([]LONG REAL value)LONG REAL: (
REF STAT stat = INIT LOC STAT;
FOR i FROM LWB value TO UPB value DO
stat +:= value[i]
OD;
(stddev OF class stat)(stat)
);
#
mean OF class stat := (REF STAT self)LONG REAL:
sum OF self/LONG REAL(num OF self);
@ -51,25 +53,20 @@ init OF class stat := (REF STAT self)REF STAT:(
self
);
[]LONG REAL value = ( 2,4,4,4,5,5,7,9 );
main:
(
# main # (
[]LONG REAL value = ( 2,4,4,4,5,5,7,9 );
# printf(($"standard deviation operator = "g(0,6)l$, STDDEV value));
#
REF STAT stat = INIT LOC STAT;
FOR i FROM LWB value TO UPB value DO
stat +:= value[i];
printf(($"value: "g(0,6)," standard dev := "g(0,6)l$, value[i], (stddev OF class stat)(stat)))
OD
OD;
#
;
printf(($"standard deviation = "g(0,6)l$, (stddev OF class stat)(stat)));
printf(($"mean = "g(0,6)l$, (mean OF class stat)(stat)));
printf(($"variance = "g(0,6)l$, (variance OF class stat)(stat)));
printf(($"count = "g(0,6)l$, (count OF class stat)(stat)))
printf(($"count = "g(0,6)l$, (count OF class stat)(stat)));
#
SKIP
)

View file

@ -0,0 +1,19 @@
double local fn CalcSD( x as double )
static double n, sum, sum2
n++
sum += x
sum2 += x * x
end fn = sqr( sum2 / n - sum * sum / n / n )
void local fn DoIt
double testData(7) = {2,4,4,4,5,5,7,9}
for int i = 0 to 7
double x = testData(i)
double a = fn CalcSD( x )
printf @"value %.0f SD = %f", x, a
next
end fn
fn DoIt
HandleEvents