op_cov_meat.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 template<typename eT>
00025 inline
00026 void
00027 op_cov::direct_cov(Mat<eT>& out, const Mat<eT>& A, const u32 norm_type)
00028 {
00029 arma_extra_debug_sigprint();
00030
00031 if(A.is_vec())
00032 {
00033 if(A.n_rows == 1)
00034 {
00035 out = var(trans(A), norm_type);
00036 }
00037 else
00038 {
00039 out = var(A, norm_type);
00040 }
00041 }
00042 else
00043 {
00044 const u32 N = A.n_rows;
00045 const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N);
00046
00047 const Row<eT> acc = sum(A);
00048
00049 out = trans(A) * A;
00050 out -= (trans(acc) * acc)/eT(N);
00051 out /= norm_val;
00052 }
00053 }
00054
00055
00056
00057 template<typename T>
00058 inline
00059 void
00060 op_cov::direct_cov(Mat< std::complex<T> >& out, const Mat< std::complex<T> >& A, const u32 norm_type)
00061 {
00062 arma_extra_debug_sigprint();
00063
00064 typedef typename std::complex<T> eT;
00065
00066 if(A.is_vec())
00067 {
00068 if(A.n_rows == 1)
00069 {
00070 const Mat<T> tmp_mat = var(trans(A), norm_type);
00071 out.set_size(1,1);
00072 out[0] = tmp_mat[0];
00073 }
00074 else
00075 {
00076 const Mat<T> tmp_mat = var(A, norm_type);
00077 out.set_size(1,1);
00078 out[0] = tmp_mat[0];
00079 }
00080 }
00081 else
00082 {
00083 const u32 N = A.n_rows;
00084 const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N);
00085
00086 const Row<eT> acc = sum(A);
00087
00088 out = trans(conj(A)) * A;
00089 out -= (trans(conj(acc)) * acc)/eT(N);
00090 out /= norm_val;
00091 }
00092 }
00093
00094
00095
00096 template<typename T1>
00097 inline
00098 void
00099 op_cov::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_cov>& in)
00100 {
00101 arma_extra_debug_sigprint();
00102
00103 typedef typename T1::elem_type eT;
00104
00105 const unwrap_check<T1> tmp(in.m, out);
00106 const Mat<eT>& A = tmp.M;
00107
00108 const u32 norm_type = in.aux_u32_a;
00109
00110 op_cov::direct_cov(out, A, norm_type);
00111 }
00112
00113
00114
00115