Creating new Input from Bayesian Inversion

When performing a Bayesian Inversion, it is possible to retrieve the moments (mean and variance) of the posterior distribution in order to create a new input that will be used for other purposes, such as sensitivity analysis. However, that means that I have to manually check the posterior distribution shapes in order to decide the kind of distribution each parameter follows (gaussian, lognormal etc.)
Is there any way to automate this proccess, by creating a custom input from the posterior distributions? The available documentation on custom distributions has not been of much help (most probably I am not familiar enough with the concepts). I hope that you can help shed light on this issue, since it can drastically decrease the time spent on a rather tedious task.

3 Likes

Hi @ChrisP

I suggest you have a look at my response to the following post:

In short: There is no example that directly does this for a Bayesian problem, but the Input User Manual, the Statistical Inference Manual and especially this Example are your friends.

If this solves your problem, it would be great if you could share the answer here for others to see as well.

3 Likes

3 posts were split to a new topic: How many samples per variable are needed in order to accurately infer their distributions

Hello @ChrisP and @paulremo,

I had the same question, and thanks to the former discussion on UQlab, I sorted it out.
I adapted the former response of Paul to my own problem, and here is a description of the case.

I have one input, which follows a (prior) Lognormal distribution. After the Bayesian inversion (without postprocessing like burn-in or so), I have two options :

  1. To get the post mean and standard deviation (in the results of the Bayesian Analysis), and to create a post Lognormal distribution, based on those parameters.
  2. The other option is to create a post input, based on the samples of MCMC and an inference.

Finally a graphical comparison is plot, based on the PDF of the two post inputs to find out if the two methods leads to different post distributions.

Here is the piece of code I used (after the bayesian inversion) :

% Option 1 : Get the postprocessing results, ie mean and standard deviation
dist_post_pro.Name = 'distribution inversion postpro';
dist_post_pro.Marginals(1).Name = 'E';
dist_post_pro.Marginals(1).Type = 'LogNormal';
dist_post_pro.Marginals(1).Moments = [myBayes.Results.PostProc.Percentiles.Mean(1) sqrt(myBayes.Results.PostProc.Percentiles.Var(1))];
mydist_post_pro = uq_createInput(dist_post_pro); %the distribution based on mean and std

%Option 2 : Inference of the samples created in MCMC
PostSample3D = myBayes.Results.PostProc.PostSample ; 
PostSample2D = reshape(permute(PostSample3D, [2 1 3]), size(PostSample3D, 2), [])';
iOpts.Inference.Data = PostSample2D ; 
iOpts.Copula.Type = 'Independent';
iOpts.Inference.Criterion = 'KS';
mydist_infer = uq_createInput(iOpts);

%Creation of samples from the two post-inputs 
Xtest_bayes= uq_getSample(mydist_post_pro , 10000, 'LHS');
Xtest_inf= uq_getSample(mydist_infer , 10000, 'LHS');

% Comparison with a Normalized histogram (a kind of PDF) 
histogram(Xtest_bayes, 'Normalization','probability')
hold on 
histogram(Xtest_inf,'Normalization','probability')

I decided not to use the inference after the comparison, because the results were almost the same with the postproc, but I think it is highly problem dependent.

Let me know if you have further questions or remarks on the code I provided :grinning:

2 Likes