I forgot to upload the R-code in last email, so heare is one
epiann <- function(T0 = 1, N=1000, ainit=1, binit=1,rho = 0.99, amean = 3,
bmean=1.6, avar =.1, bvar=.1, f){
moving <- 1
count <- 0
Temp <- T0
aout <- ainit
bout <- binit
while(moving > 0){
moving <- 0
for (i in 1:N) {
aprop <- rnorm (1,amean, avar)
bprop <- rnorm (1,bmean, bvar)
if (aprop > 0 & bprop > 0){
acceptprob <- min(1,exp((f(aout, bout) -
f(aprop,bprop))/Temp))
u <- runif(1)
if(u<acceptprob){
moving <- moving +1
aout <- aprop
bout <- bprop
}
else{aprob <- aout
bprob <- bout}
}
}
Temp <- Temp*rho
count <- count +1
}
fmin <- f(aout,bout)
return(c(aout, bout,fmin, count) )
}
out<- epiann(f = loglikelihood)
On Mon, Dec 5, 2011 at 3:46 PM, Gyanendra Pokharel <
gyanendra.pokharel@gmail.com> wrote:
> Hi all,
> I have the following code,
> When I run the code, it never terminate this is because of the while loop
> i am using. In general, if you need a loop for which you don't know in
> advance how many iterations there will be, you can use the `while'
> statement so here too i don't know the number how many iterations are
> there. So Can some one suggest me whats going on?
> I am using the Metropolis simulated annealing algorithm
> Best
>
[[alternative HTML version deleted]]