% Example in Doc sec 2.2.1 to 2.2.5 modified by Sec. 2.5 
fprintf(' Example in Doc, sec 2.2.1 to 2.2.5; modified by Sec. 2.5\n ')
fprintf('Further modified to check influence of group order on scater plots')
clear all 
clearvars
uqlab
rng(100)
PriorOpts.Name = 'Model parameters prior';
PriorOpts.Marginals(1).Name = 'b';
PriorOpts.Marginals(1).Type = 'Constant';
PriorOpts.Marginals(1).Parameters = 0.15; % (m)
PriorOpts.Marginals(2).Name = 'h';
PriorOpts.Marginals(2).Type = 'Constant';
PriorOpts.Marginals(2).Parameters = 0.3; % (m)
PriorOpts.Marginals(3).Name = 'L';
PriorOpts.Marginals(3).Type = 'Constant';
PriorOpts.Marginals(3).Parameters = 5; % (m)
PriorOpts.Marginals(4).Name = 'E';
PriorOpts.Marginals(4).Type = 'Lognormal';
PriorOpts.Marginals(4).Moments = [30000 4500] ; % (MPa)
PriorOpts.Marginals(5).Name = 'p';
PriorOpts.Marginals(5).Type = 'Constant';
PriorOpts.Marginals(5).Parameters = 0.012; % (kN/m)

myPriorDist = uq_createInput(PriorOpts);

ModelOpts1.Name = 'Beam bending deflection';
ModelOpts1.mFile = 'uq_SimplySupportedBeam';
ForwardModels(1).Model = uq_createModel(ModelOpts1);


V_mid = [12.84; 13.12; 12.13; 12.19; 12.67]/1000; % (m)


% Data group 1
myData(1).y = V_mid;
myData(1).Name = 'Beam mid-span deflection';
myData(1).MOMap = [ 1;... % Model ID
                    1]; % Output ID
             
myData(1).MOMapNotUnique = [1 ]   

%  Data group 2
myData(2).y = [0.0121891451379298] 
myData(2).Name = 'Beam mid-span deflection estimate'
myData(2).MOMap = [ 1;... % Model ID 
                  1];  % Output ID
              
 myData(2).MOMapNotUnique = [ 1]    % dummy, is not evaluated in consistence check



     % Discrepancy group 1
DiscrepancyPriorOpts1.Name = 'Prior of sigma_1ˆ2';
DiscrepancyPriorOpts1.Marginals(1).Name = 'Sigma2';
DiscrepancyPriorOpts1.Marginals(1).Type = 'Uniform';
DiscrepancyPriorOpts1.Marginals(1).Parameters = [0, 1e-4];
myDiscrepancyPrior1 = uq_createInput(DiscrepancyPriorOpts1);
DiscrepancyOpts(1).Type = 'Gaussian';
DiscrepancyOpts(1).Prior = myDiscrepancyPrior1;
% D i s c r e p a n c y group 2
DiscrepancyOpts(2).Type = 'Gaussian';
DiscrepancyOpts(2).Parameters = 1e-7; % knownd i s c r e p a n c yv a r i a n c e
         
              
BayesOpts.Type = 'Inversion';
BayesOpts.Name = 'Bayesian multiple models';
BayesOpts.Prior = myPriorDist;
BayesOpts.ForwardModel = ForwardModels;
BayesOpts.Data = myData;
BayesOpts.Discrepancy = DiscrepancyOpts;

myBayesianAnalysis = uq_createAnalysis(BayesOpts);




uq_print(myBayesianAnalysis)

uq_display(myBayesianAnalysis)


