Hi @Imfett , welcome to UQWorld!
To add to @bsudret’s answer, there is an additional UQLab-related problem with your posted solution.
Estimating Sobol’ indices by Monte Carlo (MC) simulation requires a specific set of sample points generated from your input. The scheme to generate this sample is similar to the one illustrated in this Wikipedia entry. In UQLab, you cannot generate your sample in advance and use it compute the Sobol’ indices; that is, your precomputed X
and Y
cannot be used.
Assuming that you have created INPUT and MODEL objects named myInput
and myModel
, here’s what happens behind the scene, when you run the Sobol’ analysis:
- UQLab generates the required sample points from your INPUT object.
- UQLab evaluates your model using the generated sample points to get the outputs.
- UQLab computes the Sobol’ indices using one of the estimators given in the Sensitivity user manual Section 1.5.3.3.
By default, UQLab uses the currently selected (lastly created) INPUT and MODEL objects to do the above steps. That’s why you don’t need to specify myInput
and myModel
explicitly in SobolOpts
.
The sample size you specified in SobolOpts.Sobol.SampleSize
corresponds to the number of MC sample points used in the estimation.
Note that the total number of model evaluations to estimate the first-order and total order Sobol’ indices for each of your model parameters is N(M+2) where N is the
SampleSize
and M is the number of model parameters. More will be needed if you ask for higher-order Sobol’ indices. This number can be large, thus for expensive (to evaluate) computational model it might be a good idea to create a metamodel first (say, PCE).
Referring to your code, you should not expect by assigning Sample_X
to SobolOpts.Sobol.SampleSize
, UQLab will recognize that the inadmissible output values of your model have been filtered. This field is just to specify the number of MC sample size and in this case, the sample is less than the initial NSamples
of 1'000 due to the filtering.
Finally, I’m also curious about this bit here:
Model.mFile = 'f(x)';
myModel = uq_createModel(Model);
Y = uq_evalModel(X);
Which f(x)
are you referring to here? Is there really a MATLAB file named f(x)
or is it the variable fx
you defined inside the for loop above? If it’s the latter, then this is also problematic because you need an actual valid MATLAB function (either as m-file, function handle, or text string) to create a MODEL object. If f(x)
is an already precomputed variable, it wouldn’t make sense to evaluate it using uq_evalModel
at X.
Once again though, you should first resolve the problem conceptually as suggested by Bruno to either make your inputs independent and continue using Sobol’ indices or use alternative dependent sensitivity measures.