# Sampling strategies

**URL:** <https://uqworld.org/t/sampling-strategies/1714>\
**Category:** Community Q&A and How To\
**Created:** [September 22, 2022, 8:23am UTC](https://uqworld.org/t/sampling-strategies/1714 "2022-09-22T08:23:57Z")\
**Posts on this page:** 14\
**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:** [September 22, 2022, 8:23am UTC](https://uqworld.org/t/sampling-strategies/1714/1 "2022-09-22T08:23:58Z")

</div>

Hi,  
I am not sure I quite fully understand the sampling strategies techniques. Especially the range of x-axis and y-axis that I obtained from my model. it is not always that the sampling should be showing that the samplings are extracted from values (0 to 1) ? Below is my figure from running all 4 sampling strategies.  
 ![image](https://uqworld.org/uploads/default/original/2X/7/7c29bef3e2efa9b33f94ca7a478e5a117e3e7525.jpeg)

Thanks for your input!  
B,;  
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:** [September 22, 2022, 4:01pm UTC](https://uqworld.org/t/sampling-strategies/1714/2 "2022-09-22T16:01:52Z")

</div>

Dear @Vishashalu

Can you share the code you used to generate the figures? I assume you are already plotting the transformed input (from the unit interval to your actual distribution).

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:** [September 22, 2022, 7:43pm UTC](https://uqworld.org/t/sampling-strategies/1714/3 "2022-09-22T19:43:05Z")

</div>

```matlab
clearvars
uqlab
rng(100, 'twister')
ModelOpts.mFile = 'uq_Abs';
myModel = uq_createModel(ModelOpts);
InputOpts.Marginals(1).Name = 'dens'; 
InputOpts.Marginals(1).Type = 'Gaussian';
InputOpts.Marginals(1).Moments = [1 0.043];
InputOpts.Marginals(2).Name = 'surfT'; 
InputOpts.Marginals(2).Type = 'Gaussian';
InputOpts.Marginals(2).Moments = [1 0.025];
myInput = uq_createInput(InputOpts);

X_MC = uq_getSample(100,'MC');
uq_figure
uq_plot(X_MC(:,1), X_MC(:,2), '.', 'MarkerSize', 15)
xlabel('$\mathrm{Density}$')
ylabel('$\mathrm{Surface tension}$')
% 
X_LHS = uq_getSample(100, 'LHS');
uq_figure
uq_plot(X_LHS(:,1), X_LHS(:,2), '.', 'MarkerSize', 15)
xlabel('$\mathrm{X_1}$')
ylabel('$\mathrm{X_2}$')
% 
X_Sobol = uq_getSample(100,'Sobol');
uq_figure
uq_plot(X_Sobol(:,1), X_Sobol(:,2), '.', 'MarkerSize', 15)
xlabel('$\mathrm{X_1}$')
ylabel('$\mathrm{X_2}$')
% 
X_Halton = uq_getSample(100,'Halton');
uq_figure
uq_plot(X_Halton(:,1), X_Halton(:,2), '.', 'MarkerSize', 15)
xlabel('$\mathrm{X_1}$')
ylabel('$\mathrm{X_2}$')
uq_figure

subplot(2, 2, 1)
uq_plot(X_MC(:,1), X_MC(:,2), '.', 'MarkerSize', 15)
title('MCS')
ylabel('$\mathrm{Surface Tension}$')

subplot(2, 2, 2)
uq_plot(X_LHS(:,1), X_LHS(:,2), '.', 'MarkerSize', 15)
title('LHS')

subplot(2, 2, 3)
uq_plot(X_Sobol(:,1), X_Sobol(:,2), '.', 'MarkerSize', 15)
title('Sobol''')
xlabel('$\mathrm{Density}$')
ylabel('$\mathrm{Surface Tension}$')

subplot(2, 2, 4)
uq_plot(X_Halton(:,1), X_Halton(:,2), '.', 'MarkerSize', 15)
title('Halton')
xlabel('$\mathrm{Density}$')

```

---

<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:** [September 22, 2022, 7:44pm UTC](https://uqworld.org/t/sampling-strategies/1714/4 "2022-09-22T19:44:33Z")

</div>

Hi Styfen,  
I think there is some formatting issue here, but I hope you can understand the code on how I input for the sampling strategies?  
I will appreciate your input for this.  
BR,  
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:** [September 23, 2022, 7:51am UTC](https://uqworld.org/t/sampling-strategies/1714/5 "2022-09-23T07:51:34Z")

</div>

Dear @Vishashalu

I fixed the formatting issue.

`uq_getSample` will indeed return you the samples according to the distribution defined. You can read more about this function and related ones here:

> **[UQLab - Probabilistic input modeling user manual](https://www.uqlab.com/input-user-manual)**
>
> User manual for the probabilistic input modeling module of UQLab.

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:** [December 19, 2022, 9:59am UTC](https://uqworld.org/t/sampling-strategies/1714/6 "2022-12-19T09:59:18Z")

</div>

Hi styfen,  
With regards to the sampling strategies types in UQLab. Can you please confirm my understanding. I am a little confused. Is that when I specify to use Sobol or Halton type of sampling strategies, my input parameters must be uniform distributed to have more accurate outputs for convergence analysis. Will it be wrong if I specify gaussian distribution type for my inputs?  
Thanks!  
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:** [December 19, 2022, 3:30pm UTC](https://uqworld.org/t/sampling-strategies/1714/7 "2022-12-19T15:30:55Z")

</div>

Dear @Vishashalu

You can use all of these quasi-random sampling methods even if your distribution is not uniform. In your first post, you asked why the generated samples are not within the unit hypercube, which is what you would expect from LHS, Sobol’, and Halton. The solution to this question is that UQLab applies an isoprobabilistic transformation to the generated samples in the unit hypercube to obtain the distribution you specified (Gaussian in our case). You can therefore safely use these sampling methods to generate samples following any distribution implemented in UQLab.

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:** [December 19, 2022, 8:54pm UTC](https://uqworld.org/t/sampling-strategies/1714/8 "2022-12-19T20:54:17Z")

</div>

Hi Styfen,  
Thank you so much for clarifying my doubt about that. As I have seen in several references and papers, Sobol as LDS method always showed superior, however with my computational model, I did get the same outcome. In fact, my convergence plot for mean value doesnt shows much changes from the exact value and each sampling strategies reaches convergence relatively quickly. Is there any other statistical values besides mean value that I could check for convergence?  
Visha

---

<div class="post-metadata">

**Author:** ![giansteve](https://uqworld.org/user_avatar/uqworld.org/giansteve/32/973_2.png) [@giansteve](https://uqworld.org/u/giansteve)\
**Post date:** [December 20, 2022, 8:59am UTC](https://uqworld.org/t/sampling-strategies/1714/9 "2022-12-20T08:59:09Z")

</div>

Hi @Vishashalu,

I jump into the conversation here 🙂  
You could try to check if the variance of your output does not change for different sample sizes. I would expect your variance to no longer vary at a given sample size. That would also be the minimum sample size you need to represent your model.

As for the convergence of your mean value, is the MC as fast as the other methods? Maybe you could show them here as well if it is not too much work 😁

I hope this was helpful.

Best  
Gian

---

<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:** [December 20, 2022, 9:57am UTC](https://uqworld.org/t/sampling-strategies/1714/10 "2022-12-20T09:57:44Z")

</div>

Hi Gian,  
Yes I should have showed them here. There you go:  
 ![image](https://uqworld.org/uploads/default/original/2X/f/ffeac265ad36797a6aa6aa883b173b7ea6f26cce.png)  
This is my output for the mean. The exact value is 89.5.  
Thanks for your input.  
BR,  
Visha

---

<div class="post-metadata">

**Author:** ![giansteve](https://uqworld.org/user_avatar/uqworld.org/giansteve/32/973_2.png) [@giansteve](https://uqworld.org/u/giansteve)\
**Post date:** [December 20, 2022, 10:51am UTC](https://uqworld.org/t/sampling-strategies/1714/11 "2022-12-20T10:51:29Z")

</div>

thank you for this 🙂

although there is a very small difference, but have you analyzed the reason why your sampling never reaches exact value?

---

<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:** [December 20, 2022, 11:01am UTC](https://uqworld.org/t/sampling-strategies/1714/12 "2022-12-20T11:01:46Z")

</div>

Hi Gian,  
I am actually not sure how I should move forward with my analysis. Do you think I should try to run with much bigger sample size? I have tried multiple runs of these simulations and it always ends up with the same conclusions.  
Visha

---

<div class="post-metadata">

**Author:** ![giansteve](https://uqworld.org/user_avatar/uqworld.org/giansteve/32/973_2.png) [@giansteve](https://uqworld.org/u/giansteve)\
**Post date:** [December 20, 2022, 11:44am UTC](https://uqworld.org/t/sampling-strategies/1714/13 "2022-12-20T11:44:50Z")

</div>

Hi Visha,

After analyzing your answer better, I noticed you mentioned that the exact value is 89,5. However, in your plot, the exact value is displayed at 90,0.

After you investigate this, it would be beneficial to know your exact value. Is it computed from your model or known from the literature?  
Also, how do you compute the mean from your samples? If you use the same model for the exact mean and your sample mean, then you **must** get the same values.  
At first glance, I may think that there is some problem in the coding of your model.

Keep me updated 😁

---

<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:** [December 20, 2022, 12:38pm UTC](https://uqworld.org/t/sampling-strategies/1714/14 "2022-12-20T12:38:05Z")

</div>

Hi Gian,  
Ok I will do that…Thanks a lot for the advise. I will have to check with my deterministic output again then. I will keep you posted here later.  
Thanks.  
Visha
