diff OrthancStone/Sources/Toolbox/LinearAlgebra.h @ 1984:187a261d7ae2

computation of mean and stddev in rectangle probes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 31 Oct 2022 14:42:46 +0100
parents 6ce81914f7e4
children 07964689cb0b
line wrap: on
line diff
--- a/OrthancStone/Sources/Toolbox/LinearAlgebra.h	Mon Oct 31 12:32:47 2022 +0100
+++ b/OrthancStone/Sources/Toolbox/LinearAlgebra.h	Mon Oct 31 14:42:46 2022 +0100
@@ -46,6 +46,35 @@
 
   namespace LinearAlgebra
   {
+    class OnlineVarianceEstimator
+    {
+    private:
+      unsigned int  count_;
+      double        sum_;
+      double        sumOfSquares_;
+
+    public:
+      OnlineVarianceEstimator()
+      {
+        Clear();
+      }
+
+      unsigned int GetCount() const
+      {
+        return count_;
+      }
+
+      void AddSample(double value);
+
+      void Clear();
+
+      double GetMean() const;  // Same as "mean()" in Matlab/Octave
+
+      double GetVariance() const;  // Same as "var()" in Matlab/Octave
+
+      double GetStandardDeviation() const;  // Same as "std()" in Matlab/Octave
+    };
+    
     void Print(const Vector& v);
 
     void Print(const Matrix& m);
@@ -301,5 +330,5 @@
     double ComputeMedian(std::vector<double>& v);
 
     float ComputeMedian(std::vector<float>& v);
-  };
+  }
 }