/* $OpenXM: OpenXM/src/hgm/mh/src/code-n.c,v 1.2 2013/02/19 08:03:14 takayama Exp $ License: LGPL Ref: Copied from this11/misc-2011/A1/wishart/Prog cf. @s/2011/12/01-my-note-code-n.pdf */ #include #include #include static void error_code(char *s); static void showf(char *s,double *v,int m); static void showd(char *s,int *v,int m); extern int MH_M; extern int MH_RANK; static int bitcount(int n) {int c; c=0; while (n) { ++c; n &= (n-1); } return(c);} #define join(k,jj) ( (1 << k) | jj) #define delete(k,jj) ( (~(1 << k)) & jj) #define member(k,ii) ( (1 << k) & ii) #define NaN 9.999e100 #define idxM(i,j) ((i)*MH_M+j) #define idxRank(i,j) ((i)*MH_RANK+j) /* p(x) = exp(-bsum*x)*x^(MH_M*(c-a)) f is p(x)*pd{J}F */ void mh_rf(double x, double *f, int rank_not_used, double *val, int n_not_used) { extern double *MH_Beta; /* beta = (1/2)*\simga^(-1) */ extern double *MH_Ng; /* freedom */ extern int MH_Mg; /* number of variables, MH_Mg=MH_M */ static int initialized = 0; /* static double b[MH_M]; */ static double *b; static double bsum = 0; static double a; static double c; static int m; /* static int bitSize[MH_RANK]; static int invbitSize[MH_RANK]; */ static int *bitSize; static int *invbitSize; int i,j,k,p; int ii,jj; /* stands for I and J */ double rijj; /* double yik[MH_M][MH_M]; double yik2[MH_M][MH_M]; double y[MH_M]; */ static double *yik=NULL; static double *yik2=NULL; static double *y=NULL; /* double f2[MH_M][MH_RANK];*/ static double *f2=NULL; if (!initialized) { b = (double *)mh_malloc(sizeof(double)*MH_M); bitSize = (int *)mh_malloc(sizeof(int)*MH_RANK); invbitSize = (int *)mh_malloc(sizeof(int)*MH_RANK); f2 = (double *)mh_malloc(sizeof(double)*MH_M*MH_RANK); yik = (double *)mh_malloc(sizeof(double)*MH_M*MH_M); yik2 = (double *)mh_malloc(sizeof(double)*MH_M*MH_M); y = (double *)mh_malloc(sizeof(double)*MH_M); m = MH_Mg; if (m != MH_M) error_code("MH_M != m. MH_M is given by -DMH_M..."); a = ((double)m+1.0)/2.0; if(MH_Beta != NULL) for (i=0;i