Skip to content

Commit

Permalink
Working towards covariance
Browse files Browse the repository at this point in the history
  • Loading branch information
Yomguithereal committed Nov 21, 2024
1 parent 1c3f3ee commit 20dde77
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/moonblade/agg/aggregators/welford.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NOTE: this is an implementation of Welford's online algorithm
// Ref: https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
// Ref: https://en.wikipedia.org/wiki/Standard_deviation
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct Welford {
count: usize,
mean: f64,
Expand All @@ -10,11 +10,7 @@ pub struct Welford {

impl Welford {
pub fn new() -> Self {
Self {
count: 0,
mean: 0.0,
m2: 0.0,
}
Self::default()
}

pub fn clear(&mut self) {
Expand Down Expand Up @@ -83,3 +79,29 @@ impl Welford {
+ ((count1 * count2 * mean_diff_squared) / (total * total));
}
}

// NOTE: https://stackoverflow.com/questions/45773857/merging-covariance-from-two-sets-to-create-new-covariance
// #[derive(Debug, Clone, Default)]
// pub struct CovarianceWelford {
// count: usize,
// mean_x: f64,
// mean_y: f64,
// m2_x: f64,
// m2_y: f64,
// c: f64,
// }

// impl CovarianceWelford {
// pub fn new() -> Self {
// Self::default()
// }

// pub fn clear(&mut self) {
// self.count = 0;
// self.mean_x = 0.0;
// self.mean_y = 0.0;
// self.m2_x = 0.0;
// self.m2_y = 0.0;
// self.c = 0.0;
// }
// }

0 comments on commit 20dde77

Please sign in to comment.