clearvars
rng(100,'twister')
uqlab
ModelOpts.mFile = 'RBDOAcademicConstraint';
ModelOpts.isVectorized = true;
myModel = uq_createModel(ModelOpts);
InputOpts.Marginals(1).Name = 'FS'; %YIELD STRESS 
InputOpts.Marginals(1).Type = 'Lognormal';
InputOpts.Marginals(1).Moments = [400 40];
InputOpts.Marginals(2).Name = 'P1';  %DEAD WEIGHT LOAD
InputOpts.Marginals(2).Type = 'Uniform';
InputOpts.Marginals(2).Moments = [500000 50000];
InputOpts.Marginals(3).Name = 'P2'; %VARIABLE LOAD
InputOpts.Marginals(3).Type = 'Gaussian';
InputOpts.Marginals(3).Moments = [650000 97500];
InputOpts.Marginals(4).Name = 'P3'; % VARIABLE LOAD
InputOpts.Marginals(4).Type = 'Gamma';
InputOpts.Marginals(4).Moments = [520000 104000];
InputOpts.Marginals(5).Name = 'FO'; % INITIAL DEFLECTION
InputOpts.Marginals(5).Type = 'Uniform';
InputOpts.Marginals(5).Moments = [30 3];
InputOpts.Marginals(6).Name = 'E'; %YOUNG MODULUS
InputOpts.Marginals(6).Type = 'Weibull';
InputOpts.Marginals(6).Moments = [21000 2100];
InputOpts.Copula.Type = 'DVine';
InputOpts.Copula.Families = {'Independent','Gumbel', 'Gumbel','Independent','Independent'};
InputOpts.Copula.Parameters = {[],1.21,1.16,[],[]};
InputOpts.Copula.Truncation = 1;
InputOpts.Copula.Rotations = [0 0 0 0 0];
InputOpts.Copula.Variables = [1 2 3 4 5 6];
InputOpts.Copula.Structure = [1 2 3 4 5 6];
myInput = uq_createInput(InputOpts);
RBDOOpts.Input.EnvVar = myInput;
RBDOOpts.Cost.mString ='(X(:,1).*X(:,2))+ (5.*X(:,3))';
RBDOOpts.LimitState.Model = myModel;
RBDOOpts.Input.DesVar(1).Name = 'B';
RBDOOpts.Input.DesVar(1).Type = 'Lognormal';
RBDOOpts.Input.DesVar(1).Std = 0.333;
RBDOOpts.Input.DesVar(2).Name = 'D';
RBDOOpts.Input.DesVar(2).Type = 'Lognormal';
RBDOOpts.Input.DesVar(2).Std = 0.5;
RBDOOpts.Input.DesVar(3).Name = 'H';
RBDOOpts.Input.DesVar(3).Type = 'Lognormal';
RBDOOpts.Input.DesVar(3).Std = 0.2;
RBDOOpts.Optim.Bounds = [200 10 100 ; 400 30 500];
RBDOOpts.Optim.StartingPoint = [200 10.5 100 ];
%RBDOOpts.SoftConstraints.mFile='RBDOCST';
RBDOOpts.TargetBeta = 3;
RBDOOpts.Optim.MaxIter = 900;
RBDOOpts.Optim.Method = 'CMAES';
RBDOOpts.Type = 'RBDO';
RBDOOpts.Method = 'Two-Level';
RBDOOpts.Reliability.Method = 'subset' ;
%RBDOOpts.Method = 'deterministic';
RBDO_PCEOpts = RBDOOpts;
RBDO_PCEOpts.Metamodel.Type = 'PCE';
PCEOpts.Degree = 2:10 ;
PCEOpts.ExpDesign.NSamples =20;
PCEOpts.ExpDesign.Sampling = 'LHS';
RBDO_PCEOpts.Metamodel.PCE = PCEOpts;
RBDO_PCEOpts.Metamodel.Enrichment.MaxAdded = 500;
%RBDO_PCEOpts.Metamodel.Enrichment.LearningFunction='U';
RBDO_PCEOpts.Metamodel.Enrichment.SampleSize=10000;
RBDO_PCEOpts.Metamodel.Enrichment.Convergence ={'stopSign','stopDf'};
RBDO_PCEOpts.Metamodel.Enrichment.ConvThreshold = 0.001;
%RBDO_PCEOpts.Metamodel.Enrichment.MaxAdded = 300;
RBDO_PCEOpts.Metamodel.Enrichment.Points = 5;
RBDO_PCEOpts.Metamodel.Enrichment.MOStrategy = 'mean';
myRBDO_PCE = uq_createAnalysis(RBDO_PCEOpts);
uq_print(myRBDO_PCE)
uq_display(myRBDO_PCE)
uq_print(myInput);
uq_display(myInput)