I have a Markov Chain Monte Carlo code that uses a chi squared function to fit some data.
I am running into an issue now with getting unrealistic values for some of the free parameters
in the code. What I would like to do is place an lower and upper bound on the parameter value (say k1[[i]]
below ). Each iteration (k1[[i]]
) of the function produces a random number that is added or subtracted from k1[[i-1]]
giving the next step in the random walk. I would like to be able to test each current parameter (k1[[i]]
) and if it is above or below a cutoff value, choose another random number until I return to the specified range.
If k1[[i]] < lowest
or k1[[i]] > largest
, choose another Random number until lowest < k1 < largest
However I am not quite sure how to implement this into the code for each parameter.
Does anyone have any suggestions?
Table[
{
k1[[i]] = k1[[i - 1]] + weight*k1[[i - 1]]*RandomReal[{-1.0, 1.0}],
k2[[i]] = k2[[i - 1]] + weight*k2[[i - 1]]*RandomReal[{-1.0, 1.0}],
k3[[i]] = k3[[i - 1]] + weight*k3[[i - 1]]*RandomReal[{-1.0, 1.0}]
},
{i,1,range}
]
While
loop and get it to choose random numbers until the condition in the while loop (the number being out of the desired bound) is no longer met. $\endgroup$k[[1]] = Clip[...]
. $\endgroup$