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 size() const
The size of the vector.
double max() const
Maximum sample.
Various functions on vectors and matrices - header file.
int n_zeros() const
Number of zero samples.
Num_T * _data()
Get the pointer to the internal structure. Not recommended for use.
int n_samples() const
Number of samples.
double _min
Minimum sample.
double norm(const cvec &v)
Calculate the 2-norm: norm(v)=sqrt(sum(abs(v).^2))
double moment(const vec &x, const int r)
Calculate the central moment of vector x.
int _n_overflows
Number of reported overflows.
T sum(const Vec< T > &v)
Sum of all elements in the vector.
double sqr_sum() const
Squared sum of all samples.
double median(const Vec< T > &v)
The median.
#define it_assert(t, s)
Abort if t is not true.
virtual void sample(const double s, const bool overflow=false)
Register a sample and flag for overflow.
Minimum and maximum functions on vectors and matrices.
double sum() const
Sum of all samples.
int _n_zeros
Number of zero samples.
double mean(const vec &v)
The mean value.
T prod(const Vec< T > &v)
The product of all elements in the vector.
vec log(const vec &x)
The natural logarithm of the elements.
double _sqr_sum
Squared sum of all samples.
int cols() const
The number of columns.
double variance(const cvec &v)
The variance of the elements in the vector. Normalized with N-1 to be unbiased.
double _max
Maximum sample.
Matrix Class Definitions.
vec exp(const vec &x)
Exp of the elements of a vector x.
double energy(const Vec< T > &v)
Calculate the energy: squared 2-norm. energy(v)=sum(abs(v).^2)
vec histogram() const
Histogram over all samples (not implemented yet)
T max(const Vec< T > &v)
Maximum value of vector.
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...
double avg() const
Average over all samples.
vec pow(const double x, const vec &y)
Calculates x to the power of y (x^y)
double sigma() const
Standard deviation of all samples.
double kurtosis(const vec &x)
Calculate the kurtosis of the input vector x.
int length() const
The size of the vector.
double _sum
Sum of all samples.
int _n_samples
Number of samples.
vec sqr(const cvec &data)
Absolute square of elements.
Stat()
Default constructor.
double min() const
Minimum sample.
int rows() const
The number of rows.
int n_overflows() const
Number of reported overflows.
vec sqrt(const vec &x)
Square root of the elements.
virtual void clear()
Clear statistics.
bin abs(const bin &inbin)
absolute value of bin
double skewness(const vec &x)
Calculate the skewness excess of the input vector x.
double kurtosisexcess(const vec &x)
Calculate the kurtosis excess of the input vector x.
A class for sampling a signal and calculating statistics.
Elementary mathematical functions - header file.
virtual ~Stat()
Destructor.
double geometric_mean(const Vec< T > &v)
The geometric mean of a vector.