1#ifndef _VECTORSTATISTICS_H_
2#define _VECTORSTATISTICS_H_
3#include "mspass/utility/MsPASSError.h"
57 std::string(
"VectorStatistics constructor: ") +
58 "input vector has insufficient data to compute statistics",
59 mspass::utility::ErrorSeverity::Invalid);
61 std::sort(d.begin(), d.end());
66 std::string(
"VectorStatistics constructor: ") +
67 "input vector has insufficient data to compute statistics",
68 mspass::utility::ErrorSeverity::Invalid);
70 for (
int i = 0; i < n; ++i)
72 std::sort(d.begin(), d.end());
76 int medposition = count / 2;
78 return (d[medposition]);
80 return ((d[medposition] + d[medposition - 1]) / 2);
85 for (
int i = 0; i < d.size(); ++i) {
88 return (result / d.size());
96 int nover4 = (n - 1) / 4;
99 result =
static_cast<double>(d[nover4]);
102 result = 0.75 *
static_cast<double>(d[nover4]) +
103 0.25 *
static_cast<double>(d[nover4 + 1]);
107 static_cast<double>(d[nover4]) +
static_cast<double>(d[nover4 + 1]);
111 result = 0.25 *
static_cast<double>(d[nover4]) +
112 0.75 *
static_cast<double>(d[nover4 + 1]);
115 return (
static_cast<T
>(result));
123 int n3_4 = 3 * (n - 1) / 4;
126 result =
static_cast<double>(d[n3_4]);
129 result = 0.75 *
static_cast<double>(d[n3_4]) +
130 0.25 *
static_cast<double>(d[n3_4 + 1]);
133 result =
static_cast<double>(d[n3_4]) +
static_cast<double>(d[n3_4 + 1]);
137 result = 0.25 *
static_cast<double>(d[n3_4]) +
138 0.75 *
static_cast<double>(d[n3_4 + 1]);
141 return (
static_cast<T
>(result));
148 return (d3_4 - d1_4);
151 std::vector<T> absdiff;
154 for (i = 0; i < n; ++i) {
156 diff = d[i] - center;
159 absdiff.push_back(diff);
167 for (i = 0; i < d.size(); ++i)
168 result = d[i] * d[i];
172 return (d[d.size() - 1]);
177 result = this->upper_bound();
178 result -= this->lower_bound();
183 std::stringstream ss;
184 ss <<
"VectorStatistics::quantile method: asked for 1-quantile number "
185 << n <<
" but data vecotor length is only " << d.size() << std::endl;
187 mspass::utility::ErrorSeverity::Invalid);
Base class for error object thrown by MsPASS library routines.
Definition MsPASSError.h:38
Generic object to compute common robust statistics from a vector container of data.
Definition VectorStatistics.h:16
T median()
Definition VectorStatistics.h:74
T q3_4()
Definition VectorStatistics.h:117
T ssq()
Definition VectorStatistics.h:164
T q1_4()
Definition VectorStatistics.h:90
T quantile(size_t n)
Definition VectorStatistics.h:181
T mad(T center)
Definition VectorStatistics.h:150
T interquartile()
Definition VectorStatistics.h:143
T range()
Definition VectorStatistics.h:175
T upper_bound()
Definition VectorStatistics.h:171
T lower_bound()
Definition VectorStatistics.h:174
VectorStatistics(std::vector< T > din)
Definition VectorStatistics.h:54
T mean()
Definition VectorStatistics.h:82