From b9758364059d52e153a9f1b4fcae3bc3f3e68422 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Fri, 7 Jul 2017 06:54:26 +0000 Subject: Fix spacing --- src/bslmm.cpp | 780 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 390 insertions(+), 390 deletions(-) (limited to 'src/bslmm.cpp') diff --git a/src/bslmm.cpp b/src/bslmm.cpp index 563b743..d579802 100644 --- a/src/bslmm.cpp +++ b/src/bslmm.cpp @@ -1,17 +1,17 @@ /* Genome-wide Efficient Mixed Model Association (GEMMA) Copyright (C) 2011-2017, Xiang Zhou - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see . */ @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -50,32 +50,32 @@ using namespace std; void BSLMM::CopyFromParam (PARAM &cPar) { a_mode=cPar.a_mode; d_pace=cPar.d_pace; - + file_bfile=cPar.file_bfile; file_geno=cPar.file_geno; file_out=cPar.file_out; path_out=cPar.path_out; - - l_min=cPar.h_min; - l_max=cPar.h_max; - n_region=cPar.n_region; + + l_min=cPar.h_min; + l_max=cPar.h_max; + n_region=cPar.n_region; pve_null=cPar.pve_null; pheno_mean=cPar.pheno_mean; - + time_UtZ=0.0; time_Omega=0.0; n_accept=0; - - h_min=cPar.h_min; - h_max=cPar.h_max; + + h_min=cPar.h_min; + h_max=cPar.h_max; h_scale=cPar.h_scale; - rho_min=cPar.rho_min; - rho_max=cPar.rho_max; + rho_min=cPar.rho_min; + rho_max=cPar.rho_max; rho_scale=cPar.rho_scale; - logp_min=cPar.logp_min; - logp_max=cPar.logp_max; + logp_min=cPar.logp_min; + logp_max=cPar.logp_max; logp_scale=cPar.logp_scale; - + s_min=cPar.s_min; s_max=cPar.s_max; w_step=cPar.w_step; @@ -86,17 +86,17 @@ void BSLMM::CopyFromParam (PARAM &cPar) { geo_mean=cPar.geo_mean; randseed=cPar.randseed; trace_G=cPar.trace_G; - + ni_total=cPar.ni_total; ns_total=cPar.ns_total; ni_test=cPar.ni_test; ns_test=cPar.ns_test; n_cvt=cPar.n_cvt; - + indicator_idv=cPar.indicator_idv; indicator_snp=cPar.indicator_snp; snpInfo=cPar.snpInfo; - + return; } @@ -108,7 +108,7 @@ void BSLMM::CopyToParam (PARAM &cPar) { cPar.n_accept=n_accept; cPar.pheno_mean=pheno_mean; cPar.randseed=randseed; - + return; } @@ -119,28 +119,28 @@ void BSLMM::WriteBV (const gsl_vector *bv) { ofstream outfile (file_str.c_str(), ofstream::out); if (!outfile) { - cout<<"error writing file: "< > &beta_g, +void BSLMM::WriteParam (vector > &beta_g, const gsl_vector *alpha, const size_t w) { string file_str; file_str=path_out+"/"+file_out; @@ -148,20 +148,20 @@ void BSLMM::WriteParam (vector > &beta_g, ofstream outfile (file_str.c_str(), ofstream::out); if (!outfile) { - cout<<"error writing file: "< > &beta_g, outfile<<0.0<<"\t"<<0.0< &rank) { size_t pos; for (size_t i=0; isize2, UtXgamma->size2); gsl_vector *Xty=gsl_vector_alloc (UtXgamma->size2); gsl_vector *OiXty=gsl_vector_alloc (UtXgamma->size2); gsl_matrix_set_identity (Omega); - gsl_matrix_scale (Omega, 1.0/sigma_a2); + gsl_matrix_scale (Omega, 1.0/sigma_a2); lapack_dgemm ((char *)"T", (char *)"N", 1.0, UtXgamma, UtXgamma, 1.0, Omega); gsl_blas_dgemv (CblasTrans, 1.0, UtXgamma, Uty, 0.0, Xty); CholeskySolve(Omega, Xty, OiXty); - + gsl_blas_ddot (Xty, OiXty, &pve); gsl_blas_ddot (Uty, Uty, &var_y); - + pve/=var_y; - + gsl_matrix_free (Omega); gsl_vector_free (Xty); gsl_vector_free (OiXty); @@ -342,28 +342,28 @@ double BSLMM::CalcPveLM (const gsl_matrix *UtXgamma, const gsl_vector *Uty, return pve; } -void BSLMM::InitialMCMC (const gsl_matrix *UtX, const gsl_vector *Uty, - vector &rank, class HYPBSLMM &cHyp, +void BSLMM::InitialMCMC (const gsl_matrix *UtX, const gsl_vector *Uty, + vector &rank, class HYPBSLMM &cHyp, vector > &pos_loglr) { double q_genome=gsl_cdf_chisq_Qinv(0.05/(double)ns_test, 1); - + cHyp.n_gamma=0; for (size_t i=0; iq_genome) {cHyp.n_gamma++;} } if (cHyp.n_gamma<10) {cHyp.n_gamma=10;} - + if (cHyp.n_gamma>s_max) {cHyp.n_gamma=s_max;} - if (cHyp.n_gamma1.0) {cHyp.rho=1.0;} - + if (cHyp.hh_max) {cHyp.h=h_max;} if (cHyp.rhorho_max) {cHyp.rho=rho_max;} if (cHyp.logplogp_max) {cHyp.logp=logp_max;} - + cout<<"initial value of h = "<size; i++) { - d=gsl_ran_gaussian(gsl_r, 1); - gsl_vector_set(beta, i, d); + d=gsl_ran_gaussian(gsl_r, 1); + gsl_vector_set(beta, i, d); } - gsl_blas_dtrsv(CblasUpper, CblasNoTrans, CblasNonUnit, Omega, beta); - + gsl_blas_dtrsv(CblasUpper, CblasNoTrans, CblasNonUnit, Omega, beta); + // This computes inv(L^T(Omega)) %*% beta. gsl_vector_scale(beta, sqrt(sigma_a2/tau)); - gsl_vector_add(beta, beta_hat); + gsl_vector_add(beta, beta_hat); gsl_blas_dgemv (CblasNoTrans, 1.0, UtXgamma, beta, 0.0, UtXb); - + // Sample alpha. gsl_vector_memcpy (alpha_prime, Uty); gsl_vector_sub (alpha_prime, UtXb); gsl_vector_mul (alpha_prime, weight_Hi); gsl_vector_scale (alpha_prime, sigma_b2); - + // Sample u. gsl_vector_memcpy (Utu, alpha_prime); gsl_vector_mul (Utu, K_eval); - + if (a_mode==11) {gsl_vector_scale (Utu_rand, sqrt(1.0/tau));} - gsl_vector_add (Utu, Utu_rand); - + gsl_vector_add (Utu, Utu_rand); + // For quantitative traits, calculate pve and pge. if (a_mode==11) { gsl_blas_ddot (UtXb, UtXb, &d); cHyp.pge=d/(double)ni_test; - + gsl_blas_ddot (Utu, Utu, &d); cHyp.pve=cHyp.pge+d/(double)ni_test; - + if (cHyp.pve==0) {cHyp.pge=0.0;} else {cHyp.pge/=cHyp.pve;} - cHyp.pve/=cHyp.pve+1.0/tau; - } + cHyp.pve/=cHyp.pve+1.0/tau; + } gsl_matrix_free (UtXgamma_eval); gsl_matrix_free (Omega); gsl_vector_free (XtHiy); gsl_vector_free (beta_hat); - gsl_vector_free (Utu_rand); + gsl_vector_free (Utu_rand); gsl_vector_free (weight_Hi); - + logpost=-0.5*logdet_H-0.5*logdet_O; if (a_mode==11) {logpost-=0.5*(double)ni_test*log(P_yy);} else {logpost-=0.5*P_yy;} logpost+=((double)cHyp.n_gamma-1.0)*cHyp.logp+ ((double)ns_test-(double)cHyp.n_gamma)*log(1.0-exp(cHyp.logp)); - + return logpost; } // Calculate pve and pge, and calculate z_hat for case-control data. -void BSLMM::CalcCC_PVEnZ (const gsl_matrix *U, const gsl_vector *Utu, +void BSLMM::CalcCC_PVEnZ (const gsl_matrix *U, const gsl_vector *Utu, gsl_vector *z_hat, class HYPBSLMM &cHyp) { double d; - + gsl_blas_ddot (Utu, Utu, &d); - cHyp.pve=d/(double)ni_test; - + cHyp.pve=d/(double)ni_test; + gsl_blas_dgemv (CblasNoTrans, 1.0, U, Utu, 0.0, z_hat); - + cHyp.pve/=cHyp.pve+1.0; - cHyp.pge=0.0; - + cHyp.pge=0.0; + return; } // Calculate pve and pge, and calculate z_hat for case-control data. -void BSLMM::CalcCC_PVEnZ (const gsl_matrix *U, const gsl_vector *UtXb, - const gsl_vector *Utu, gsl_vector *z_hat, +void BSLMM::CalcCC_PVEnZ (const gsl_matrix *U, const gsl_vector *UtXb, + const gsl_vector *Utu, gsl_vector *z_hat, class HYPBSLMM &cHyp) { double d; gsl_vector *UtXbU=gsl_vector_alloc (Utu->size); - + gsl_blas_ddot (UtXb, UtXb, &d); cHyp.pge=d/(double)ni_test; - + gsl_blas_ddot (Utu, Utu, &d); cHyp.pve=cHyp.pge+d/(double)ni_test; - + gsl_vector_memcpy (UtXbU, Utu); gsl_vector_add (UtXbU, UtXb); - gsl_blas_dgemv (CblasNoTrans, 1.0, U, UtXbU, 0.0, z_hat); - + gsl_blas_dgemv (CblasNoTrans, 1.0, U, UtXbU, 0.0, z_hat); + if (cHyp.pve==0) {cHyp.pge=0.0;} else {cHyp.pge/=cHyp.pve;} - + cHyp.pve/=cHyp.pve+1.0; - + gsl_vector_free(UtXbU); return; } -void BSLMM::SampleZ (const gsl_vector *y, const gsl_vector *z_hat, - gsl_vector *z) { +void BSLMM::SampleZ (const gsl_vector *y, const gsl_vector *z_hat, + gsl_vector *z) { double d1, d2, z_rand=0.0; for (size_t i=0; isize; ++i) { d1=gsl_vector_get (y, i); @@ -634,7 +634,7 @@ void BSLMM::SampleZ (const gsl_vector *y, const gsl_vector *z_hat, if (d1<=0.0) { // Control, right truncated. - do { + do { z_rand=d2+gsl_ran_gaussian(gsl_r, 1.0); } while (z_rand>0.0); } @@ -643,25 +643,25 @@ void BSLMM::SampleZ (const gsl_vector *y, const gsl_vector *z_hat, z_rand=d2+gsl_ran_gaussian(gsl_r, 1.0); } while (z_rand<0.0); } - + gsl_vector_set (z, i, z_rand); } return; } -double BSLMM::ProposeHnRho (const class HYPBSLMM &cHyp_old, +double BSLMM::ProposeHnRho (const class HYPBSLMM &cHyp_old, class HYPBSLMM &cHyp_new, const size_t &repeat) { - + double h=cHyp_old.h, rho=cHyp_old.rho; - + double d_h=(h_max-h_min)*h_scale, d_rho=(rho_max-rho_min)*rho_scale; - + for (size_t i=0; ih_max) {h=2*h_max-h;} - + rho=rho+(gsl_rng_uniform(gsl_r)-0.5)*d_rho; if (rhorho_max) {rho=2*rho_max-rho;} @@ -671,13 +671,13 @@ double BSLMM::ProposeHnRho (const class HYPBSLMM &cHyp_old, return 0.0; } -double BSLMM::ProposePi (const class HYPBSLMM &cHyp_old, +double BSLMM::ProposePi (const class HYPBSLMM &cHyp_old, class HYPBSLMM &cHyp_new, const size_t &repeat) { double logp_old=cHyp_old.logp, logp_new=cHyp_old.logp; double log_ratio=0.0; - + double d_logp=min(0.1, (logp_max-logp_min)*logp_scale); - + for (size_t i=0; i &rank_old, - vector &rank_new, - const double *p_gamma, - const class HYPBSLMM &cHyp_old, - class HYPBSLMM &cHyp_new, +double BSLMM::ProposeGamma (const vector &rank_old, + vector &rank_new, + const double *p_gamma, + const class HYPBSLMM &cHyp_old, + class HYPBSLMM &cHyp_new, const size_t &repeat) { map mapRank2in; size_t r; double unif, logp=0.0; int flag_gamma; size_t r_add, r_remove, col_id; - + rank_new.clear(); if (cHyp_old.n_gamma!=rank_old.size()) {cout<<"size wrong"< &rank_old, mapRank2in[r]=1; } } - cHyp_new.n_gamma=cHyp_old.n_gamma; - + cHyp_new.n_gamma=cHyp_old.n_gamma; + for (size_t i=0; i=0.40 && unif < 0.80 && + else if (unif>=0.40 && unif < 0.80 && cHyp_new.n_gamma>s_min) { flag_gamma=2; } - else if (unif>=0.80 && cHyp_new.n_gamma>0 && + else if (unif>=0.80 && cHyp_new.n_gamma>0 && cHyp_new.n_gamma &rank_old, // Delete a SNP. col_id=gsl_rng_uniform_int(gsl_r, cHyp_new.n_gamma); r_remove=rank_new[col_id]; - + double prob_total=1.0; for (size_t i=0; i &rank_old, // Be careful with the proposal. do { r_add=gsl_ran_discrete (gsl_r, gsl_t); - } while (mapRank2in.count(r_add)!=0); - + } while (mapRank2in.count(r_add)!=0); + double prob_total=1.0; for (size_t i=0; i &rank_old, } else {logp+=0;} // Do not change. } - + stable_sort (rank_new.begin(), rank_new.end(), comp_vec); mapRank2in.clear(); @@ -806,54 +806,54 @@ double BSLMM::ProposeGamma (const vector &rank_old, } bool comp_lr (pair a, pair b) { - return (a.second > b.second); + return (a.second > b.second); } // If a_mode==13 then Uty==y. -void BSLMM::MCMC (const gsl_matrix *U, const gsl_matrix *UtX, - const gsl_vector *Uty, const gsl_vector *K_eval, +void BSLMM::MCMC (const gsl_matrix *U, const gsl_matrix *UtX, + const gsl_vector *Uty, const gsl_vector *K_eval, const gsl_vector *y) { - clock_t time_start; + clock_t time_start; class HYPBSLMM cHyp_old, cHyp_new; - + gsl_matrix *Result_hyp=gsl_matrix_alloc (w_pace, 6); - gsl_matrix *Result_gamma=gsl_matrix_alloc (w_pace, s_max); - - gsl_vector *alpha_prime=gsl_vector_alloc (ni_test); + gsl_matrix *Result_gamma=gsl_matrix_alloc (w_pace, s_max); + + gsl_vector *alpha_prime=gsl_vector_alloc (ni_test); gsl_vector *alpha_new=gsl_vector_alloc (ni_test); - gsl_vector *alpha_old=gsl_vector_alloc (ni_test); + gsl_vector *alpha_old=gsl_vector_alloc (ni_test); gsl_vector *Utu=gsl_vector_alloc (ni_test); gsl_vector *Utu_new=gsl_vector_alloc (ni_test); gsl_vector *Utu_old=gsl_vector_alloc (ni_test); - + gsl_vector *UtXb_new=gsl_vector_alloc (ni_test); gsl_vector *UtXb_old=gsl_vector_alloc (ni_test); - + gsl_vector *z_hat=gsl_vector_alloc (ni_test); gsl_vector *z=gsl_vector_alloc (ni_test); - gsl_vector *Utz=gsl_vector_alloc (ni_test); + gsl_vector *Utz=gsl_vector_alloc (ni_test); + + gsl_vector_memcpy (Utz, Uty); - gsl_vector_memcpy (Utz, Uty); - double logPost_new, logPost_old; double logMHratio; - double mean_z=0.0; - + double mean_z=0.0; + gsl_matrix_set_zero (Result_gamma); gsl_vector_set_zero (Utu); gsl_vector_set_zero (alpha_prime); if (a_mode==13) { pheno_mean=0.0; } - + vector > beta_g; for (size_t i=0; i rank_new, rank_old; - vector beta_new, beta_old; + vector beta_new, beta_old; vector > pos_loglr; @@ -865,59 +865,59 @@ void BSLMM::MCMC (const gsl_matrix *U, const gsl_matrix *UtX, for (size_t i=0; itm_hour%24*3600+ ptm->tm_min*60+ptm->tm_sec); } - gsl_r = gsl_rng_alloc(gslType); + gsl_r = gsl_rng_alloc(gslType); gsl_rng_set(gsl_r, randseed); - - double *p_gamma = new double[ns_test]; + + double *p_gamma = new double[ns_test]; CalcPgamma (p_gamma); - + gsl_t=gsl_ran_discrete_preproc (ns_test, p_gamma); - + // Initial parameters. InitialMCMC (UtX, Utz, rank_old, cHyp_old, pos_loglr); - + cHyp_initial=cHyp_old; - + if (cHyp_old.n_gamma==0 || cHyp_old.rho==0) { - logPost_old=CalcPosterior(Utz, K_eval, Utu_old, alpha_old, + logPost_old=CalcPosterior(Utz, K_eval, Utu_old, alpha_old, cHyp_old); beta_old.clear(); for (size_t i=0; isize; ++i) { beta_old.push_back(gsl_vector_get(beta, i)); - } + } gsl_matrix_free (UtXgamma); gsl_vector_free (beta); - } - + } + // Calculate centered z_hat, and pve. if (a_mode==13) { time_start=clock(); @@ -929,28 +929,28 @@ void BSLMM::MCMC (const gsl_matrix *U, const gsl_matrix *UtX, } time_UtZ+=(clock()-time_start)/(double(CLOCKS_PER_SEC)*60.0); } - + // Start MCMC. int accept; size_t total_step=w_step+s_step; size_t w=0, w_col, pos; size_t repeat=0; - + for (size_t t=0; tsize; ++i) { beta_old.push_back(gsl_vector_get(beta, i)); @@ -980,7 +980,7 @@ void BSLMM::MCMC (const gsl_matrix *U, const gsl_matrix *UtX, gsl_vector_free (beta); } } - + // M-H steps. for (size_t i=0; i0 || log(gsl_rng_uniform(gsl_r))size2, UtX, bv, 0.0, beta); @@ -1181,18 +1181,18 @@ void BSLMM::RidgeR(const gsl_matrix *U, const gsl_matrix *UtX, WriteParam (beta); WriteBV(bv); - + gsl_vector_free (H_eval); gsl_vector_free (beta); gsl_vector_free (bv); - + return; } // Below fits MCMC for rho=1. void BSLMM::CalcXtX (const gsl_matrix *X, const gsl_vector *y, const size_t s_size, gsl_matrix *XtX, gsl_vector *Xty) { - time_t time_start=clock(); + time_t time_start=clock(); gsl_matrix_const_view X_sub=gsl_matrix_const_submatrix(X, 0, 0, X->size1, s_size); gsl_matrix_view XtX_sub=gsl_matrix_submatrix(XtX, 0, 0, s_size, s_size); @@ -1271,7 +1271,7 @@ void BSLMM::SetXgamma (const gsl_matrix *X, const gsl_matrix *X_old, for (size_t i=0; isize1, rank_add.size() ); gsl_matrix *XtX_aa=gsl_matrix_alloc(X_add->size2, X_add->size2); @@ -1302,7 +1302,7 @@ void BSLMM::SetXgamma (const gsl_matrix *X, const gsl_matrix *X_old, // Get t(X_add)X_add and t(X_add)X_temp. clock_t time_start=clock(); - + // Somehow the lapack_dgemm does not work here. gsl_blas_dgemm (CblasTrans, CblasNoTrans, 1.0, X_add, X_add, 0.0, XtX_aa); @@ -1325,15 +1325,15 @@ void BSLMM::SetXgamma (const gsl_matrix *X, const gsl_matrix *X_old, i_flag=0; } - gsl_vector_view Xnew_col=gsl_matrix_column(X_new, i_new); + gsl_vector_view Xnew_col=gsl_matrix_column(X_new, i_new); if (i_flag==1) { gsl_vector_view Xcopy_col=gsl_matrix_column(X_add, i_add); gsl_vector_memcpy (&Xnew_col.vector, &Xcopy_col.vector); } else { gsl_vector_const_view Xcopy_col= - gsl_matrix_const_column(X_old, i_old); + gsl_matrix_const_column(X_old, i_old); gsl_vector_memcpy (&Xnew_col.vector, &Xcopy_col.vector); - } + } if (i_flag==1) { d=gsl_vector_get (Xty_add, i_add); @@ -1385,34 +1385,34 @@ void BSLMM::SetXgamma (const gsl_matrix *X, const gsl_matrix *X_old, rank_union.clear(); mapRank2in_remove.clear(); mapRank2in_add.clear(); - + return; } -double BSLMM::CalcPosterior (const double yty, class HYPBSLMM &cHyp) { +double BSLMM::CalcPosterior (const double yty, class HYPBSLMM &cHyp) { double logpost=0.0; - + // For quantitative traits, calculate pve and pge. // Pve and pge for case/control data are calculted in CalcCC_PVEnZ. if (a_mode==11) { cHyp.pve=0.0; - cHyp.pge=1.0; + cHyp.pge=1.0; } // Calculate likelihood. if (a_mode==11) {logpost-=0.5*(double)ni_test*log(yty);} else {logpost-=0.5*yty;} - + logpost+=((double)cHyp.n_gamma-1.0)*cHyp.logp+ ((double)ns_test-(double)cHyp.n_gamma)*log(1-exp(cHyp.logp)); - + return logpost; } double BSLMM::CalcPosterior (const gsl_matrix *Xgamma, const gsl_matrix *XtX, const gsl_vector *Xty, const double yty, const size_t s_size, gsl_vector *Xb, - gsl_vector *beta, class HYPBSLMM &cHyp) { + gsl_vector *beta, class HYPBSLMM &cHyp) { double sigma_a2=cHyp.h/( (1-cHyp.h)*exp(cHyp.logp)*(double)ns_test); double logpost=0.0; double d, P_yy=yty, logdet_O=0.0; @@ -1423,10 +1423,10 @@ double BSLMM::CalcPosterior (const gsl_matrix *Xgamma, const gsl_matrix *XtX, gsl_matrix_const_submatrix (XtX, 0, 0, s_size, s_size); gsl_vector_const_view Xty_sub= gsl_vector_const_subvector (Xty, 0, s_size); - + gsl_matrix *Omega=gsl_matrix_alloc (s_size, s_size); gsl_matrix *M_temp=gsl_matrix_alloc (s_size, s_size); - gsl_vector *beta_hat=gsl_vector_alloc (s_size); + gsl_vector *beta_hat=gsl_vector_alloc (s_size); gsl_vector *Xty_temp=gsl_vector_alloc (s_size); gsl_vector_memcpy (Xty_temp, &Xty_sub.vector); @@ -1436,9 +1436,9 @@ double BSLMM::CalcPosterior (const gsl_matrix *Xgamma, const gsl_matrix *XtX, gsl_matrix_scale (Omega, sigma_a2); gsl_matrix_set_identity (M_temp); gsl_matrix_add (Omega, M_temp); - + // Calculate beta_hat. - logdet_O=CholeskySolve(Omega, Xty_temp, beta_hat); + logdet_O=CholeskySolve(Omega, Xty_temp, beta_hat); gsl_vector_scale (beta_hat, sigma_a2); gsl_blas_ddot (Xty_temp, beta_hat, &d); @@ -1453,27 +1453,27 @@ double BSLMM::CalcPosterior (const gsl_matrix *Xgamma, const gsl_matrix *XtX, // Sample beta. for (size_t i=0; i > beta_g; for (size_t i=0; i rank_new, rank_old; vector > pos_loglr; - + time_start=clock(); MatrixCalcLmLR (X, z, pos_loglr); time_Proposal=(clock()-time_start)/(double(CLOCKS_PER_SEC)*60.0); @@ -1570,44 +1570,44 @@ void BSLMM::MCMC (const gsl_matrix *X, const gsl_vector *y) { for (size_t i=0; itm_hour%24*3600+ ptm->tm_min*60+ptm->tm_sec); } - gsl_r = gsl_rng_alloc(gslType); + gsl_r = gsl_rng_alloc(gslType); gsl_rng_set(gsl_r, randseed); - - double *p_gamma = new double[ns_test]; + + double *p_gamma = new double[ns_test]; CalcPgamma (p_gamma); - + gsl_t=gsl_ran_discrete_preproc (ns_test, p_gamma); - + // Initial parameters. InitialMCMC (X, z, rank_old, cHyp_old, pos_loglr); - + cHyp_initial=cHyp_old; - if (cHyp_old.n_gamma==0) { + if (cHyp_old.n_gamma==0) { logPost_old=CalcPosterior (ztz, cHyp_old); } - else { - SetXgamma (Xgamma_old, X, rank_old); + else { + SetXgamma (Xgamma_old, X, rank_old); CalcXtX (Xgamma_old, z, rank_old.size(), XtX_old, Xtz_old); logPost_old=CalcPosterior (Xgamma_old, XtX_old, Xtz_old, ztz, rank_old.size(), Xb_old, beta_old, cHyp_old); - } + } // Calculate centered z_hat, and pve. if (a_mode==13) { @@ -1618,28 +1618,28 @@ void BSLMM::MCMC (const gsl_matrix *X, const gsl_vector *y) { CalcCC_PVEnZ (Xb_old, z_hat, cHyp_old); } } - + // Start MCMC. int accept; size_t total_step=w_step+s_step; size_t w=0, w_col, pos; size_t repeat=0; - + for (size_t t=0; t0 || log(gsl_rng_uniform(gsl_r))