fml  0.1-0
Fused Matrix Library
cor.hh
1 // This file is part of fml which is released under the Boost Software
2 // License, Version 1.0. See accompanying file LICENSE or copy at
3 // https://www.boost.org/LICENSE_1_0.txt
4 
5 #ifndef FML_MPI_STATS_COR_H
6 #define FML_MPI_STATS_COR_H
7 #pragma once
8 
9 
10 #include <stdexcept>
11 
12 #include "../../_internals/omp.hh"
13 
14 #include "../mpimat.hh"
15 #include "../dimops.hh"
16 
17 #include "../linalg/crossprod.hh"
18 #include "../linalg/matmult.hh"
19 
20 
21 namespace fml
22 {
23 namespace stats
24 {
40  template <typename REAL>
42  {
43  dimops::scale(true, true, x);
44 
45  const REAL alpha = 1. / ((REAL) (x.nrows()-1));
46  linalg::crossprod(alpha, x, cov);
47  }
48 
49 
50 
52  template <typename REAL>
54  {
55  if (x.nrows() != y.nrows())
56  throw std::runtime_error("non-conformable arguments");
57 
58  dimops::scale(true, true, x);
59  dimops::scale(true, true, y);
60 
61  const REAL alpha = 1. / ((REAL) (x.nrows()-1));
62  linalg::matmult(true, false, alpha, x, y, cov);
63  }
64 }
65 }
66 
67 
68 #endif
fml::linalg::crossprod
void crossprod(const REAL alpha, const cpumat< REAL > &x, cpumat< REAL > &ret)
Computes lower triangle of alpha*x^T*x.
Definition: crossprod.hh:37
fml::mpimat
Matrix class for data distributed over MPI in the 2-d block cyclic format.
Definition: mpimat.hh:40
fml::unimat::nrows
len_t nrows() const
Number of rows.
Definition: unimat.hh:36
fml::dimops::scale
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
fml::stats::cor
void cor(cpumat< REAL > &x, cpumat< REAL > &cov)
Covariance.
Definition: cor.hh:43
fml
Core namespace.
Definition: dimops.hh:10
fml::stats::cov
void cov(cpumat< REAL > &x, cpumat< REAL > &cov)
Covariance.
Definition: cov.hh:43
fml::linalg::matmult
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