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);