# An error in training SPCE models

**URL:** <https://uqworld.org/t/an-error-in-training-spce-models/4020>\
**Category:** Community Q&A and How To\
**Tags:** pce, metamodeling\
**Created:** [February 26, 2025, 5:11am UTC](https://uqworld.org/t/an-error-in-training-spce-models/4020 "2025-02-26T05:11:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HZhang](https://uqworld.org/letter_avatar_proxy/v4/letter/h/df788c/32.png) [@HZhang](https://uqworld.org/u/HZhang)\
**Post date:** [February 26, 2025, 5:11am UTC](https://uqworld.org/t/an-error-in-training-spce-models/4020/1 "2025-02-26T05:11:38Z")

</div>

Hi everyone,

I was training SPCE models using an existing dataset and encountered the following error. The error does not always occur, most of the time, it works when I change the training set. It appears to happen after the coefficient calculation. What could be the possible causes?

```matlab
--- Calculating the stochastic polynomial chaos expansion by regression... ---
The construction of SPCE stopped at latent variable of type Gaussian with 
parameters [0.0 1.0] polynomial degree 5 and qNorm 1.00 for output variable 1
Final CV score: -1.807380e+02
--- Calculation finished! ---
Error using uq_eval_univ_basis (line 46)
Index in position 1 exceeds array bounds. Index must not exceed 4.

Error in uq_PCE_eval_unipoly (line 33)
univ_p_val = uq_eval_univ_basis(U, BasisParameters);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in uq_PCE_eval (line 84)
univ_p_val = uq_PCE_eval_unipoly(current_model, U(:,nonConstIdx));
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in uq_eval_uq_metamodel (line 10)
        [varargout{1:nargout}] = uq_PCE_eval(current_model,X);
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in uq_evalModel (line 100)
    [varargout{1:nargout}] = current_model.eval(current_model,varargin{:});
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in uq_SPCE_LatentPCECoeff (line 42)
coefZ = uq_evalModel(PCECoef,X)';
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in uq_SPCE_evalModelSampleMetrics (line 139)
        [coefZ,Zdegree] = uq_SPCE_LatentPCECoeff(mySPCE,X,oo);
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in uq_evalStochSimMetrics (line 6)
        metrics = uq_SPCE_evalModelSampleMetrics(module,X,Y,varargin);
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in uq_initialize_uq_metamodel (line 493)
        metrics=uq_evalStochSimMetrics(current_model,VSet.X,VSet.Y);
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in uq_core_module/run_initialization_script (line 201)
                            initHandle(obj);
                            ^^^^^^^^^^^^^^^^
Error in uq_core_model/add_module (line 91)
                success = this.run_initialization_script(obj);
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in uq_createModel (line 107)
eval(str);
^^^^^^^^^^

```

---

<div class="post-metadata">

**Author:** ![styfen.schaer](https://uqworld.org/user_avatar/uqworld.org/styfen.schaer/32/849_2.png) [@styfen.schaer](https://uqworld.org/u/styfen.schaer)\
**Post date:** [February 26, 2025, 6:47am UTC](https://uqworld.org/t/an-error-in-training-spce-models/4020/2 "2025-02-26T06:47:01Z")

</div>

Hi @HZhang

Can you provide us with a minimal executable example to help us diagnose the problem?

Best regards  
Styfen

---

<div class="post-metadata">

**Author:** ![HZhang](https://uqworld.org/letter_avatar_proxy/v4/letter/h/df788c/32.png) [@HZhang](https://uqworld.org/u/HZhang)\
**Post date:** [February 28, 2025, 2:23pm UTC](https://uqworld.org/t/an-error-in-training-spce-models/4020/3 "2025-02-28T14:23:22Z")

</div>

Hi @styfen.schaer ,

Please see the following links for downloading the data and script. I also noticed that the error disappears when MetaOpts.ValidationSet is not specified.

[SPCE\_data\_for\_training.mat](https://1drv.ms/u/c/9d78c8ee1d6a3017/Ea8FbtKXDVhCoBAYBYYb_QAB9qeTAO2lDFOtwLAA4TqJhw?e=wO6x9c)

[SPCE\_training\_debug.m](https://1drv.ms/u/c/9d78c8ee1d6a3017/EX6jCuwFSR1DqtZy_kPmldcBgl8Trgrjd5bPgBezSDgDag?e=j33Gj2)

Thank you very much for your help with this!

Best,

Hongzhou
