Problem using multiple chains in mhsample

6 visualizaciones (últimos 30 días)
Matthew Vincent
Matthew Vincent el 13 de Oct. de 2011
Editada: XINYUE Xu el 22 de Feb. de 2022
I have set up code to use the mhsample function to estimate the posterior distribution for a complex problem with a large data set (which is confidential). As such I will not be able provide the entire coding since it is very long and will likely be more confusing. My proposal distribution and pdf is set up to take a row vector of a certain size and returns a row vector of the same size and a value for the posterior distribution, respectively. The function works when I set nchain to 1 but if I make it > 1 I get the following error message
??? Index exceeds matrix dimensions.
Error in ==> mhsample at 177 x0(acc,:) = y(acc,:); % preserves x's shape.
I have looked at the function and think I may have found the problem but am not sure how to fix it. It seems that it is attempting to access the number of rows = nchain for y the proposal values. The proposal function currently only puts out a single row vector so the values it it trying to access do not exist.
Do i need to change the proposal distribution so that it returns a matrix instead of just a row vector? If I do this I must then change it everytime that I want to try a different number if chains. Also I would need to change my pdf function to accept this matrix and then calculate separate values for the joint posterior distribution for each row. Is there a better way to deal with this problem?
Thank You Matt Vincent

Respuestas (1)

XINYUE Xu
XINYUE Xu el 22 de Feb. de 2022
Editada: XINYUE Xu el 22 de Feb. de 2022
Hi, I had the same problem and I found out this is becuase the return values of your target pdf are not in the size (nchain,1).
Once your pdf and proposal pdf work well with multiple initial points, the mhsample works.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by