Go to the documentation of this file.
42 #ifndef INCLUDE_GNSSTK_STATS_INCLUDE
43 #define INCLUDE_GNSSTK_STATS_INCLUDE
61 const int n(v.
size());
64 if(n==2)
return (v(0)+v(1))/T(2);
72 while(j>=0 && x<w[j]) {
79 if(n % 2)
return (w[(n+1)/2-1]);
80 return ((w[n/2-1]+w[n/2])/T(2));
87 if (v.
size() < 2)
return T();
91 for(
size_t i=0; i < w.
size(); i++)
92 w[i] = std::abs(w[i]- med);
98 template <
class T>
inline T
median(
const std::vector<T>& v)
100 const unsigned int n(v.size());
104 std::sort(w.begin(), w.end());
106 if (n % 2)
return w[(n+1)/2-1];
107 return ((w[n/2-1]+w[n/2])/T(2));
111 template <
class T>
inline T
mad(
const std::vector<T>& v)
113 if (v.size() < 2)
return T();
117 for(
size_t i=0; i < w.size(); i++)
118 w[i] = std::abs(w[i]- med);
181 if(
n == 1) {
n = 0;
return; }
191 for(
size_t i=0; i < X.
size(); i++)
Add(X(i));
195 inline void Add(std::vector<T>& X)
197 for(
size_t i=0; i<X.size(); i++)
Add(X[i]);
213 for(
size_t i=0; i<X.size(); i++)
Subtract(X[i]);
239 if(
n <= S.
n) {
Reset();
return *
this; }
252 void Dump(std::vector<unsigned int>&
vuint, std::vector<T>& vT)
259 vT.push_back(
min); vT.push_back(
max);
260 vT.push_back(
sum); vT.push_back(
sum2);
269 void Load(
const std::vector<unsigned int>&
vuint,
const std::vector<T>& vT)
271 if(
vuint.size() < 2 || vT.size() < 4) {
290 std::string
asString(std::string msg=std::string(),
int w=7,
int p=4)
const
292 std::ostringstream oss;
294 oss <<
"stats(con):" << (msg.empty() ?
"" :
" "+msg)
295 <<
" N " << std::setw(w) <<
N() << std::fixed << std::setprecision(p)
296 <<
" Ave " << std::setw(w) <<
Average()
297 <<
" Std " << std::setw(w) <<
StdDev()
298 <<
" Var " << std::setw(w) <<
Variance()
299 <<
" Min " << std::setw(w) <<
Minimum()
300 <<
" Max " << std::setw(w) <<
Maximum()
306 std::string
asShortString(std::string msg=std::string(),
int w=0,
int p=3)
const
308 std::ostringstream oss;
309 oss << msg << std::fixed << std::setprecision(p)
310 <<
" N " << std::setw(w) <<
N()
311 <<
" Ave " << std::setw(w) <<
Average()
312 <<
" Std " << std::setw(w) <<
StdDev();
318 inline unsigned int N(
void)
const {
return n; }
322 {
if(
n)
return min;
else return T(); }
326 {
if(
n)
return max;
else return T(); }
352 {
if(
n)
return scale;
else return T(); }
368 std::ofstream savefmt;
370 s <<
" N = " << ST.
N() <<
" (1-sample statistics)\n";
371 s <<
" Minimum = "; s.copyfmt(savefmt); s << ST.
Minimum();
372 s <<
" Maximum = "; s.copyfmt(savefmt); s << ST.
Maximum() <<
"\n";
373 s <<
" Average = "; s.copyfmt(savefmt); s << ST.
Average();
374 s <<
" Std Dev = "; s.copyfmt(savefmt); s << ST.
StdDev();
375 s <<
" Variance = "; s.copyfmt(savefmt); s << ST.
Variance();
439 for(
size_t i=0; i<X.
size(); i++)
Add(X(i));
443 inline void Add(std::vector<T>& X)
445 for(
size_t i=0; i<X.size(); i++)
Add(X[i]);
461 for(
size_t i=0; i<X.size(); i++)
Subtract(X[i]);
469 if(S.
n == 0)
return *
this;
470 if(
n==0) { *
this = S;
return *
this; }
477 ave = newave/T(
n+S.
n);
490 if(
n <= S.
n) {
n=0;
return *
this; }
494 ave = newave/T(
n-S.
n);
507 void Dump(std::vector<unsigned int>&
vuint, std::vector<T>& vT)
513 vT.push_back(
min); vT.push_back(
max);
514 vT.push_back(
ave); vT.push_back(
var);
523 void Load(
const std::vector<unsigned int>&
vuint,
const std::vector<T>& vT)
525 if(
vuint.size() < 1 || vT.size() < 4) {
540 std::string
asString(std::string msg=std::string(),
int w=7,
int p=4)
const
542 std::ostringstream oss;
544 oss <<
"stats(seq):" << (msg.empty() ?
"" :
" "+msg)
545 <<
" N " << std::setw(w) <<
N() << std::fixed << std::setprecision(p)
546 <<
" Ave " << std::setw(w) <<
Average()
547 <<
" Std " << std::setw(w) <<
StdDev()
548 <<
" Var " << std::setw(w) <<
Variance()
549 <<
" Min " << std::setw(w) <<
Minimum()
550 <<
" Max " << std::setw(w) <<
Maximum()
556 std::string
asShortString(std::string msg=std::string(),
int w=0,
int p=3)
const
558 std::ostringstream oss;
559 oss << msg << std::fixed << std::setprecision(p)
560 <<
" N " << std::setw(w) <<
N()
561 <<
" Ave " << std::setw(w) <<
Average()
562 <<
" Std " << std::setw(w) <<
StdDev();
568 inline unsigned int N(
void)
const {
return n; }
571 inline T
Minimum(
void)
const {
if(
n)
return min;
else return T(); }
574 inline T
Maximum(
void)
const {
if(
n)
return max;
else return T(); }
577 inline T
Average(
void)
const {
if(
n == 0)
return T();
return ave; }
582 if(
n <= 1)
return T();
583 return (T(
n)*
var/T(
n-1));
589 if(
n <= 1)
return T();
605 std::ofstream savefmt;
607 s <<
" N = " << ST.
N() <<
" (1-sample stats, seq.impl.)\n";
608 s <<
" Minimum = "; s.copyfmt(savefmt); s << ST.
Minimum();
609 s <<
" Maximum = "; s.copyfmt(savefmt); s << ST.
Maximum() <<
"\n";
610 s <<
" Average = "; s.copyfmt(savefmt); s << ST.
Average();
611 s <<
" Std Dev = "; s.copyfmt(savefmt); s << ST.
StdDev();
612 s <<
" Variance = "; s.copyfmt(savefmt); s << ST.
Variance();
638 void Add(
const T& x,
const T& wt_in)
641 if(wt == T())
return;
671 if(wt == T())
return;
690 inline void Add(std::vector<T>& X, std::vector<T>& W)
692 for(
size_t i=0; i<(X.size()>W.size() ? W.size():X.size()); i++)
703 for(i=0; i<nn; i++)
Subtract(X[i],W[i]);
710 inline void Subtract(std::vector<T>& X, std::vector<T>& W)
712 size_t i, nn(X.size() > W.size() ? W.size() : X.size());
713 for(i=0; i<nn; i++)
Subtract(X[i],W[i]);
724 { *
this = S;
return *
this; }
767 void Dump(std::vector<unsigned int>&
vuint, std::vector<T>& vT)
779 void Load(std::vector<unsigned int>&
vuint, std::vector<T>& vT)
781 if(
vuint.size() < 1 || vT.size() < 5) {
785 for(
size_t i=0; i<5; i++) vT.push_back(T(0));
794 std::string
asString(std::string msg=std::string(),
int w=7,
int p=4)
const
796 std::ostringstream oss;
797 oss <<
"stats(wtd):" << (msg.empty() ?
"" :
" "+msg)
799 << std::fixed << std::setprecision(p)
805 <<
" P2P " << std::setw(w)
807 <<
" Wts " << std::setw(w) <<
WtsSum();
812 std::string
asShortString(std::string msg=std::string(),
int w=0,
int p=3)
const
814 std::ostringstream oss;
815 oss << msg << std::fixed << std::setprecision(p)
833 std::ofstream savefmt;
835 s <<
" N = " << ST.
N() <<
" (weighted 1-sample stats)\n";
836 s <<
" Minimum = "; s.copyfmt(savefmt); s << ST.
Minimum();
837 s <<
" Maximum = "; s.copyfmt(savefmt); s << ST.
Maximum() <<
"\n";
838 s <<
" Average = "; s.copyfmt(savefmt); s << ST.
Average();
839 s <<
" Std Dev = "; s.copyfmt(savefmt); s << ST.
StdDev();
840 s <<
" Variance = "; s.copyfmt(savefmt); s << ST.
Variance() <<
"\n";
841 s <<
" SumWts = "; s.copyfmt(savefmt); s << ST.
WtsSum();
849 template <
class T>
class TwoSampleStats
867 void Add(
const T& x,
const T&
y)
882 if(
n == 1) {
Reset();
return; }
892 for(
size_t i=0; i<(X.
size()<
Y.size() ? X.
size():
Y.size()); i++)
897 void Add(
const std::vector<T>& X,
const std::vector<T>& Y)
899 for(
size_t i=0; i<(X.size()<
Y.size() ? X.size():
Y.size()); i++)
906 for(
size_t i=0; i<(X.
size()<
Y.size() ? X.
size():
Y.size()); i++)
911 void Subtract(
const std::vector<T>& X,
const std::vector<T>& Y)
913 for(
size_t i=0; i<(X.size()<
Y.size() ? X.size():
Y.size()); i++)
923 if(
n + TSS.n == 0)
return *
this;
926 sumxy += (TSS.SX.scale/
SX.scale)*(TSS.SY.scale/
SY.scale)*TSS.sumxy;
937 if(
n <= TSS.n) {
Reset();
return *
this; }
940 sumxy -= (TSS.SX.scale/
SX.scale)*(TSS.SY.scale/
SY.scale)*TSS.sumxy;
951 void Dump(std::vector<unsigned int>&
vuint, std::vector<T>& vT)
954 std::vector<unsigned int> vi;
957 vuint.clear(); vT.clear();
960 for(i=0; i<2; i++)
vuint.push_back(vi[i]);
961 for(i=0; i<5; i++) vT.push_back(vt[i]);
964 for(i=0; i<2; i++)
vuint.push_back(vi[i]);
965 for(i=0; i<5; i++) vT.push_back(vt[i]);
977 void Load(std::vector<unsigned int>&
vuint, std::vector<T>& vT)
980 std::vector<unsigned int> vi2;
981 std::vector<double> vt2;
982 if(
vuint.size() < 5 || vT.size() < 11) {
984 for(i=0; i<5; i++) vT.push_back(T(0));
986 for(i=0; i<11; i++) vT.push_back(T(0));
990 for(i=0; i<2; i++) vi2.push_back(
vuint[i+2]);
991 for(i=0; i<5; i++) vt2.push_back(vT[i+5]);
1001 std::string
asString(std::string msg=std::string(),
int w=7,
int p=4)
const
1003 std::ostringstream oss;
1005 oss <<
SX.asString(msg,w,p) <<
" (X)" << std::endl
1006 <<
SY.asString(msg,w,p) <<
" (Y)" << std::endl
1007 <<
"stats(tss):" << (msg.empty() ?
"" :
" "+msg)
1008 <<
" N " << std::setw(w) <<
N() << std::fixed << std::setprecision(p)
1009 <<
" Int " << std::setw(w) <<
Intercept()
1010 <<
" Slp " << std::setw(w) <<
Slope()
1012 <<
" CSig " << std::setw(w) <<
SigmaYX()
1018 std::string
asShortString(std::string msg=std::string(),
int w=0,
int p=3)
const
1020 std::ostringstream oss;
1021 oss <<
SX.asShortString(msg,w,p) <<
" (X);"
1022 <<
SY.asShortString(msg,w,p) <<
" (Y);"
1023 << msg << std::fixed << std::setprecision(p)
1024 << std::fixed << std::setprecision(p)
1025 <<
" Int " << std::setw(w) <<
Intercept()
1026 <<
" Slp " << std::setw(w) <<
Slope()
1028 <<
" CSig " << std::setw(w) <<
SigmaYX()
1037 inline unsigned int N(
void)
const {
return n; }
1063 T den(
SX.sum2-
SX.sum*
SX.sum/T(
n));
1064 if(den == T())
return T();
1065 return ( (
SY.scale/
SX.scale) * (
sumxy-
SX.sum*
SY.sum/T(
n)) / den );
1085 if(den == T())
return T();
1097 if(den == T())
return T();
1138 std::ofstream savefmt;
1140 s <<
" N = " << TSS.N() <<
" (two-sample-statistics)\n";
1141 s <<
" Minimum: X = "; s.copyfmt(savefmt); s << TSS.MinimumX();
1142 s <<
" Y = "; s.copyfmt(savefmt); s << TSS.MinimumY() <<
"\n";
1143 s <<
" Maximum: X = "; s.copyfmt(savefmt); s << TSS.MaximumX();
1144 s <<
" Y = "; s.copyfmt(savefmt); s << TSS.MaximumY() <<
"\n";
1145 s <<
" Average: X = "; s.copyfmt(savefmt); s << TSS.AverageX();
1146 s <<
" Y = "; s.copyfmt(savefmt); s << TSS.AverageY() <<
"\n";
1147 s <<
" Std Dev: X = "; s.copyfmt(savefmt); s << TSS.StdDevX();
1148 s <<
" Y = "; s.copyfmt(savefmt); s << TSS.StdDevY() <<
"\n";
1149 s <<
" Variance: X = "; s.copyfmt(savefmt); s << TSS.VarianceX();
1150 s <<
" Y = "; s.copyfmt(savefmt); s << TSS.VarianceY() <<
"\n";
1152 bool bad(TSS.VarianceYX() == T());
1153 std::string badmsg(
"undef");
1154 s <<
" Intercept = "; s.copyfmt(savefmt);
1155 if(bad) s << badmsg;
else s << TSS.Intercept();
1156 s <<
" Slope = "; s.copyfmt(savefmt);
1157 if(bad) s << badmsg;
else s << TSS.Slope();
1158 s <<
" with uncertainty = "; s.copyfmt(savefmt);
1159 if(bad) s << badmsg;
else s << TSS.SigmaSlope();
1160 s <<
"\n Conditional uncertainty (sigma Y given X) = "; s.copyfmt(savefmt);
1161 if(bad) s << badmsg;
else s << TSS.SigmaYX();
1162 s <<
" Correlation = "; s.copyfmt(savefmt);
1163 if(bad) s << badmsg;
else s << TSS.Correlation();
1172 #endif // INCLUDE_GNSSTK_STATS_INCLUDE
void Add(std::vector< T > &X)
add a std::vector<T> of samples to the computation of statistics
void Subtract(std::vector< T > &X)
void Subtract(std::vector< T > &X)
std::string asShortString(std::string msg=std::string(), int w=0, int p=3) const
Write Stats N,ave,sig to a short single-line string.
void Add(const T &x, const T &wt_in)
void Subtract(Vector< T > &X)
void Add(const T &x, const T &y)
void Subtract(const T &x)
Stats< T > SY
conventional 1-sample stats for second sample y
void Dump(std::vector< unsigned int > &vuint, std::vector< T > &vT)
bool setScale
scale has been set to non-zero
T Variance(void) const
return computed variance
TwoSampleStats< T > & operator-=(TwoSampleStats< T > &TSS)
T Slope(void) const
return slope of best-fit line Y=slope*X + intercept
Stats< T > SX
conventional 1-sample stats for first sample x
T Minimum(void) const
return minimum value
Stats< T > & operator-=(const Stats< T > &S)
std::string asShortString(std::string msg=std::string(), int w=0, int p=3) const
Write SeqStats N,ave,sig to a short single-line string.
T StdDev(void) const
return computed standard deviation
T StdDevY(void) const
return computed Y standard deviation
@ Y
Encrypted legacy GPS precise code.
T Intercept(void) const
return intercept of best-fit line Y=slope*X + intercept
void Add(const Vector< T > &X)
Add gnsstk::Vector<T> of data to the statistics.
void Load(std::vector< unsigned int > &vuint, std::vector< T > &vT)
void Reset(void)
reset, i.e. ignore earlier data and restart sampling
T MinimumX(void) const
return minimum X value
T SigmaYX(void) const
return conditional uncertainty = uncertainty y given x
void Add(const std::vector< T > &X, const std::vector< T > &Y)
Add two std::vectors of data to the statistics.
void Subtract(const Vector< T > &X, const Vector< T > &Y)
Subtract two gnsstk::Vector<T>s of data from the statistics.
unsigned int n
number of samples added to the statistics
void Subtract(const T &x, const T &y)
std::string asShortString(std::string msg=std::string(), int w=0, int p=3) const
Write WtdStats N,ave,sig to a short single-line string.
WtdStats< T > & operator+=(const WtdStats< T > &S)
combine two WtdStats (assumed taken from the same or equivalent ensembles);
SeqStats(Vector< T > &X)
constructor given a gnsstk::Vector<T> of data
void Add(Vector< T > &X)
add a gnsstk::Vector<T> of samples to the computation of statistics
T AverageY(void) const
return computed Y average
T Maximum(void) const
return maximum value
Stats< T > & operator+=(const Stats< T > &S)
combine two Stats (assumed taken from the same or equivalent ensembles)
void Add(const Vector< T > &X, const Vector< T > &Y)
Add two gnsstk::Vector<T>s of data to the statistics.
std::string asShortString(std::string msg=std::string(), int w=0, int p=3) const
Write TwoSampleStats as a short 1-line string.
void Add(Vector< T > &X, Vector< T > &W)
add a gnsstk::Vector<T> of samples, with weights
page HOWTO subpage DoxygenGuide Documenting Your Code page DoxygenGuide Documenting Your Code todo Flesh out this document section doctips Tips for Documenting When defining make sure that the prototype is identical between the cpp and hpp including both the namespaces and the parameter names for you have std::string as the return type in the hpp file and string as the return type in the cpp Doxygen may get confused and autolink to the cpp version with no documentation If you don t use the same parameter names between the cpp and hpp that will also confuse Doxygen Don t put type information in return or param documentation It doesn t really add anything and will often cause Doxygen to complain and not produce the documentation< br > use note Do not put a comma after a param name unless you mean to document multiple parameters< br/> the output stream</code >< br/> y
T Minimum(void) const
return minimum value
T Variance(void) const
return computed variance
T StdDev(void) const
return computed standard deviation
T MaximumX(void) const
return maximum X value
T WtNorm
Normalization constant = sum weights.
unsigned int n
number of samples added to the statistics
T MaximumY(void) const
return maximum Y value
TwoSampleStats< T > & operator+=(TwoSampleStats< T > &TSS)
T var
Variance (square of the standard deviation)
T SigmaSlope(void) const
return uncertainty in slope
std::ostream & operator<<(std::ostream &s, const ObsEpoch &oe) noexcept
void Load(std::vector< unsigned int > &vuint, std::vector< T > &vT)
T AverageX(void) const
return computed X average
T Maximum(void) const
return maximum value
void Load(const std::vector< unsigned int > &vuint, const std::vector< T > &vT)
TwoSampleStats(Vector< T > &X, Vector< T > &Y)
constructor given two gnsstk::Vector<T>s of data - must be parallel
T VarianceX(void) const
return computed X variance
void Add(std::vector< T > &X, std::vector< T > &W)
add a std::vector<T> of samples, with weights
void Subtract(const T &x, const T &wt_in)
T Correlation(void) const
return correlation
std::string asString(std::string msg=std::string(), int w=7, int p=4) const
Write SeqStats to a single-line string.
std::string asString(std::string msg=std::string(), int w=7, int p=4) const
Write Stats to a single-line string.
T Scale(void) const
return the scale
void Load(const std::vector< unsigned int > &vuint, const std::vector< T > &vT)
std::string asString(std::string msg=std::string(), int w=7, int p=4) const
Write WtdStats to a single-line string.
T StdDevX(void) const
return computed X standard deviation
T VarianceYX(void) const
return conditional variance = (uncertainty y given x)^2
WtdStats< T > & operator-=(const WtdStats< T > &S)
size_t size() const
STL size.
std::string asString(std::string msg=std::string(), int w=7, int p=4) const
Write TwoSampleStats to a three-line string.
void Subtract(const std::vector< T > &X, const std::vector< T > &Y)
Subtract two std::vectors of data from the statistics.
void Reset(void)
reset, i.e. ignore earlier data and restart sampling
unsigned int N(void) const
return the sample size
T VarianceY(void) const
return computed Y variance
void Dump(std::vector< unsigned int > &vuint, std::vector< T > &vT)
T MinimumY(void) const
return minimum Y value
unsigned int N(void) const
unsigned int n
number of samples added to the statistics
T Average(void) const
return the average
SeqStats< T > & operator+=(const SeqStats< T > &S)
combine two SeqStats (assumed taken from the same or equivalent ensembles);
void Dump(std::vector< unsigned int > &vuint, std::vector< T > &vT)
void Subtract(const Vector< T > &X)
T Average(void) const
return computed average
WtdStats(Vector< T > &X, Vector< T > &W)
constructor given a gnsstk::Vector<T> of data, with weights
SeqStats< T > & operator-=(const SeqStats< T > &S)
T median(const Vector< T > &v)
Compute the median of a gnsstk::Vector.
void Reset(void)
reset, i.e. ignore earlier data and restart sampling
void Add(std::vector< T > &X)
add a std::vector<T> of samples to the computation of statistics
T Evaluate(T x) const
return the predicted Y at the given X, using Slope and Intercept
T mad(const gnsstk::Vector< T > &v)
median absolute deviation of a gnsstk::Vector
void Subtract(Vector< T > &X, Vector< T > &W)
T WtsSum(void) const
return normalization = sum of weights
unsigned int N(void) const
return the sample size
void Subtract(std::vector< T > &X, std::vector< T > &W)
void Dump(std::vector< unsigned int > &vuint, std::vector< T > &vT)
TwoSampleStats()
constructor
gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:41