# Kriging metamodelling for multiple input dimensions

**URL:** <https://uqworld.org/t/kriging-metamodelling-for-multiple-input-dimensions/1331>\
**Category:** Community Q&A and How To\
**Created:** [October 5, 2021, 9:24am UTC](https://uqworld.org/t/kriging-metamodelling-for-multiple-input-dimensions/1331 "2021-10-05T09:24:58Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vishashalu](https://uqworld.org/letter_avatar_proxy/v4/letter/v/7bcc69/32.png) [@Vishashalu](https://uqworld.org/u/Vishashalu)\
**Post date:** [October 5, 2021, 9:24am UTC](https://uqworld.org/t/kriging-metamodelling-for-multiple-input-dimensions/1331/1 "2021-10-05T09:24:59Z")

</div>

Hi,  
I am looking into Kriging metamodelling especially this example provided by UQLab below:  
KRIGING METAMODELING: BRANIN-HOO FUNCTION  
Is it possible to run a model with 5 probabilistic input models instead of only 1 or 2? I have an issue as how to obtain the figures displayed using the examples. The error message appears to be only 1 and 2 dimensional X’s are supported. Is it possible to make the figures for more than 2 inputs?  
Thank you!  
Visha

---

<div class="post-metadata">

**Author:** ![damarginal](https://uqworld.org/user_avatar/uqworld.org/damarginal/32/73_2.png) [@damarginal](https://uqworld.org/u/damarginal)\
**Post date:** [October 5, 2021, 9:37am UTC](https://uqworld.org/t/kriging-metamodelling-for-multiple-input-dimensions/1331/2 "2021-10-05T09:37:34Z")

</div>

Hi @Vishashalu,

While it is always possible to evaluate a model with more inputs (if the model allows for it), UQLab only supports plotting the results of metamodeling up to 2 dimension.

Perhaps you can be more specific on what kind of plots you’d like to see for more than 2 input variables? If you, say make a sketch, what would be displayed?

---

<div class="post-metadata">

**Author:** ![Vishashalu](https://uqworld.org/letter_avatar_proxy/v4/letter/v/7bcc69/32.png) [@Vishashalu](https://uqworld.org/u/Vishashalu)\
**Post date:** [October 5, 2021, 12:18pm UTC](https://uqworld.org/t/kriging-metamodelling-for-multiple-input-dimensions/1331/3 "2021-10-05T12:18:21Z")

</div>

Hi Damar,

Actually it is about the estimation of moments using these metamodels. Because I saw in the example under Kriging for the multiple input dimension topic, the Kriging predictor mean and variance can be quickly visualized using the uq\_display function.

So once we create the metamodel using Kriging and PCE-Kriging methods and with my 5 input model, I am unsure of how to obtain these statistical moments similar to PCE model for e.g. with the subtopic example on the ( PCE METAMODELING: ESTIMATION OF STATISTICAL MOMENTS MONTE-CARLO- VS PCE-BASED ESTIMATION OF MOMENTS)

I just wanted to know how can I see what the comparison of MCS based model and the metamodels based moments looks like.

Thanks!

Best regards,  
Visha

---

<div class="post-metadata">

**Author:** ![damarginal](https://uqworld.org/user_avatar/uqworld.org/damarginal/32/73_2.png) [@damarginal](https://uqworld.org/u/damarginal)\
**Post date:** [October 6, 2021, 7:57am UTC](https://uqworld.org/t/kriging-metamodelling-for-multiple-input-dimensions/1331/4 "2021-10-06T07:57:35Z")

</div>

For PCE metamodels, the first and second moment can be directly obtain from the coefficients, as you seen in the example you mentioned. However, for Kriging and PC-Kriging, you basically need to do Monte Carlo simulation but by using the metamodel instead of the full computational model. That is: generate (input) sample points, evaluate the metamodel, and then compute the mean and standard deviation (or variance) from the outputs.

Assuming you have created a Kriging metamodel stored in `myKriging`, then:

```matlab
% Get a sample from the probabilistic input model
X_ED = uq_getSample(1e4,'LHS');

% Evaluate the metamodel on the current experimental design
Y_Krg = uq_evalModel(myKriging,X_ED);

% Calculate the moments
mean_Krg = mean(Y_Krg);
std_Krg = std(Y_Krg, 0, 1);

```

Note that the sample size to estimate the moments can be much larger (say, \sim 10^4) than the sample size to create the metamodel (say \sim 10^2). You can also plot the histogram of the metamodel prediction to see how the values distributed.

In the example [PCE METAMODELING: ESTIMATION OF STATISTICAL MOMENTS](https://www.uqlab.com/pce-simply-supported-beam), the moments are directly taken from the coefficients of the PCE metamodels created by increasing sample sizes.

In that example, the convergence plot that comes after is custom made (i.e., not via `uq_display`), you can create the same for Kriging or PCK by replacing relevant code sections with the above procedure.

I hope this helps!

---

<div class="post-metadata">

**Author:** ![Vishashalu](https://uqworld.org/letter_avatar_proxy/v4/letter/v/7bcc69/32.png) [@Vishashalu](https://uqworld.org/u/Vishashalu)\
**Post date:** [October 6, 2021, 12:18pm UTC](https://uqworld.org/t/kriging-metamodelling-for-multiple-input-dimensions/1331/5 "2021-10-06T12:18:38Z")

</div>

Hi Damar,

This answers my questions. Thank you so much for your inputs!  
Because in my mind the metamodel helps to not burden computational cost for computing the statistical moments such as PCE which can be directly computed. So based on what you are saying here the Kriging and PCE kriging are not like that. It is because I have an issue with vectorizing my complex model, I do not where it went wrong, so having to evaluate the model for large sample size is going to be a huge computational cost. I will have to check again.  
Thank you very much for your help!  
Best regards,  
Visha

---

<div class="post-metadata">

**Author:** ![damarginal](https://uqworld.org/user_avatar/uqworld.org/damarginal/32/73_2.png) [@damarginal](https://uqworld.org/u/damarginal)\
**Post date:** [October 6, 2021, 1:26pm UTC](https://uqworld.org/t/kriging-metamodelling-for-multiple-input-dimensions/1331/6 "2021-10-06T13:26:24Z")

</div>

Yes, PCE metamodels do have nice properties regarding moment estimation (among other things). However, once you have a Kriging or PC-Kriging metamodel the computational cost to compute a large number of sample points from the metamodel should be minor compared to running the full computational model (assuming your complex model is non-trivial to run). Furthermore, I think the evaluation of all metamodels in UQLab is vectorized.

---

<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:** [October 7, 2021, 9:17am UTC](https://uqworld.org/t/kriging-metamodelling-for-multiple-input-dimensions/1331/7 "2021-10-07T09:17:05Z")

</div>

Dear Visha

As Damar said, UQLab evaluates the metamodel in a vectorized way. However, there may be rare cases where the best way to evaluate the metamodel is not obvious. For example, see this post:

> [@Vectorized mfile-based model with an if statement](https://uqworld.org/t/vectorized-mfile-based-model-with-an-if-statement/1199):
>
> Dear UQLab Community I have a mfile-based model with this if statement that needs to be true so I can evaluate a performance function according to different metamodel previously established. It is my understanding that the mfile is vectorized, improving the performance of the code by several orders of magnitude, since it allows the evaluation of N different realizations in a single call. Nevertheless, I notice that the if statement that I am using the mfile is never true, but it should be for…

If you explain you computational model in more detail, I can hopefully say more about that.

Best regards  
Styfen

---

<div class="post-metadata">

**Author:** ![RobertoUNITN](https://uqworld.org/letter_avatar_proxy/v4/letter/r/8edcca/32.png) [@RobertoUNITN](https://uqworld.org/u/RobertoUNITN)\
**Post date:** [October 7, 2021, 8:30pm UTC](https://uqworld.org/t/kriging-metamodelling-for-multiple-input-dimensions/1331/8 "2021-10-07T20:30:21Z")

</div>

Hi all

I am Roberto from University of Trento. I am new to UQworld.

Regarding this discussion, the BraninHoo function provides the nice plots of mean and variance of the Gaussian process, that I’m attaching. The dimension of the input here is 2 so clearly such plot representation is possible, but it wouldn’t be for higher dimensions.

![mu_sigmaSQ](https://uqworld.org/uploads/default/original/1X/c48553cb8eaa0559bfe20536f886e57159b29385.jpeg)

My question is how to obtain the same information for dimension of the input higher than 2 (e.g. my case is with 3)?

Thank you in advance  
Roberto

---

<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:** [October 8, 2021, 8:08am UTC](https://uqworld.org/t/kriging-metamodelling-for-multiple-input-dimensions/1331/9 "2021-10-08T08:08:16Z")

</div>

Dear Roberto

You can obtain the mean and variance of your Kriging model at any point x as follows:

```matlab
[Ymu,Yvar] = uq_evalModel(x)

```

Best regards  
Styfen

---

<div class="post-metadata">

**Author:** ![RobertoUNITN](https://uqworld.org/letter_avatar_proxy/v4/letter/r/8edcca/32.png) [@RobertoUNITN](https://uqworld.org/u/RobertoUNITN)\
**Post date:** [October 8, 2021, 6:57pm UTC](https://uqworld.org/t/kriging-metamodelling-for-multiple-input-dimensions/1331/10 "2021-10-08T18:57:24Z")

</div>

Dear Styfen

Thank you so much. That’s what I needed.

Roberto

---

<div class="post-metadata">

**Author:** ![Vishashalu](https://uqworld.org/letter_avatar_proxy/v4/letter/v/7bcc69/32.png) [@Vishashalu](https://uqworld.org/u/Vishashalu)\
**Post date:** [October 28, 2021, 12:01pm UTC](https://uqworld.org/t/kriging-metamodelling-for-multiple-input-dimensions/1331/11 "2021-10-28T12:01:46Z")

</div>

Hi Damar,  
Yes indeed when I ran the metamodel to obtain the statistical moments, I got the solutions quite quick. I am wondering about the convergence plot you mentioned. Can you show me how you can implement it for Kriging for e.g. once you have found the metamodel. I tried following the methods from [PCE METAMODELING: ESTIMATION OF STATISTICAL MOMENTS](https://www.uqlab.com/pce-simply-supported-beam), however it did not work.  
Thank you for your help!  
Visha

---

<div class="post-metadata">

**Author:** ![Vishashalu](https://uqworld.org/letter_avatar_proxy/v4/letter/v/7bcc69/32.png) [@Vishashalu](https://uqworld.org/u/Vishashalu)\
**Post date:** [October 29, 2021, 8:40am UTC](https://uqworld.org/t/kriging-metamodelling-for-multiple-input-dimensions/1331/12 "2021-10-29T08:40:53Z")

</div>

Hi styfen,  
My computational model is using orthogonal collocation method to solve boundary conditions problem where I need to choose no. of colloc points and fsolve to solve system of nonlinear equations to get the output. I failed to vectorized the inputs for the simple model (few uncertain inputs) and bit more complex model where it has more uncertain inputs. I did exactly following the examples shown to vectorized the inputs and I am not what went wrong.  
Perhaps I can share you the error message here. It is definitely MATLAB problem not the UQLab I am sure.  
Best regards,  
Visha

---

<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:** [November 1, 2021, 1:47pm UTC](https://uqworld.org/t/kriging-metamodelling-for-multiple-input-dimensions/1331/13 "2021-11-01T13:47:51Z")

</div>

Dear Visha

Regarding your first problem: The example you linked is for PCE. For PCE, you can derive the mean and variance analytically from the coefficients. For Kriging, this is not possible. You would need to evaluate your model on a fairly large number of points to get the global mean and variance. Essentially, you are performing an MC analysis on your surrogate. Note that I write “global” because this is not to be confused with the mean and variance that Roberto asked about.

As for your second problem, can you either provide us with your error message or, if possible, your code so that we can reproduce the error.

Best regards  
Styfen

---

<div class="post-metadata">

**Author:** ![Vishashalu](https://uqworld.org/letter_avatar_proxy/v4/letter/v/7bcc69/32.png) [@Vishashalu](https://uqworld.org/u/Vishashalu)\
**Post date:** [November 1, 2021, 2:06pm UTC](https://uqworld.org/t/kriging-metamodelling-for-multiple-input-dimensions/1331/14 "2021-11-01T14:06:42Z")

</div>

Hi Styfen,  
Yes I understood from Damar’s explanation regarding obtaining the statistical moments from the Kriging method. I ran MC analysis on the surrogate with 10e3 samples and I got the global mean and variance pretty quickly. I hope I did it correctly though 🙂 Damar further explained that the convergence plot that comes after showed for the PCE metamodel following the link example can be created for Kriging or PCK by replacing relevant code sections. So I wanted to find the similar convergence plot for Kriging first but not successful. Hence the confusion.

As for my 2nd issue, I will provide you the error message once I am done as soon.

Best regards,  
Visha

---

<div class="post-metadata">

**Author:** ![Vishashalu](https://uqworld.org/letter_avatar_proxy/v4/letter/v/7bcc69/32.png) [@Vishashalu](https://uqworld.org/u/Vishashalu)\
**Post date:** [November 1, 2021, 2:07pm UTC](https://uqworld.org/t/kriging-metamodelling-for-multiple-input-dimensions/1331/15 "2021-11-01T14:07:08Z")

</div>

Hi again,  
Thanks for your help by the way and taking your time!  
Visha

---

<div class="post-metadata">

**Author:** ![Vishashalu](https://uqworld.org/letter_avatar_proxy/v4/letter/v/7bcc69/32.png) [@Vishashalu](https://uqworld.org/u/Vishashalu)\
**Post date:** [November 2, 2021, 1:14pm UTC](https://uqworld.org/t/kriging-metamodelling-for-multiple-input-dimensions/1331/16 "2021-11-02T13:14:17Z")

</div>

Hi Styfen,

I ran the complex model that I was talking about, it was really slow to run even with PCE metamodel method with sample design of 200. Once completed, I received the following error message:

Incorrect dimensions for matrix multiplication. Check that the number of columns  
in the first matrix matches the number of rows in the second matrix. To perform  
elementwise multiplication, use '._’.  
Error in uq\_lar (line 231)  
cj = Psi’_(Y - mu);  
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 362)  
success = uq\_calculateMetamodel(current\_model);

I am not sure where is the problem to be exact.

Thanks,  
Visha
