Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,32 @@
pub struct CumulativeStandardDeviation {
n: f64,
sum: f64,
sum_sq: f64
}
impl CumulativeStandardDeviation {
pub fn new() -> Self {
CumulativeStandardDeviation {
n: 0.,
sum: 0.,
sum_sq: 0.
}
}
fn push(&mut self, x: f64) -> f64 {
self.n += 1.;
self.sum += x;
self.sum_sq += x * x;
(self.sum_sq / self.n - self.sum * self.sum / self.n / self.n).sqrt()
}
}
fn main() {
let nums = [2, 4, 4, 4, 5, 5, 7, 9];
let mut cum_stdev = CumulativeStandardDeviation::new();
for num in nums.iter() {
println!("{}", cum_stdev.push(*num as f64));
}
}

View file

@ -0,0 +1,20 @@
fn sd_creator() -> impl FnMut(f64) -> f64 {
let mut n = 0.0;
let mut sum = 0.0;
let mut sum_sq = 0.0;
move |x| {
sum += x;
sum_sq += x*x;
n += 1.0;
(sum_sq / n - sum * sum / n / n).sqrt()
}
}
fn main() {
let nums = [2, 4, 4, 4, 5, 5, 7, 9];
let mut sd_acc = sd_creator();
for num in nums.iter() {
println!("{}", sd_acc(*num as f64));
}
}