Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,20 @@
|
|||
function running_stddev() {
|
||||
var n = 0;
|
||||
var sum = 0.0;
|
||||
var sum_sq = 0.0;
|
||||
return function(num) {
|
||||
n++;
|
||||
sum += num;
|
||||
sum_sq += num*num;
|
||||
return Math.sqrt( (sum_sq / n) - Math.pow(sum / n, 2) );
|
||||
}
|
||||
}
|
||||
|
||||
var sd = running_stddev();
|
||||
var nums = [2,4,4,4,5,5,7,9];
|
||||
var stddev = [];
|
||||
for (var i in nums)
|
||||
stddev.push( sd(nums[i]) );
|
||||
|
||||
// using WSH
|
||||
WScript.Echo(stddev.join(', ');
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
(function (xs) {
|
||||
|
||||
return xs.reduce(function (a, x, i) {
|
||||
var n = i + 1,
|
||||
sum_ = a.sum + x,
|
||||
squaresSum_ = a.squaresSum + (x * x);
|
||||
|
||||
return {
|
||||
sum: sum_,
|
||||
squaresSum: squaresSum_,
|
||||
stages: a.stages.concat(
|
||||
Math.sqrt((squaresSum_ / n) - Math.pow((sum_ / n), 2))
|
||||
)
|
||||
};
|
||||
|
||||
}, {
|
||||
sum: 0,
|
||||
squaresSum: 0,
|
||||
stages: []
|
||||
}).stages
|
||||
|
||||
})([2, 4, 4, 4, 5, 5, 7, 9]);
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
[0, 1, 0.9428090415820626, 0.8660254037844386,
|
||||
0.9797958971132716, 1, 1.3997084244475297, 2]
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
(() => {
|
||||
'use strict';
|
||||
|
||||
// ---------- CUMULATIVE STANDARD DEVIATION ----------
|
||||
|
||||
// cumulativeStdDevns :: [Float] -> [Float]
|
||||
const cumulativeStdDevns = ns => {
|
||||
const go = ([s, q]) =>
|
||||
([i, x]) => {
|
||||
const
|
||||
_s = s + x,
|
||||
_q = q + (x * x),
|
||||
j = 1 + i;
|
||||
return [
|
||||
[_s, _q],
|
||||
Math.sqrt(
|
||||
(_q / j) - Math.pow(_s / j, 2)
|
||||
)
|
||||
];
|
||||
};
|
||||
return mapAccumL(go)([0, 0])(ns)[1];
|
||||
};
|
||||
|
||||
// ---------------------- TEST -----------------------
|
||||
const main = () =>
|
||||
showLog(
|
||||
cumulativeStdDevns([
|
||||
2, 4, 4, 4, 5, 5, 7, 9
|
||||
])
|
||||
);
|
||||
|
||||
// --------------------- GENERIC ---------------------
|
||||
|
||||
// mapAccumL :: (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])
|
||||
const mapAccumL = f =>
|
||||
// A tuple of an accumulation and a list
|
||||
// obtained by a combined map and fold,
|
||||
// with accumulation from left to right.
|
||||
acc => xs => [...xs].reduce((a, x, i) => {
|
||||
const pair = f(a[0])([i, x]);
|
||||
return [pair[0], a[1].concat(pair[1])];
|
||||
}, [acc, []]);
|
||||
|
||||
|
||||
// showLog :: a -> IO ()
|
||||
const showLog = (...args) =>
|
||||
console.log(
|
||||
args
|
||||
.map(x => JSON.stringify(x, null, 2))
|
||||
.join(' -> ')
|
||||
);
|
||||
|
||||
// MAIN ---
|
||||
return main();
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue