florianhartig / BayesianTools

General-Purpose MCMC and SMC Samplers and Tools for Bayesian Statistics
https://cran.r-project.org/web/packages/BayesianTools/index.html
115 stars 29 forks source link

Setted number of chains #183

Closed sbfiedler closed 5 years ago

sbfiedler commented 5 years ago

Hi Florian,

These are my settings:

bayesianSetup <- createBayesianSetup(objective, lower = refPar$lower[parSel], upper = refPar$upper[parSel], best = refPar$default[parSel], names = rownames(refPar)[parSel])
settings <- list(iterations = 100000, nrChains = 2)
out <- runMCMC(bayesianSetup = bayesianSetup, sampler = "DEzs", settings = settings)

summary(out) shows the following:

...
# MCMC sampler:  DEzs 
# Nr. Chains:  6 
# Iterations per chain:  33334 
...

The number of iterations per chain suggest that three chains were actually calculated (3*33334 = about 100000 iterations). This is also verified by three differently colored solid lines in plot(out) that are doing something. There are three additional solid lines in a different color staying at the same level. I am now wondering

  1. why three chains instead of two chains were caluclated.
  2. why 6 chains are shown.
  3. if the 3 additional chains (doing nothing in the plots) influence my results.

Thank you and all the best, Sebastian.

woodwards commented 5 years ago

I think I can answer this. It is confusing.

You asked for 2 independent chains with 100000 iterations each.

The DEzs method (like the DREAMzs one I tend to use) has startValue=3 (default) non-independent internal chains that it runs in parallel to explore the parameter space. The 100000 iterations for each independent DEzs chain is split among these 3 internal chains.

So you get 2 independent DEzs chains, each consisting 100000 samples that get split between 3 non-independent internal chains.

florianhartig commented 5 years ago

Yes, Simon is right - it's a design principle of the DE algorithm family that you run several chains in parallel and use their mix to generate the proposal. Those chains are actually quasi-independent as soon as the algorithm is in equilibrium (but possibly dependent before), so effectively you get 100,000 iterations for each of the two chains, but those are split across the internal chains.

In the summary functions, we treat the output as 6 chains, but in fact it is 2x3 chains, with the 3 being slightly correlated during warm-up (the correlation info can sometimes be important when calculating summary statistics, for example we do not recommend running only one DE chain, even though you could formally calculate convergence diagnostics from the internal chains).