13 #ifndef MLPACK_CORE_MATH_CCOV_IMPL_HPP 14 #define MLPACK_CORE_MATH_CCOV_IMPL_HPP 22 inline arma::Mat<eT> ColumnCovariance(
const arma::Mat<eT>& x,
23 const size_t normType)
27 Log::Fatal <<
"ColumnCovariance(): norm_type must be 0 or 1!" << std::endl;
34 const arma::Mat<eT>& xAlias = (x.n_cols == 1) ?
35 arma::Mat<eT>(const_cast<eT*>(x.memptr()), x.n_cols, x.n_rows,
false,
37 arma::Mat<eT>(
const_cast<eT*
>(x.memptr()), x.n_rows, x.n_cols,
false,
40 const size_t n = xAlias.n_cols;
41 const eT normVal = (normType == 0) ? ((n > 1) ? eT(n - 1) : eT(1)) : eT(n);
43 const arma::Mat<eT> tmp = xAlias.each_col() - arma::mean(xAlias, 1);
53 inline arma::Mat<std::complex<T>> ColumnCovariance(
54 const arma::Mat<std::complex<T>>& x,
55 const size_t normType)
59 Log::Fatal <<
"ColumnCovariance(): norm_type must be 0 or 1" << std::endl;
62 typedef typename std::complex<T> eT;
70 const arma::Mat<T> tmpMat = arma::var(arma::trans(x), normType);
76 const arma::Mat<T> tmpMat = arma::var(x, normType);
83 const size_t n = x.n_cols;
84 const eT normVal = (normType == 0) ?
85 ((n > 1) ? eT(n - 1) : eT(1)) : eT(n);
87 const arma::Col<eT> acc = arma::sum(x, 1);
89 out = x * arma::trans(arma::conj(x));
90 out -= (acc * arma::trans(arma::conj(acc))) / eT(n);
100 #endif // MLPACK_CORE_MATH_CCOV_IMPL_HPP static MLPACK_EXPORT util::PrefixedOutStream Fatal
Prints fatal messages prefixed with [FATAL], then terminates the program.
Definition: log.hpp:90
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1