jhncl/Model-in-C
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Code is mostly out of date, for up-to-date qfaBayes code see R package QFABayes: https://r-forge.r-project.org/scm/viewvc.php/pkg/qfaBayes/?root=qfa C code within the R package is found in the src directory. ################################################################################# SHM IHM JHM Things To Do: Makefile build main should depend on data condor grab data and main from within folder i.e. SHM/data100 no need for .o files etc. makefile to cp main to second location Data git clone "****" git commit -m 'jh' git add "file" git rm "file" git push -u origin master Set up git git config --global user.name "Your Name" git config --global user.email j.j.heydari@ncl.ac.uk Next steps: mkdir Model-in-C cd Model-in-C git init touch README git add README git commit -m 'first commit' git remote add origin git@github.com:jhncl/Model-in-C.git git push -u origin master Existing Git Repo? cd existing_git_repo git remote add origin git@github.com:jhncl/Model-in-C.git git push -u origin master git pull spare code /*READ IN*/ gsl_matrix *getParticleMatrix(char *filename) { int line_length = 10000000; int nrows, ncols; FILE* f; char *pch; char line[10000000]; gsl_matrix *particles; f=fopen(filename, "r"); if(NULL==f) { fprintf(stderr, "Cannot open file %s\n", filename); exit(1); } nrows = 0, ncols = 0; /*Scan once to get the dimensions there doesn't seem to be a realloc matrix function */ while(fgets(line, line_length, f) != NULL){ pch = strtok(line," "); while(nrows == 0 && pch != NULL ) { ncols++; pch = strtok(NULL," "); } nrows++; } fclose(f); /*Create matrix and fill up*/ particles = gsl_matrix_alloc(nrows, ncols); nrows = 0; ncols = 0; f=fopen(filename, "r"); while(fgets(line, line_length, f) != NULL){ pch = strtok(line," "); while(pch != NULL ) { gsl_matrix_set(particles, nrows, ncols, atof(pch)); ncols++; pch = strtok(NULL," "); } ncols = 0; nrows++; } fclose(f); return(particles); } double meanParticleMatrix(gsl_matrix* matrix,int col,int start,int end){ int i; double mean=0; for (i=start;i<=end;i++){ mean=mean+gsl_matrix_get(matrix,i,col); } mean=mean/(end-start+1); return(mean); } int datadouble(char filename[], char filename2[], double datavec[],int length,struct_data *D) { int i; double P,K,r; gsl_matrix* matrixA=getParticleMatrix(filename); gsl_matrix* matrixB=getParticleMatrix(filename2); i=D->SHIFTmn+2*D->L+3-1; P=exp(meanParticleMatrix(matrixA,i,1,D->CAPiter)); for (i=0;i<D->SHIFTmn;i++){ K=exp(meanParticleMatrix(matrixA,i,1,D->CAPiter)); r=exp(meanParticleMatrix(matrixA,i+D->SHIFTmn+2*D->L+4-1,1,D->CAPiter)); D->y[i]=(r/log(2*gsl_max(0,K-P)/gsl_max(0,K-2*P)))*(log(K/P)/log(2)); } i=D->SHIFTmn+2*D->L+3-1; P=exp(meanParticleMatrix(matrixB,i,1,D->CAPiter)); for (i=0;i<(D->MAXmn-D->SHIFTmn);i++){ K=exp(meanParticleMatrix(matrixB,i,1,D->CAPiter)); r=exp(meanParticleMatrix(matrixB,i+(D->MAXmn-D->SHIFTmn)+2*D->L+4-1,1,D->CAPiter)); D->y[D->SHIFTmn+i]=(r/log(2*gsl_max(0,K-P)/gsl_max(0,K-2*P)))*(log(K/P)/log(2)); } return 0; } for (i=0;i<1000;i++){ D_para->alpha_c[1]=MCMC_base_adaptive( RNG,D,D_para,D_priors,&D_MH->accept_nu,&D_MH->halpha_c,D_para->alpha_c[1],MCMC_alpha_c,-999,-999,-999); D_para->sigma_gamma=MCMC_base_adaptive( RNG,D,D_para,D_priors,&D_MH->accept_Z,&D_MH->hsigma_gamma,D_para->sigma_gamma,MCMC_sigma_gamma,-999,-999,-999); D_para->upsilon_c[1]=MCMC_base_adaptive( RNG,D,D_para,D_priors,&D_MH->accept_up,&D_MH->hupsilon_c,D_para->upsilon_c[1],MCMC_upsilon_c,-999,-999,-999); D_para->sigma_upsilon=MCMC_base_adaptive( RNG,D,D_para,D_priors,&D_MH->accept_Z,&D_MH->hsigma_upsilon,D_para->sigma_upsilon,MCMC_sigma_upsilon,-999,-999,-999); D_para->sigma_nu=MCMC_base_adaptive(RNG,D,D_para,D_priors,&D_MH->accept_Z,&D_MH->hsigma_nu,D_para->sigma_nu,MCMC_sigma_nu,-999,-999,-999); D_para->Z_p=gauss_sample(RNG,D,0,D->L,D_para->Z_l,exp(D_para->sigma_Z),D_priors->Z_mu,D_priors->eta_Z_p); D_para->sigma_Z=gsl_min(10,MCMC_base( RNG,D,D_para,D_priors,&D_MH->accept_Z,&D_MH->hsigma_Z,D_para->sigma_Z,MCMC_sigma_Z,-999,-999,-999)); D_para->nu_p=gauss_sample(RNG,D,0,D->L,D_para->nu_l,exp(D_para->sigma_nu),D_priors->nu_mu,D_priors->eta_nu_p); for (l=0;l<D->L;l++){ D_para->delta_l[l]=aug_delta_l(RNG,D,D_para,D_priors,l); D_para->gamma_cl[l]=MCMC_base_adaptive( RNG,D,D_para,D_priors,&D_MH->accept_Z,&D_MH->hgamma_cl,D_para->gamma_cl[l],MCMC_gamma_cl,-999,l,-999); D_para->Z_l[l]=MCMC_base_adaptive(RNG,D,D_para,D_priors,&D_MH->accept_Z,&D_MH->hZ_l,D_para->Z_l[l],MCMC_Z_l,-999,l,-999); D_para->nu_l[l]=MCMC_base_adaptive(RNG,D,D_para,D_priors,&D_MH->accept_Z,&D_MH->hnu_l,D_para->nu_l[l],MCMC_nu_l,-999,l,-999); } }
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published