# Issues while building PCE surrogate

**URL:** <https://uqworld.org/t/issues-while-building-pce-surrogate/1095>\
**Category:** Community Q&A and How To\
**Tags:** pce, metamodeling\
**Created:** [March 22, 2021, 11:42am UTC](https://uqworld.org/t/issues-while-building-pce-surrogate/1095 "2021-03-22T11:42:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![geofflo](https://uqworld.org/letter_avatar_proxy/v4/letter/g/8797f3/32.png) [@geofflo](https://uqworld.org/u/geofflo)\
**Post date:** [March 22, 2021, 11:42am UTC](https://uqworld.org/t/issues-while-building-pce-surrogate/1095/1 "2021-03-22T11:42:26Z")

</div>

Hello UQLab community,

I want to use PCE surrogate for the sensitivity analysis … But I’m having a problem while computing PCE coefficeints for my Y1 (or Y2) outputs.  
Is there any way to help me figure out why this is not working (see report below)?

Thanks in advance,

— Calculating the PCE coefficients by regression. —  
NaN’s cannot be converted to logicals.

Error in uq\_PCE\_loo\_error (line 52)  
if ~varY % if the data has 0 variance, set the errors to 0

Error in uq\_PCE\_OLS\_regression (line 49)  
[LOO, normEmpErr, optErrorParams] = uq\_PCE\_loo\_error(Psi, M, Y, results.coefficients,  
modified\_loo);

Error in uq\_lar (line 215)  
ols\_results = uq\_PCE\_OLS\_regression(ones(size(Y,1),1), Y, olsoptions);

Error in uq\_PCE\_lars (line 64)  
lar\_results = uq\_lar(Psi, Y, lar\_options);

Error in uq\_PCE\_calculate\_coefficients\_regression (line 197)  
lars\_results = uq\_PCE\_lars(univ\_p\_val, current\_model);

Error in uq\_PCE\_calculate\_coefficients (line 47)  
uq\_PCE\_calculate\_coefficients\_regression(current\_model);

Error in uq\_calculateMetamodel (line 18)  
success = uq\_PCE\_calculate\_coefficients(current\_model);

Error in uq\_initialize\_uq\_metamodel (line 358)  
success = uq\_calculateMetamodel(current\_model);

---

<div class="post-metadata">

**Author:** ![bsudret](https://uqworld.org/user_avatar/uqworld.org/bsudret/32/224_2.png) [@bsudret](https://uqworld.org/u/bsudret)\
**Post date:** [March 22, 2021, 1:31pm UTC](https://uqworld.org/t/issues-while-building-pce-surrogate/1095/2 "2021-03-22T13:31:00Z")

</div>

@geofflo

It looks like your data is corrupted, possibly with some NaNs.  
You could plot a scatterplot of your input /output matrix `[X Y]` using Matlab `plotmatrix` command (use a Monte Carlo sample to do this, or your data if you pre-computed it) and see if there is nothing obviously wrong.  
Best regards

---

<div class="post-metadata">

**Author:** ![geofflo](https://uqworld.org/letter_avatar_proxy/v4/letter/g/8797f3/32.png) [@geofflo](https://uqworld.org/u/geofflo)\
**Post date:** [March 22, 2021, 2:03pm UTC](https://uqworld.org/t/issues-while-building-pce-surrogate/1095/3 "2021-03-22T14:03:04Z")

</div>

@bsudret

I used pre-computed data in order to build my PCE surrogate for a wide rande of frequencies (frequential behavior).  
By plotting the input/output matrix for the first point in the frequential range, I don’t encouter any issue (see attachement).

Thank you for you feedback, ![Input_output_Matrix_data](https://uqworld.org/uploads/default/original/1X/b1c43e000e64d0f0d31a72f7a595484309904db2.png)

---

<div class="post-metadata">

**Author:** ![bsudret](https://uqworld.org/user_avatar/uqworld.org/bsudret/32/224_2.png) [@bsudret](https://uqworld.org/u/bsudret)\
**Post date:** [March 22, 2021, 2:08pm UTC](https://uqworld.org/t/issues-while-building-pce-surrogate/1095/4 "2021-03-22T14:08:42Z")

</div>

@geofflo

Your input X1 looks as a constant, meaning zero variance (thus the error).  
It should not be used as input of your PCE construction, or you should declare it as a constant in your `INPUT` object. Did you check that your `INPUT` marginals as declared in UQLab are consistent with the data plotted above?  
Best regards

---

<div class="post-metadata">

**Author:** ![geofflo](https://uqworld.org/letter_avatar_proxy/v4/letter/g/8797f3/32.png) [@geofflo](https://uqworld.org/u/geofflo)\
**Post date:** [March 22, 2021, 2:17pm UTC](https://uqworld.org/t/issues-while-building-pce-surrogate/1095/5 "2021-03-22T14:17:11Z")

</div>

@bsudret

Even though I discard X1 component of my input, I meet the same report of error.  
I asked to UQLab to detect the marginals for my input data: " Input.Marginals(ll).Type = ‘auto’;  
Input.Marginals(ll).Inference.Data = ExpDes\_X(:,ll); "

Input object name: Input 1  
Dimension(M): 6

Marginals:

## Index | Name | Type | Parameters | Moments

1 | X1 | Gaussian | 9.017e-04, 2.302e-05 | 9.017e-04, 2.302e-05  
2 | X2 | Gaussian | 7.958e+05, 6.628e-03 | 7.958e+05, 6.628e-03  
3 | X3 | Gaussian | 2.892e+03, 1.794e+01 | 2.892e+03, 1.794e+01  
4 | X4 | Uniform | 2.249e+02, 2.500e+02 | 2.375e+02, 7.232e+00  
5 | X5 | Uniform | 5.483e-03, 6.094e-03 | 5.789e-03, 1.763e-04  
6 | X6 | Uniform | 1.114e-09, 1.257e-09 | 1.185e-09, 4.138e-11

Thanks in advance,  
 ![Input_output_Matrix_data2](https://uqworld.org/uploads/default/original/1X/cf4d3bd4bd49cd9ff76c6e6a441f39cb1ae788a6.png)

---

<div class="post-metadata">

**Author:** ![xujia](https://uqworld.org/user_avatar/uqworld.org/xujia/32/214_2.png) [@xujia](https://uqworld.org/u/xujia)\
**Post date:** [March 22, 2021, 6:08pm UTC](https://uqworld.org/t/issues-while-building-pce-surrogate/1095/6 "2021-03-22T18:08:05Z")

</div>

Hi @geofflo,

Thanks for creating the post. I think the problem is not related to UQLab but due to the data. As @bsudret mentioned in the previous reply, please double check the model input/output which should contain NaNs.

P.S. You can also upload your code on UQWorld, which will help us better support you.

Best regards

---

<div class="post-metadata">

**Author:** ![geofflo](https://uqworld.org/letter_avatar_proxy/v4/letter/g/8797f3/32.png) [@geofflo](https://uqworld.org/u/geofflo)\
**Post date:** [March 23, 2021, 11:21am UTC](https://uqworld.org/t/issues-while-building-pce-surrogate/1095/7 "2021-03-23T11:21:25Z")

</div>

Hello @xujia ,

As you mentionned, I find some NaNs in my model output, specifically all 228th elements of the output structure. After fixing theses elements, I succeeded to compute the PCE coefficients. But there are still some warnings (see below) in the UQLab report. Is it normal to receive those warnings?

Thank you in advance for your feedback,

— Calculating the PCE coefficients by regression. —  
Warning: Warning: numerical instability!! Gamma for LAR iteration 30 was set to 0 to  
prevent crashes.

> In uq\_lar (line 301)  
> In uq\_PCE\_lars (line 64)  
> In uq\_PCE\_calculate\_coefficients\_regression (line 197)  
> In uq\_PCE\_calculate\_coefficients (line 47)  
> In uq\_calculateMetamodel (line 18)  
> In uq\_initialize\_uq\_metamodel (line 358)  
> In uq\_core\_module/run\_initialization\_script (line 221)  
> In uq\_core\_model/add\_module (line 100)  
> In uq\_createModel (line 91)  
> Warning: Warning: numerical instability!! Gamma for LAR iteration 102 was set to 0 to  
> prevent crashes.  
> In uq\_lar (line 301)  
> In uq\_PCE\_lars (line 64)  
> In uq\_PCE\_calculate\_coefficients\_regression (line 197)  
> In uq\_PCE\_calculate\_coefficients (line 47)  
> In uq\_calculateMetamodel (line 18)  
> In uq\_initialize\_uq\_metamodel (line 358)  
> In uq\_core\_module/run\_initialization\_script (line 221)  
> In uq\_core\_model/add\_module (line 100)  
> In uq\_createModel (line 91)  
> Warning: Warning: numerical instability!! Gamma for LAR iteration 103 was set to 0 to  
> prevent crashes.  
> In uq\_lar (line 301)  
> In uq\_PCE\_lars (line 64)  
> In uq\_PCE\_calculate\_coefficients\_regression (line 197)  
> In uq\_PCE\_calculate\_coefficients (line 47)  
> In uq\_calculateMetamodel (line 18)  
> In uq\_initialize\_uq\_metamodel (line 358)  
> In uq\_core\_module/run\_initialization\_script (line 221)  
> In uq\_core\_model/add\_module (line 100)  
> In uq\_createModel (line 91)  
> Warning: Warning: numerical instability!! Gamma for LAR iteration 114 was set to 0 to  
> prevent crashes.  
> In uq\_lar (line 301)  
> In uq\_PCE\_lars (line 64)  
> In uq\_PCE\_calculate\_coefficients\_regression (line 197)  
> In uq\_PCE\_calculate\_coefficients (line 47)  
> In uq\_calculateMetamodel (line 18)  
> In uq\_initialize\_uq\_metamodel (line 358)  
> In uq\_core\_module/run\_initialization\_script (line 221)  
> In uq\_core\_model/add\_module (line 100)  
> In uq\_createModel (line 91)  
> Warning: Warning: numerical instability!! Gamma for LAR iteration 118 was set to 0 to  
> prevent crashes.  
> In uq\_lar (line 301)  
> In uq\_PCE\_lars (line 64)  
> In uq\_PCE\_calculate\_coefficients\_regression (line 197)  
> In uq\_PCE\_calculate\_coefficients (line 47)  
> In uq\_calculateMetamodel (line 18)  
> In uq\_initialize\_uq\_metamodel (line 358)  
> In uq\_core\_module/run\_initialization\_script (line 221)  
> In uq\_core\_model/add\_module (line 100)  
> In uq\_createModel (line 91)  
> Warning: Warning: numerical instability!! Gamma for LAR iteration 119 was set to 0 to  
> prevent crashes.  
> In uq\_lar (line 301)  
> In uq\_PCE\_lars (line 64)  
> In uq\_PCE\_calculate\_coefficients\_regression (line 197)  
> In uq\_PCE\_calculate\_coefficients (line 47)  
> In uq\_calculateMetamodel (line 18)  
> In uq\_initialize\_uq\_metamodel (line 358)  
> In uq\_core\_module/run\_initialization\_script (line 221)  
> In uq\_core\_model/add\_module (line 100)  
> In uq\_createModel (line 91)

Below, is the code used for the quantification of uncertainties:

uqlab  
Nfreq = 50;  
PCE\_Resi = cell(Nfreq,1); PCE\_Indu = cell(Nfreq,1);  
PCESobolAnalysis = cell(Nfreq,1); % structure for PCE models along frequency  
for ii = 1:Nfreq  
ExpDes\_X = [(Re\_Zskin{ii})’ (Im\_Zskin{ii})’ (Re\_Nuprox{ii})’ (Im\_Nuprox{ii})’ (Re\_Mucore{ii})’ (Im\_Mucore{ii})’ (Sigma\_core{ii})‘];  
ExpDes\_Y1 = (Resi2{ii})’; ExpDes\_Y2 = (Indu2{ii})';

```
Input = struct;
Input_dim = size(ExpDes_X,2);
for ll = 1:Input_dim
    Input.Marginals(ll).Type = 'auto';
    Input.Marginals(ll).Inference.Data = ExpDes_X(:,ll);
end
myInput = uq_createInput(Input);
uq_print(myInput);

MetaOpts.Type = 'Metamodel';
MetaOpts.MetaType = 'PCE';
MetaOpts.ExpDesign.X = ExpDes_X;
MetaOpts.ExpDesign.Y = ExpDes_Y1;
MetaOpts.Degree = 2:15;
myPCE_Arb = uq_createModel(MetaOpts);
PCE_Resi{ii} = myPCE_Arb;

% Sensitivity analysis thanks to PCE surrogate
PCESobol.Type = 'Sensitivity';
PCESobol.Method = 'Sobol';
PCESobol.Sobol.Order = 2;
PCESobolAnalysis{ii} = uq_createAnalysis(PCESobol);

```

end

---

<div class="post-metadata">

**Author:** ![xujia](https://uqworld.org/user_avatar/uqworld.org/xujia/32/214_2.png) [@xujia](https://uqworld.org/u/xujia)\
**Post date:** [March 23, 2021, 4:01pm UTC](https://uqworld.org/t/issues-while-building-pce-surrogate/1095/8 "2021-03-23T16:01:09Z")

</div>

Dear @geofflo,

Thanks for the feedback. This warning is emitted when there is some numerical instability (usually due to the experimental design) in the LARS iteration. Nevertheless, it does not indicate that the surrogate model is not accurate. To assess the quality of the surrogate model, you check the leave-one-out error (please see [this post](https://uqworld.org/t/acceptable-loo-error/681/2) and the [PCE manual](https://uqftp.ethz.ch/uqlab_doc_pdf/1.4.0/UserManual_PolynomialChaos.pdf) for more details).

---

<div class="post-metadata">

**Author:** ![geofflo](https://uqworld.org/letter_avatar_proxy/v4/letter/g/8797f3/32.png) [@geofflo](https://uqworld.org/u/geofflo)\
**Post date:** [April 8, 2021, 8:30am UTC](https://uqworld.org/t/issues-while-building-pce-surrogate/1095/9 "2021-04-08T08:30:31Z")

</div>

Hello UQLab world,

After solving my PCE construction problem, I computed the Sobol indices from the PCE surrogate over a wide range of frequencies.

Here are the evolutions (see below) of the total Sobol indices from the sensitivity analysis of the 7 inputs (X1, X2, X3, X4, X5, X6, X7) on the two outputs (Resi and Indu). But I am confused when I want to interpret the influences of X5 and X6 as they oscillate and intertwine with each other throughout the frequency.

Have you ever gotten that kind of evolution? If so, how did you interpret such evolution? Or am I visualizing something else instead of what needs to be presented (total Sobol indices instead of the first order indices)?

![MCSH895_Sobol_indices_Resi](https://uqworld.org/uploads/default/original/1X/f0b63d829cac0bbbd41966462e5582ecf2627b70.png)
