UQWorld

Model setup: passing different parameter types into a Wrapper function

Hello UQWorld,

I feel I have a very simple question, but I must be missing something as I cannot solve my issue using the user manuals, or example codes.

I am looking to perform a Sobol’ analysis using Monte Carlo on a high-dimensional, Matlab-based model. This model is called using a Wrapper function, which has various parameter types, including lists and strings of the form:

function [answer] = runModel( list_1 , rvVector, list_2, switch)

List 1 and 2 are just for configuring the runs and are to be kept constant throughout the analysis. I have these defined above the analysis code.

The rvVector is essentially the X vector of 49 random variables, which is to change every run of the analysis. I would like this to be the INPUT object, however I am unsure how to pass the Input object as the rvVector into the wrapper function for the actual analysis. I have copied the format of my code below:

%% 1 - INITIALIZE UQLAB
clearvars
rng(100,‘twister’)
uqlab

%% 2 - COMPUTATIONAL MODEL

fid = fopen(‘list_1.txt’);
scannedText = textscan(fid,’%s’);
list_1 = scannedText{1,1};
fclose(fid);

list_2 = ’ entry 1, entry 2, entry 3 ';

switch = ‘on’;

ModelOpts.mFile = ‘runModel’;
ModelOpts.isVectorized = false;
ModelOpts.Parameters = [list_1 list_2 switch];
myModel = uq_createModel(ModelOpts);

%% 3 - PROBABILISTIC INPUT MODEL

for i = 1:49
InputOpts.Marginals(i).Type = ‘Uniform’;
InputOpts.Marginals(i).Parameters = [0 1];
end

myInput = uq_createInput(InputOpts);

%% 4 - VALIDATION OF MODEL AT SAMPLE POINTS

rvVector = uq_getSample(10,‘LHS’);

for ii = 1:size(rvVector,1);
Y = uq_evalModel(myModel,rvVector(ii,:));
end

I get an error performing the model evaluation in this last line:

Error in uq_evalModel

Any help would be greatly appreciated!

Dear hwa96,

Hard to spot the error from these code snippets and without a full error message but maybe this will help you:

As input to your function the variable input rvVector has to be followed by the parameters ModelOpts.Parameters. In your case this might look like below.
Be careful with your “switch” variable since it is also a statement in Matlab. Add e.g. a trailing underscore to avoid a naming conflict.

function [answer] = runModel(rvVector, P)
    list_1 = P(1)
    list_2 = P(2)
    switch_ = P(3)
    % Body of your function ...
end

However, there might be other errors too.
You may share your whole code and post the full error message.

Best regards,
Styfen