Hi all,
I’ve been doing some very simple tests on using PCE on a 1D sine function.
To my surprise, if I take only 2 or 3 samples, the PCE approximation does not result in a first order or second order polynomial. Below is a MWE:
rng default;
%% model definition
Model.mString = 'sin(2*pi*X(:,1))';
myModel = uq_createModel(Model);
% list with number of samples to test
Samples_list = 2:4;
Nrun = length(Samples_list);
error_LOO = zeros(Nrun,1);
% loop over samples
for k=1:Nrun
%% input
mu = 0.;
sigma = 0.25;
Input.Marginals(1).Type = 'Uniform';
Input.Marginals(1).Parameters = [mu-2*sigma, mu+2*sigma];
Input.Marginals(1).Bounds = [mu-2*sigma, mu+2*sigma];
myInput = uq_createInput(Input);
%% LARS
metamodelLARS.FullModel = myModel;
metamodelLARS.Input = myInput;
metamodelLARS.Type = 'Metamodel';
metamodelLARS.MetaType = 'PCE';
metamodelLARS.Method = 'LARS';
metamodelLARS.Degree = 1:8; % this automatically switches on degree adaptive PCE
metamodelLARS.TruncOptions.qNorm = 0.5:0.1:1.5;
metamodelLARS.ExpDesign.Sampling = 'LHS'; % or 'LHS' or 'Sobol' or 'Halton'
metamodelLARS.ExpDesign.NSamples = Samples_list(k);
myPCE_LARS = uq_createModel(metamodelLARS);
%% plot results
Xsamples = myPCE_LARS.ExpDesign.X;
Ysamples = myPCE_LARS.ExpDesign.Y;
% evaluate the PCE model at many points
X_PCE = linspace(Input.Marginals(1).Bounds(1),Input.Marginals(1).Bounds(2),100)';
Y_PCE = uq_evalModel(myPCE_LARS,X_PCE);
figure
plot(Xsamples(:,1),Ysamples,'o');
hold on
plot(X_PCE(:,1),Y_PCE);
end
- For 2 samples, I get as a solution a constant zero solution, whereas I would have expected a linear fit between the two data points. Another surprise is that I get myPCE_LARS.PCE.Basis.Degree to equal 1, while the basis coefficients are identically 0. I would think that’s a zero degree polynomial, given that the first (zeroth order) Legendre basis function is 1?
- For 3 samples, a similar thing happens. I get a constant (non-zero) solution, whereas I would have expected a linear or quadratic fit between the three data points. Again, UQlab tells that the Degree is equal to 1, while only the first basis coefficient is nonzero.
- For 4 samples things get much better, and I get as expected a third order polynomial with a nice fit.
So in summary I have two questions:
- why does PCE on 2 or 3 samples not result in linear or quadratic approximations? is this because LARS is favouring low rank solutions, which are in this case a bit ‘too low’?
- why does UQLab indicate that constant functions have degree 1?
I’m probably overlooking something since this is quite basic material. But any help would be appreciated.
Thanks!
Benjamin