From a29e5290f3247bccf6ab800a495cdb0edc25d237 Mon Sep 17 00:00:00 2001 From: Matthew Webster <mwebster@fmrib.ox.ac.uk> Date: Tue, 6 Aug 2013 13:31:46 +0000 Subject: [PATCH] removed redundant calc_corr --- melhlprfns.cc | 52 +++------------------------------------------------ melhlprfns.h | 2 -- 2 files changed, 3 insertions(+), 51 deletions(-) diff --git a/melhlprfns.cc b/melhlprfns.cc index c2026b9..5f7965d 100644 --- a/melhlprfns.cc +++ b/melhlprfns.cc @@ -211,53 +211,6 @@ namespace Melodic{ return out; } - Matrix calc_corr(const Matrix& in, const Matrix& weights, int econ) - { - Matrix Res; - int nrows=in.Nrows(); - int ncols=in.Ncols(); - Res = zeros(nrows,nrows); - RowVector localweights; - if(weights.Storage() == 0) - localweights = ones(1,ncols); - else - localweights = weights; - if(econ>0){ - RowVector colmeans(ncols); - for (int n=1; n<=ncols; n++) { - colmeans(n)=0; - for (int m=1; m<=nrows; m++) { - colmeans(n)+=in(m,n); - } - colmeans(n)/=nrows; - } - int dcol = econ; - Matrix suba; - - for(int ctr=1; ctr <= in.Ncols(); ctr+=dcol){ - suba=in.SubMatrix(1,nrows,ctr,Min(ctr+dcol-1,ncols)); - int scolmax = suba.Ncols(); - - for (int n=1; n<=scolmax; n++) { - double cmean=colmeans(ctr + n - 1); - double locw =localweights(ctr + n - 1); - for (int m=1; m<=nrows; m++) { - suba(m,n)-=cmean; - suba(m,n)*= locw; - } - } - Res += suba*suba.t() / ncols; - } - } - else{ - Res = SP2(in,localweights); - Res = cov_r(Res,false,econ); - } - return Res; - } //Matrix calc_corr - - - float calc_white(const Matrix& tmpE, const RowVector& tmpD, const RowVector& PercEV, int dim, Matrix& param, Matrix& paramS, Matrix& white, Matrix& dewhite) { @@ -335,7 +288,7 @@ namespace Melodic{ tmp2 = calc_white(tmpE,tmpD, tmp, dim, param, paramS, white, dewhite); } //Matrix calc_white - void calc_white(const SymmetricMatrix& Corr, int dim, Matrix& white, Matrix& dewhite) + void calc_white(const SymmetricMatrix& Corr, int dim, Matrix& white, Matrix& dewhite) { Matrix RE; DiagonalMatrix RD; @@ -349,9 +302,10 @@ namespace Melodic{ void std_pca(const Matrix& Mat, const Matrix& weights, SymmetricMatrix& Corr, Matrix& evecs, RowVector& evals, int econ) { if(weights.Storage()>0) - Corr << calc_corr(Mat, weights, econ); + Corr = cov_r(Mat, weights, econ); else Corr = cov_r(Mat,false,econ); + DiagonalMatrix tmpD; EigenValues(Corr,tmpD,evecs); evals = tmpD.AsRow(); diff --git a/melhlprfns.h b/melhlprfns.h index c57d076..0f06f33 100644 --- a/melhlprfns.h +++ b/melhlprfns.h @@ -56,8 +56,6 @@ namespace Melodic{ Matrix corrcoef(const Matrix& in1, const Matrix& in2); Matrix corrcoef(const Matrix& in1, const Matrix& in2, const Matrix& part); - Matrix calc_corr(const Matrix& in, const Matrix& weights, int econ = 20000); - float calc_white(const Matrix& tmpE, const RowVector& tmpD, const RowVector& PercEV, int dim, Matrix& param, Matrix& paramS, Matrix& white, Matrix& dewhite); float calc_white(const Matrix& tmpE, const RowVector& tmpD, const RowVector& PercEV, int dim, Matrix& white, Matrix& dewhite); void calc_white(const Matrix& tmpE, const RowVector& tmpD, int dim, Matrix& param, Matrix& paramS, Matrix& white, Matrix& dewhite); -- GitLab