38 return sum(v) / v.length();
41 std::complex<double>
mean(
const cvec &v)
43 return sum(v) / double(v.size());
48 return (
double)
sum(v) / v.length();
53 return (
double)
sum(v) / v.length();
58 return sum(
sum(m)) / (m.rows()*m.cols());
61 std::complex<double>
mean(
const cmat &m)
63 return sum(
sum(m)) /
static_cast<std::complex<double>
>(m.rows()*m.cols());
68 return static_cast<double>(
sum(
sum(m))) / (m.rows()*m.cols());
73 return static_cast<double>(
sum(
sum(m))) / (m.rows()*m.cols());
80 for (
int i = 0; i < v.length(); i++)
86 double norm(
const cvec &v,
int p)
89 for (
int i = 0; i < v.size(); i++)
95 double norm(
const cvec &v,
const std::string &)
105 double norm(
const mat &m,
int p)
108 "norm(): Can only calculate a matrix norm of order 1 or 2");
121 double norm(
const cmat &m,
int p)
124 "norm(): Can only calculate a matrix norm of order 1 or 2");
133 double norm(
const mat &m,
const std::string &s)
135 it_assert(s ==
"fro",
"norm(): Unrecognised norm");
137 for (
int r = 0; r < m.rows(); ++r) {
138 for (
int c = 0; c < m.cols(); ++c) {
139 E += m(r, c) * m(r, c);
146 double norm(
const cmat &m,
const std::string &s)
148 it_assert(s ==
"fro",
"norm(): Unrecognised norm");
150 for (
int r = 0; r < m.rows(); ++r) {
151 for (
int c = 0; c < m.cols(); ++c) {
163 std::complex<double>
sum = 0.0;
164 const std::complex<double> *p = v._data();
166 for (
int i = 0; i < len; i++, p++) {
171 return (
double)(sq_sum -
std::norm(sum) / len) / (len - 1);
176 double m =
mean(x), mr = 0;
182 for (
int j = 0; j < n; j++)
186 for (
int j = 0; j < n; j++)
187 mr += (x(j) - m) * (x(j) - m);
190 for (
int j = 0; j < n; j++)
191 mr += (x(j) - m) * (x(j) - m) * (x(j) - m);
194 for (
int j = 0; j < n; j++) {
195 temp = (x(j) - m) * (x(j) - m);
201 for (
int j = 0; j < n; j++)
202 mr +=
std::pow(x(j) - m, double(r));
214 double k2 =
variance(x) * n / (n - 1);
215 double k3 =
moment(x, 3) * n * n / (n - 1) / (n - 2);
217 return k3 /
std::pow(k2, 3.0 / 2.0);
226 double k2 = m2 * n / (n - 1);
227 double k4 = (m4 * (n + 1) - 3 * (n - 1) * m2 * m2) * n * n / (n - 1) / (n - 2) / (n - 3);
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.
T sum(const Vec< T > &v)
Sum of all elements in the vector.
#define it_assert(t, s)
Abort if t is not true.
double mean(const vec &v)
The mean value.
double variance(const cvec &v)
The variance of the elements in the vector. Normalized with N-1 to be unbiased.
bool svd(const mat &A, vec &S)
Get singular values s of a real matrix A using SVD.
T max(const Vec< T > &v)
Maximum value of vector.
vec pow(const double x, const vec &y)
Calculates x to the power of y (x^y)
Miscellaneous statistics functions and classes - header file.
vec sqrt(const vec &x)
Square root of the elements.
Definitions of Singular Value Decompositions.
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.
double norm(const cmat &m, const std::string &s)
Calculate the Frobenius norm of a matrix for s = "fro".