clearvars
sob_order = 3;
poly_degree = 50;
damage_degree = 10;
Title=['order',num2str(sob_order),' degree',num2str(poly_degree),' damage',num2str(damage_degree)]
diary (Title)
uqlab
FILELOCATION = fullfile('hpc/home/bz75/fracture');%E:\DUKE\res\summer\result\PE_L49P100
load(fullfile(FILELOCATION,'etas.mat'), 'eta_PE_E','eta_PE_G','eta_PE_d');

for i=1:5
    InputOpts.Marginals(i).Name = sprintf('E%d',i);
    InputOpts.Marginals(i).Type = 'Gaussian';  
    InputOpts.Marginals(i).Parameters = [0 1]; 
end
for i =6:10
    InputOpts.Marginals(i).Name = sprintf('Gc%d',i);
    InputOpts.Marginals(i).Type = 'Gaussian';  
    InputOpts.Marginals(i).Parameters = [0 1]; 
end
% Create an INPUT object based on the specified marginals:
myInput = uq_createInput(InputOpts);


% Select the sensitivity analysis module in UQLab
% and the Sobol' analysis method:
SobolOpts.Type = 'Sensitivity';
SobolOpts.Method = 'Sobol';
% Specify the maximum order of the Sobol' indices to be calculated:
SobolOpts.Sobol.Order = sob_order;


% Select the metamodeling tool in UQLab
% and the polynomial chaos expansion (PCE) type:
PCEOpts.Type = 'Metamodel';
PCEOpts.MetaType = 'PCE';
% Assign the full computational model:
PCEOpts.ExpDesign.X = [eta_PE_E eta_PE_G];
PCEOpts.ExpDesign.Y = eta_PE_d(:,1:damage_degree);
% The full model is used to generate an experimental design for the PCE. 
% Specify the maximum polynomial degree (*default*: sparse PCE):
PCEOpts.Degree = poly_degree;


myPCE = uq_createModel(PCEOpts);
uq_print(myPCE)
YPCE = uq_evalModel(myPCE,[eta_PE_E eta_PE_G]);

% to create a new analysis on the PCE model:
mySobolAnalysisPCE = uq_createAnalysis(SobolOpts);
% Retrieve the results for comparison:
mySobolResultsPCE = mySobolAnalysisPCE.Results;
uq_print(mySobolAnalysisPCE)

uq_figure
uq_plot(eta_PE_d(:,1:damage_degree), YPCE, '+')
title({['original eta\_d vs. PCE of eta\_d']
    ['order',num2str(sob_order),'degree',num2str(poly_degree),'damage',num2str(damage_degree)]
    })
xlabel('original eta\_d')
ylabel('PCE of eta\_d')
saveas(gcf,['order',num2str(sob_order),' degree',num2str(poly_degree),' damage',num2str(damage_degree),'.png'])
diary off
