Created
December 4, 2015 16:34
-
-
Save CnrLwlss/6e1af1d9ad5fcd7c99c8 to your computer and use it in GitHub Desktop.
Truncating priors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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