op_cor_meat.hpp
Go to the documentation of this file.
1 // Copyright (C) 2009-2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2009-2011 Conrad Sanderson
3 // Copyright (C) 2009-2010 Dimitrios Bouzas
4 //
5 // This file is part of the Armadillo C++ library.
6 // It is provided without any warranty of fitness
7 // for any purpose. You can redistribute this file
8 // and/or modify it under the terms of the GNU
9 // Lesser General Public License (LGPL) as published
10 // by the Free Software Foundation, either version 3
11 // of the License or (at your option) any later version.
12 // (see http://www.opensource.org/licenses for more info)
13 
14 
15 
18 
19 
20 
21 template<typename eT>
22 inline
23 void
24 op_cor::direct_cor(Mat<eT>& out, const Mat<eT>& A, const uword norm_type)
25  {
27 
28  if(A.is_empty())
29  {
30  out.reset();
31  return;
32  }
33 
34  if(A.is_vec())
35  {
36  out.set_size(1,1);
37  out[0] = eT(1);
38  }
39  else
40  {
41  const uword N = A.n_rows;
42  const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N);
43 
44  const Row<eT> acc = sum(A);
45  const Row<eT> sd = stddev(A);
46 
47  out = (trans(A) * A);
48  out -= (trans(acc) * acc)/eT(N);
49  out /= norm_val;
50  out /= trans(sd) * sd;
51  }
52  }
53 
54 
55 
56 template<typename T>
57 inline
58 void
59 op_cor::direct_cor(Mat< std::complex<T> >& out, const Mat< std::complex<T> >& A, const uword norm_type)
60  {
62 
63  typedef typename std::complex<T> eT;
64 
65  if(A.is_empty())
66  {
67  out.reset();
68  return;
69  }
70 
71  if(A.is_vec())
72  {
73  out.set_size(1,1);
74  out[0] = eT(1);
75  }
76  else
77  {
78  const uword N = A.n_rows;
79  const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N);
80 
81  const Row<eT> acc = sum(A);
82  const Row<T> sd = stddev(A);
83 
84  out = trans(A) * A; // out = strans(conj(A)) * A;
85  out -= (trans(acc) * acc)/eT(N); // out -= (strans(conj(acc)) * acc)/eT(N);
86  out /= norm_val;
87 
88  //out = out / (trans(sd) * sd);
89  out /= conv_to< Mat<eT> >::from(trans(sd) * sd);
90  }
91  }
92 
93 
94 
95 template<typename T1>
96 inline
97 void
99  {
101 
102  typedef typename T1::elem_type eT;
103 
104  const unwrap_check<T1> tmp(in.m, out);
105  const Mat<eT>& A = tmp.M;
106 
107  const uword norm_type = in.aux_uword_a;
108 
109  op_cor::direct_cor(out, A, norm_type);
110  }
111 
112 
113 
arma_inline const Op< T1, op_sum > sum(const Base< typename T1::elem_type, T1 > &X, const uword dim=0)
Delayed sum of elements of a matrix along a specified dimension (either rows or columns). The result is stored in a dense matrix that has either one column or one row. For dim = 0, find the sum of each column. For dim = 1, find the sum of each row. The default is dim = 0. NOTE: this function works differently than in Matlab/Octave.
Definition: fn_sum.hpp:29
arma_inline arma_warn_unused bool is_vec() const
returns true if the object can be interpreted as a column or row vector
Definition: Mat_meat.hpp:3824
void set_size(const uword in_elem)
change the matrix to have user specified dimensions (data is not preserved)
Definition: Mat_meat.hpp:4211
const mtOp< typename T1::pod_type, T1, op_stddev > stddev(const Base< typename T1::elem_type, T1 > &X, const uword norm_type=0, const uword dim=0)
Definition: fn_stddev.hpp:22
static void apply(Mat< typename T1::elem_type > &out, const Op< T1, op_cor > &in)
Definition: op_cor_meat.hpp:98
const uword n_rows
number of rows in the matrix (read-only)
Definition: Mat_bones.hpp:29
arma_aligned const T1 & m
storage of reference to the operand (eg. a matrix)
Definition: Op_bones.hpp:45
u32 uword
Definition: typedef.hpp:85
arma_inline const Op< T1, op_htrans > trans(const Base< typename T1::elem_type, T1 > &X)
Definition: fn_trans.hpp:21
void reset()
Definition: Mat_meat.hpp:4553
Class for row vectors (matrices with only one row)
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
static void direct_cor(Mat< eT > &out, const Mat< eT > &X, const uword norm_type)
Definition: op_cor_meat.hpp:24
Dense matrix class.
const Mat< eT > M
Definition: unwrap.hpp:142
arma_aligned uword aux_uword_a
storage of auxiliary data, uword format
Definition: Op_bones.hpp:47
arma_inline arma_warn_unused bool is_empty() const
returns true if the matrix has no elements
Definition: Mat_meat.hpp:3812


armadillo_matrix
Author(s):
autogenerated on Fri Apr 16 2021 02:31:58