Skip to content

Instantly share code, notes, and snippets.

@CnrLwlss
Created December 4, 2015 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CnrLwlss/6e1af1d9ad5fcd7c99c8 to your computer and use it in GitHub Desktop.
Save CnrLwlss/6e1af1d9ad5fcd7c99c8 to your computer and use it in GitHub Desktop.
Truncating priors
double MCMC_base_truncate_low(double truncate, struct_data *D,struct_para *D_para,struct_priors *D_priors,double *accept,double *h,double para,double (*foo)(struct struct_data *D,struct struct_para *D_para,struct struct_priors *D_priors,double,int,int),int l, int m){
double logu,logaprob,can;
//can=rnorm(para,*h); /*can=para+gsl_ran_gaussian(RNG,*h);*/
// if(can<=(truncate)){
// can=para;
// }
can=truncate-1.0;
while(can<=truncate){
can=rnorm(para,*h);
}
logaprob=(*foo)(D,D_para,D_priors,can,l,m)-(*foo)(D,D_para,D_priors,para,l,m);
logu=log(1-runif(0,1)); /*logu=log(1-gsl_rng_uniform(RNG));*/
if (logaprob>logu){para=can;*accept=*accept+1;}
return(para);
}
double MCMC_base_truncate_high(double truncate, struct_data *D,struct_para *D_para,struct_priors *D_priors,double *accept,double *h,double para,double (*foo)(struct struct_data *D,struct struct_para *D_para,struct struct_priors *D_priors,double,int,int),int l, int m){
double logu,logaprob,can;
//can=rnorm(para,*h);
// if(can>=(truncate)){
// can=para;
// }
can=truncate+1.0;
while(can>=truncate){
can=rnorm(para,*h);
}
logaprob=(*foo)(D,D_para,D_priors,can,l,m)-(*foo)(D,D_para,D_priors,para,l,m);
logu=log(1-runif(0,1));
if (logaprob>logu){para=can;*accept=*accept+1;}
return(para);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment