 |
fml
0.1-0
Fused Matrix Library
|
5 #ifndef FML_CPU_STATS_COV_H
6 #define FML_CPU_STATS_COV_H
12 #include "../../_internals/omp.hh"
14 #include "../cpumat.hh"
15 #include "../cpuvec.hh"
17 #include "../dimops.hh"
19 #include "../linalg/crossprod.hh"
20 #include "../linalg/matmult.hh"
42 template <
typename REAL>
47 const REAL alpha = 1. / ((REAL) (x.
nrows()-1));
54 template <
typename REAL>
58 throw std::runtime_error(
"non-conformable arguments");
63 const REAL alpha = 1. / ((REAL) (x.
nrows()-1));
70 template <
typename REAL>
73 const len_t n = x.
size();
75 throw std::runtime_error(
"non-conformal arguments");
80 REAL sum_xy = 0, sum_x = 0, sum_y = 0;
82 #pragma omp parallel for reduction(+: sum_xy, sum_x, sum_y) if(n>fml::omp::OMP_MIN_SIZE)
83 for (len_t i=0; i<n; i++)
85 const REAL xi = x_d[i];
86 const REAL yi = y_d[i];
93 return (sum_xy - (sum_x*sum_y*((REAL) 1./n))) * ((REAL) 1./(n-1));
Matrix class for data held on a single CPU.
Definition: cpumat.hh:36
void crossprod(const REAL alpha, const cpumat< REAL > &x, cpumat< REAL > &ret)
Computes lower triangle of alpha*x^T*x.
Definition: crossprod.hh:37
T * data_ptr()
Pointer to the internal array.
Definition: univec.hh:28
len_t nrows() const
Number of rows.
Definition: unimat.hh:36
Vector class for data held on a single CPU.
Definition: cpuvec.hh:31
void scale(const bool rm_mean, const bool rm_sd, cpumat< REAL > &x)
Remove the mean and/or the sd from a matrix.
Definition: dimops.hh:376
Core namespace.
Definition: dimops.hh:10
len_t size() const
Number of elements in the vector.
Definition: univec.hh:26
void cov(cpumat< REAL > &x, cpumat< REAL > &cov)
Covariance.
Definition: cov.hh:43
void matmult(const bool transx, const bool transy, const REAL alpha, const cpumat< REAL > &x, const cpumat< REAL > &y, cpumat< REAL > &ret)
Computes ret = alpha*op(x)*op(y) where op(A) is A or A^T.
Definition: matmult.hh:43