Go to the documentation of this file.
36 #include <itpp/itexports.h>
68 virtual void sample(
const double s,
const bool overflow =
false) {
72 if (s < _min) _min = s;
73 if (s > _max) _max = s;
74 if (overflow) _n_overflows++;
75 if (s == 0.0) _n_zeros++;
85 double avg()
const {
return _sum / _n_samples;}
87 double max()
const {
return _max;}
89 double min()
const {
return _min;}
92 double sigma2 = _sqr_sum / _n_samples - avg() * avg();
93 return std::sqrt(sigma2 < 0 ? 0 : sigma2);
98 double sum()
const {
return _sum;}
121 ITPP_EXPORT
double mean(
const vec &v);
123 ITPP_EXPORT std::complex<double>
mean(
const cvec &v);
125 ITPP_EXPORT
double mean(
const svec &v);
127 ITPP_EXPORT
double mean(
const ivec &v);
129 ITPP_EXPORT
double mean(
const mat &m);
131 ITPP_EXPORT std::complex<double>
mean(
const cmat &m);
133 ITPP_EXPORT
double mean(
const smat &m);
135 ITPP_EXPORT
double mean(
const imat &m);
158 return (
double)(invect[(invect.
length()-1)/2] + invect[invect.
length()/2]) / 2.0;
162 ITPP_EXPORT
double norm(
const cvec &v);
169 for (
int i = 0; i < v.
size(); i++)
170 E +=
sqr(
static_cast<double>(v[i]));
176 ITPP_EXPORT
double norm(
const cvec &v,
int p);
183 for (
int i = 0; i < v.
size(); i++)
184 E +=
std::pow(fabs(
static_cast<double>(v[i])),
static_cast<double>(p));
190 ITPP_EXPORT
double norm(
const cvec &v,
const std::string &s);
196 it_assert(s ==
"fro",
"norm(): Unrecognised norm");
199 for (
int i = 0; i < v.
size(); i++)
200 E +=
sqr(
static_cast<double>(v[i]));
213 ITPP_EXPORT
double norm(
const mat &m,
int p = 2);
223 ITPP_EXPORT
double norm(
const cmat &m,
int p = 2);
226 ITPP_EXPORT
double norm(
const mat &m,
const std::string &s);
229 ITPP_EXPORT
double norm(
const cmat &m,
const std::string &s);
233 ITPP_EXPORT
double variance(
const cvec &v);
240 const T *p = v.
_data();
241 double sum = 0.0, sq_sum = 0.0;
243 for (
int i = 0; i < len; i++, p++) {
248 return (
double)(sq_sum -
sum*
sum / len) / (len - 1);
262 return (fabs(x -xref) <= tol) ? true :
false;
266 inline bool within_tolerance(std::complex<double> x, std::complex<double> xref,
double tol = 1e-14)
268 return (
abs(x -xref) <= tol) ? true :
false;
274 return (
max(
abs(x -xref)) <= tol) ? true :
false;
280 return (
max(
abs(x -xref)) <= tol) ? true :
false;
286 return (
max(
max(
abs(X -Xref))) <= tol) ? true :
false;
292 return (
max(
max(
abs(X -Xref))) <= tol) ? true :
false;
306 ITPP_EXPORT
double moment(
const vec &x,
const int r);
336 ITPP_EXPORT
double skewness(
const vec &x);
385 #endif // #ifndef MISC_STAT_H
int length() const
The size of the vector.
double median(const Vec< T > &v)
The median.
double sqr_sum() const
Squared sum of all samples.
bool within_tolerance(double x, double xref, double tol=1e-14)
Return true if the input value x is within the tolerance tol of the reference value xref.
int n_samples() const
Number of samples.
double _min
Minimum sample.
int n_overflows() const
Number of reported overflows.
Matrix Class Definitions.
vec histogram() const
Histogram over all samples (not implemented yet)
double energy(const Vec< T > &v)
Calculate the energy: squared 2-norm. energy(v)=sum(abs(v).^2)
int rows() const
The number of rows.
double sigma() const
Standard deviation of all samples.
virtual void sample(const double s, const bool overflow=false)
Register a sample and flag for overflow.
int _n_overflows
Number of reported overflows.
double variance(const cvec &v)
The variance of the elements in the vector. Normalized with N-1 to be unbiased.
int _n_zeros
Number of zero samples.
T prod(const Vec< T > &v)
The product of all elements in the vector.
Various functions on vectors and matrices - header file.
vec exp(const vec &x)
Exp of the elements of a vector x.
double max() const
Maximum sample.
double kurtosisexcess(const vec &x)
Calculate the kurtosis excess of the input vector x.
Stat()
Default constructor.
Elementary mathematical functions - header file.
int size() const
The size of the vector.
T max(const Vec< T > &v)
Maximum value of vector.
double skewness(const vec &x)
Calculate the skewness excess of the input vector x.
double _max
Maximum sample.
int cols() const
The number of columns.
vec sqr(const cvec &data)
Absolute square of elements.
double mean(const vec &v)
The mean value.
virtual void clear()
Clear statistics.
double min() const
Minimum sample.
vec pow(const double x, const vec &y)
Calculates x to the power of y (x^y)
double norm(const cvec &v)
Calculate the 2-norm: norm(v)=sqrt(sum(abs(v).^2))
bin abs(const bin &inbin)
absolute value of bin
int _n_samples
Number of samples.
virtual ~Stat()
Destructor.
vec sqrt(const vec &x)
Square root of the elements.
A class for sampling a signal and calculating statistics.
double kurtosis(const vec &x)
Calculate the kurtosis of the input vector x.
double _sum
Sum of all samples.
int n_zeros() const
Number of zero samples.
double geometric_mean(const Vec< T > &v)
The geometric mean of a vector.
double _sqr_sum
Squared sum of all samples.
double sum() const
Sum of all samples.
Minimum and maximum functions on vectors and matrices.
double avg() const
Average over all samples.
vec log(const vec &x)
The natural logarithm of the elements.
double moment(const vec &x, const int r)
Calculate the central moment of vector x.
Num_T * _data()
Get the pointer to the internal structure. Not recommended for use.
T sum(const Vec< T > &v)
Sum of all elements in the vector.
#define it_assert(t, s)
Abort if t is not true.
Generated on Sun Jan 3 2021 11:31:33 for IT++ by Doxygen 1.8.20