%% RELIABILITY: RESISTANCE VS. STRESS (R-S)
%

%% 1 - INITIALIZE UQLAB
%
clearvars
rng(100,'twister')
uqlab

%% 2 - COMPUTATIONAL MODEL
%
ModelOpts.mFile = 'uq_OvertoppingFailure2';
myModel = uq_createModel(ModelOpts);

%% 3 - PROBABILISTIC INPUT MODEL
%
  
  InputOpts.Marginals(1).Name = 'Hs' ; %X1
  InputOpts.Marginals(1).Type = 'Lognormal';
  InputOpts.Marginals(1).Parameters = [-0.0932 0.4552];
  
  InputOpts.Marginals(2).Name = 'Tp'; %X2
  InputOpts.Marginals(2).Type = 'Lognormal';
  InputOpts.Marginals(2).Parameters = [1.9543 0.2107];
 
  InputOpts.Marginals(3).Name = 'WL'; %X3
  InputOpts.Marginals(3).Type = 'Gaussian';
  InputOpts.Marginals(3).Parameters = [1.6127 0.6474];
  
%%
% Create an INPUT object based on the specified marginals:
myInput = uq_createInput(InputOpts);

%% 4 - RELIABILITY ANALYSIS
%

%% 4.1 Monte Carlo simulation (MCS)
%
% Select the Reliability module and the Monte Carlo simulation (MCS)
% method:
MCSOpts.Type = 'Reliability';
MCSOpts.Method = 'MCS';

%%
% Specify the maximum sample size:
MCSOpts.Simulation.MaxSampleSize = 1e6;

%%
% Run reliability analysis with MCS:
MCSAnalysis = uq_createAnalysis(MCSOpts);

%%
% Print out a report of the results:
uq_print(MCSAnalysis)

%%
% Create a graphical representation of the results:
uq_display(MCSAnalysis)

%% 4.2 FORM
%
% Select FORM as the reliability analysis method:
FORMOpts.Type = 'Reliability';
FORMOpts.Method = 'FORM';

%%
% Run the FORM analysis:
FORMAnalysis = uq_createAnalysis(FORMOpts);

%%
% Print out a report of the results:
uq_print(FORMAnalysis)

%%
% Create a graphical representation of the results:
uq_display(FORMAnalysis)

%% 4.3 Importance sampling (IS)
%
% Select importance sampling (IS) as the reliability analysis method:
ISOpts.Type = 'Reliability';
ISOpts.Method = 'IS';

%%
% Specify the sample size and the target coefficient of variation (CoV):
ISOpts.Simulation.BatchSize = 1e4;
ISOpts.Simulation.MaxSampleSize = 1e6;
ISOpts.Simulation.TargetCoV = 1e-2;

%%
% Save the evaluations:
ISOpts.SaveEvaluations = 1;

%%
% Run the IS reliability analysis:
ISAnalysis = uq_createAnalysis(ISOpts);

%%
% Print out a report of the results:
uq_print(ISAnalysis)

%%
% Create a graphical representation of the results:
uq_display(ISAnalysis)
