# Choice of proposal distributions in Bayesian calibration

**URL:** https://openturns.discourse.group/t/choice-of-proposal-distributions-in-bayesian-calibration/337
**Category:** Methodology
**Created:** [January 12, 2024, 1:56pm UTC](https://openturns.discourse.group/t/choice-of-proposal-distributions-in-bayesian-calibration/337 "2024-01-12T13:56:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![elieso](https://avatars.discourse-cdn.com/v4/letter/e/f04885/32.png) [@elieso](https://openturns.discourse.group/u/elieso)
#### Post date: [January 12, 2024, 1:56pm UTC](https://openturns.discourse.group/t/choice-of-proposal-distributions-in-bayesian-calibration/337/1 "2024-01-12T13:56:46Z")

</div>

Hi all,

I am running a Bayesian calibration using Independant Metropolis Hastings algorithm.  
My problem has 6 inputs variables and 2 quantities of interest as outputs.  
I use a Gibbs sampler.

I have some trouble tuning my MH algorithm in order to get good acceptance rates of the chains and to get nice posterior distributions.  
I assume that the choice of the proposal distributions (for each of my 6 input variables) is of great importance here.

Do you have advice on how i can choose these distributions ?

For the sake of completeness, here are the PRIOR distributions I use :

```auto
ot.Normal(1.096e5,2e3)
ot.Normal(0.23,1.5e-3)
ot.Uniform(0.1,1.0) 
ot.Uniform(0.047,0.75)
ot.Uniform(0.7,0.9)
ot.Uniform(0.29,0.7)

```

Also, I use a Kriging surrogate model as forward model in the MH algorithm.  
I also specify that the experimental values I use to perform the calibration are within the model response using prior distributions.

Thanks by advance for any help or clue on this topic !  
Best regards

Elie

---

<div class="post-metadata">

### Author: ![josephmure](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/josephmure/32/114_2.png) [@josephmure](https://openturns.discourse.group/u/josephmure)
#### Post date: [January 24, 2024, 1:27pm UTC](https://openturns.discourse.group/t/choice-of-proposal-distributions-in-bayesian-calibration/337/2 "2024-01-24T13:27:26Z")

</div>

Hi @elieso ! With independent Metropolis-Hastings, your proposal distribution needs to be “close” to the posterior distribution. The closer it is, the better the acceptance rate. If you have no idea what the posterior distribution looks like, it will be hard to choose a proposal distribution.

I have several questions for you:

1. Have you tried random walk Metropolis-Hastings?
2. Have you tried to visualize the log-PDF of the posterior distribution using cross-cuts? Here is an [example](https://openturns.github.io/openturns/1.22/auto_reliability_sensitivity/sensitivity_analysis/plot_sensitivity_wingweight.html#cross-cuts-of-the-function) : you need to replace `m.model` with a function which calls the [computeLogPosterior](https://openturns.github.io/openturns/1.22/user_manual/_generated/openturns.IndependentMetropolisHastings.html#openturns.IndependentMetropolisHastings.computeLogPosterior) method and you need to define a reference point (maybe simply use the mean of the prior distribution, that way you only need to replace `m.distributionX` with your prior distribution).
3. Could you share more of your code? As always, it is easier to give appropriate answers with a better understanding of your use case.

---

<div class="post-metadata">

### Author: ![elieso](https://avatars.discourse-cdn.com/v4/letter/e/f04885/32.png) [@elieso](https://openturns.discourse.group/u/elieso)
#### Post date: [February 29, 2024, 2:58pm UTC](https://openturns.discourse.group/t/choice-of-proposal-distributions-in-bayesian-calibration/337/3 "2024-02-29T14:58:15Z")

</div>

Hi,

Thanks for these information !  
I have indeed no idea what the shapes of the posterior distributions will look like…

I have 6 uncertain variables to calibrate, and my surrogate model outputs 2 quantities of interest.

This problem is related to the topic i’ve created before here:

> [@Use Kriging as forward model in Bayesian calibration](https://openturns.discourse.group/t/use-kriging-as-forward-model-in-bayesian-calibration/262/13):
>
> Hi @elieso and sorry for the delay, I have not had time to browse the forum for a while. If your Kriging model has output dimension 2, let’s say \boldsymbol{Y}(x) = (Y\_1(x), Y\_2(x))^T where x is the N\_d-dimensional input, then \boldsymbol{Y}(x) follows a bivariate normal distribution. Therefore your conditional distribution is going to be defined with: conditional = ot.Normal(2) And your link function will need to output the parameters of a bivariate normal distribution. To see what these p…

Here I can show you the prior distributions I use :

```auto
# variable X0
distribName	= 'Normal'
    P_mean = 1.0e5  	
    P_std = 2000  	
    PdistParams = [P_mean,P_std] 
# variable X1
    distribName = 'Normal'
    lev_mean = 0.27
    lev_std = 3.5e-2 # good 1.5e-2
    levDistParam = [lev_mean,lev_std] 
# variable X2
    distribName = 'LogNormal'     
    m_mu = 0.1           
    m_sigma = 1.0           
    mDistParam = [m_mu,m_sigma] 

# variable X3 
    alphadistribName	= 'Uniform'
    alpha_min = 0.047 
    alpha_max = 0.75
    alphaDistParams = [alpha_min,alpha_max] 
# variable X4
    betaDistribName = 'Uniform'
    beta_min = 0.7 
    beta_max = 0.9 
    betaDistParams = [beta_min,beta_max] 
# variable X5 
    gammaDistribName	= 'Uniform'
    gamma_min = 0.29 
    gamma_max = 0.7
    gammaDistParams = [gamma_min,gamma_max] 

```

The Random MH algorithm and Gibbs sampler definition i tried is the following (note that i tried to take proposals distributions having the same mean as the priors) :

```auto
propStd = 1 
proposal =[ot.Normal(1e5,propStd),    
                       ot.Normal(0.27	,propStd),      
                       ot.Normal(0.1	,propStd),     
                       ot.Normal(0.3985	,propStd),      
                       ot.Normal(0.8	,propStd),      
                       ot.Normal(0.495	,propStd)]      
                    
mh_coll = [
        ot.RandomWalkMetropolisHastings(priorDistrib,initialState,proposal,[i])  
        for i in range(0,Nd)
            ]    
        
for mh in mh_coll:
    mh.setLikelihood(conditional,Yexp,linkFunction) 

sampler = ot.Gibbs(mh_coll) 
sampleSize = int(5e4) 
sampler.setBurnIn(int(sampleSize/5))

```

Also, to be complete, the linkFunction is a Kriging model mapping the 6 uncertain inputs to the 2 quantities of interest. Of course, the experimental data used to calibrate are within the bounds of the quantities of interest when propagated with these prior distributions.

I get really small acceptance rates with this set of parameters…

Thanks again !

Best regards,  
Elie

---

<div class="post-metadata">

### Author: ![josephmure](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/josephmure/32/114_2.png) [@josephmure](https://openturns.discourse.group/u/josephmure)
#### Post date: [July 11, 2024, 11:53am UTC](https://openturns.discourse.group/t/choice-of-proposal-distributions-in-bayesian-calibration/337/4 "2024-07-11T11:53:16Z")

</div>

Hi! Again, sorry for the late reply. I don’t understand parts of your code.

This part should not work:

```python
mh_coll = [
        ot.RandomWalkMetropolisHastings(priorDistrib,initialState,proposal,[i])  
        for i in range(0,Nd)
            ]   

```

because you defined `proposal` as a list:

```python
proposal =[ot.Normal(1e5,propStd),    
                       ot.Normal(0.27	,propStd),      
                       ot.Normal(0.1	,propStd),     
                       ot.Normal(0.3985	,propStd),      
                       ot.Normal(0.8	,propStd),      
                       ot.Normal(0.495	,propStd)]  

```

I also think there is a misunderstanding about what the proposal is: in the case of `RandomWalkMetropolisHastings`, it is the distribution of the _steps_ of the random walk. In the case where a normal distribution is used for the step, that distribution should probably have zero mean (unless you have a really good reason to want to skew the proposal towards the right).
