#include #include #include #include #include //small functions used later in MCMC double square(double x){ double y = x*x; return y ; } double logitInverse(double x){ return 1.0/(1.0 + exp(-1.0 * x)); } //read row ii of a matrix with dd columns void ReadRow(double *XX, int ii, double *Row, int *nn, int *dd) { for(int kk =0; kk < dd[0]; kk++) { Row[kk] = XX[ii + kk*nn[0]]; } } //write row ii in a matrix void WriteRow(double *XX, int ii, double *Xvec, int *nn, int *dd) { for(int kk = 0; kk < dd[0]; kk ++) { XX[ii + kk*nn[0]] = Xvec[kk]; } } //extract Y and Z matrix for KK network with nn rows and pp columns void getY(double *Mat,double *NewMat, int *nn,int kk){ int ss = 0.0; if(kk > 0){ for(int ll = 0;ll < kk; ll++){ ss += nn[ll]*nn[ll]; } } for(int xx= 0;xx < nn[kk]; xx++){ for(int yy =0; yy < nn[kk]; yy++){ NewMat[xx+yy*nn[kk]] = Mat[xx+yy*nn[kk]+ss]; } } } void getZ(double *Mat,double *NewMat, int *nn,int dd,int kk){ int ss = 0.0; if(kk > 0){ for(int ll = 0;ll < kk; ll++){ ss += (dd*nn[ll]); } } for(int xx= 0;xx < nn[kk]; xx++){ for(int yy =0; yy < dd; yy++){ NewMat[xx+yy*nn[kk]] = Mat[xx+yy*nn[kk]+ss]; } } } //ss = sum(nn[1:kk] for kk groups void readX(double *X,double *newX, int *nn, int pp, int kk){ int ss = 0.0; if(kk > 0){ for(int ll = 0;ll < kk; ll++){ ss += nn[ll]*nn[ll]; } } for(int xx = 0; xx < nn[kk]; xx++){ for(int yy = 0; yy < nn[kk];yy ++){ for(int zz =0; zz