PCB Environment
2
Loading...
Searching...
No Matches
pcbenv
cxx
Math
Moments.hpp
1
#ifndef GYM_PCB_MATH_STATS_H
2
#define GYM_PCB_MATH_STATS_H
3
4
#include "Defs.hpp"
5
6
namespace
math {
7
8
struct
Moments
9
{
10
float
m1{0.0f};
11
float
m2{0.0f};
12
uint N{0};
13
14
Moments
& operator+=(
float
v)
15
{
16
const
auto
m1o = m1;
17
N += 1;
18
m1 += (v - m1) / N;
19
m2 += (v - m1) * (v - m1o);
20
return
*
this
;
21
}
22
23
Moments
& operator+=(
const
Moments
&A)
24
{
25
const
uint64_t No = N;
26
const
auto
D = m1 - A.m1;
27
N += A.N;
28
m1 += (A.m1 - m1) * A.N /
float
(N);
29
m2 += A.m2 + float(No * A.N) / N * (D * D);
30
return
*
this
;
31
}
32
};
33
34
}
// namespace math
35
36
#endif
// GYM_PCB_MATH_STATS_H
math::Moments
Definition
Moments.hpp:9
Generated by
1.15.0