Changeset 3745 for trunk/yat/statistics/utility.cc
 Timestamp:
 Jul 27, 2018, 2:27:02 AM (4 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/statistics/utility.cc
r2919 r3745 27 27 #include "utility.h" 28 28 29 #include "yat/normalizer/Centralizer.h" 30 #include "yat/normalizer/ColumnNormalizer.h" 31 29 32 #include <gsl/gsl_cdf.h> 30 33 #include <gsl/gsl_randist.h> … … 44 47 { 45 48 return gsl_cdf_hypergeometric_P(k, n1, n2, t); 49 } 50 51 52 utility::Matrix correlation(utility::Matrix x) 53 { 54 using utility::Matrix; 55 size_t n = x.columns(); 56 // centralise 57 normalizer::ColumnNormalizer<normalizer::Centralizer<> > normalizer; 58 normalizer(x, x); 59 60 Matrix cov(n, n); 61 for (size_t i=0; i<n; ++i) { 62 for (size_t j=i; j<n; ++j) { 63 cov(i, j) = x.column_const_view(i) * x.column_const_view(j); 64 cov(j, i) = cov(i, j); 65 } 66 } 67 68 utility::Vector stddev(n); 69 for (size_t i=0; i<n; ++i) 70 stddev(i) = std::sqrt(cov(i, i)); 71 72 Matrix corr(cov); 73 for (size_t i=0; i<n; ++i) { 74 corr(i, i) = 1.0; 75 for (size_t j=0; j<i; ++j) { 76 corr(i, j) = cov(i, j) / (stddev(i) * stddev(j)); 77 corr(j, i) = corr(i, j); 78 } 79 } 80 return corr; 46 81 } 47 82
Note: See TracChangeset
for help on using the changeset viewer.