Pass a UQLink model to a .m file model

Hello everyone,

I defined a computational model through a .m file function. The function takes the random input X and gives the output Y. In the .m file, I define a UQLink model (which links UQLab to a FEM software) and I use the result of the FEM analysis (the FEM result is extracted thanks to a parser and is a scalar) as input for another computation which is implemented in the .m file. So the output Y is dependent on my FEM result and from other computations performed in the .m file. The problem is, that a new UQLink model is created each time the .m file function is called (at the end of the analysis I have in the folder many .mat files and .zip files called Model1, Model2, …, ModelN). Is there a way, to define the UQLink model outside the .m function and pass it, so that I only have to keep in the .m file the line which starts the FEM analysis? Something like:

function Y = myFunction(X,myUQLinkModel)
...
FEMresult = uq_evalModel(myUQLinkModel,X)
Y = f(FEMresult)
end

Another problem I have, is that if I perform an AKMCS, even if I limit the max added samples, say MaxAdded = 30, it runs forever and doesn’t stop. But I don’t know if it is related with the problem of having a new UQLink model each time the function Y is called.

Thank you!

Hi @Gil

You can do what you suggested by passing the UQLink model as parameter of your myFunction model. Basically it would go like:

Mopts.mFile = 'myFunction';
Mopts.Parameters = myUQLinkModel ;
myModel = uq_createModel(Mopts);

Then you can define your model exactly as you have suggested:

function Y = myFunction(X,myUQLinkModel)
...
FEMresult = uq_evalModel(myUQLinkModel,X)
Y = f(FEMresult)
end

The UQLink model is defined in the main configuration file of your analysis, prior to defining myModel.

I think with this change you shouldn’t anymore have multiple models defined.

Generally speaking, also remember that when you have to build a model repetitively in UQLab (which is not the case for your problem here), you can use the options ’-private' as in

myModel = uq_createModel(Mopts,'-private');

to avoid saving in memory intermediate models that were built throughout the analysis.

For UQLink, you can also use the .Archiving option to clear the files created during the FE analysis.

Regarding the AK-MCS issue, that is a bit weird and I can’t reproduce the error from my side. Could you please try again with the updates above and let me know if you still have the same issue?

Cheers,
Moustapha

1 Like

10 posts were split to a new topic: AKMCS does not terminate after maximum added sample reached