AKMCS does not terminate after maximum added sample reached

Dear @moustapha,

thank you for your fast reply!
With the solution you suggested, I have no more multiple models.
But unfortunately the problem with AKMCS persists.

I have to be clearer with the description of the .m file model which I called myFunction. In this function also another function is used, which creates the .inp file to be read by the FE software. This because I pass to my FE software a lognormal random field. So myFunction takes X of size d, where there are (d-1) normal Gaussian random values and another random value which follows a lognormal distribution. Then a function, say RFGenerator, takes X(1:d-1) and creates the random field. The random field is then passed to a function called, say, INPGenerator, which creates the .inp file to be read and evaluated from my FE software thanks to uq_evalModel. INPGenerator not only sets at the “right place” the values of the random field, but also sets the string <X0001> at the place where the random variable which follows a lognormal distribution (X(d)) is going to be inserted. Here how my code now looks like:

function Y = myFunction(X,myUQLinkModel)

RF = RFGenerator(X(1:d-1)); % Creates the random field
INPGenerator(RF); % Creates the file .inp
FEMresult = uq_evalModel(myUQLinkModel,X(d)); % Evaluates the .inp with the FE software
Y = f(FEMresult); % Some calculations to get the output of interest


The fact, that I create the file .inp, could cause the problem with AKMCS?

Dear @moustapha,

do you have any suggestions to solve the problem with AK-MCS described above?

Hi @Gil ,

Sorry for my late reply.
I can’t figure out the reason you have an issue here. Normally, the AK-MCS algorithm uses the computational model as black-box, so the fact that you run a FE model from within shouldn’t disturb the algorithm. Are you sure it’s AK-MCS running and not your model that is somehow stuck? Normally when running AK-MCS you have a print on the evolution of the enrichment at each iteration, something like:

AK-MCS: 1 samples added
AK-MCS: 2 samples added

Do you see that? Can you please set the MaxAdded option to 2 samples and see if the algorithm continues beyond that point? Otherwise the problem would be that the computational model is stuck somehow somewhere.



If I run AK-MCS, even with MaxAdded = 1, it runs forever. In contrast, if I run, say 5 samples, with

X = uq_getSample(5, 'LHS');
Y = uq_evalModel(myModel,X);

the iterations stop after 5, like it should be, but I get

Running Realization 1
Running Realization 1
Running Realization 1
Running Realization 1
Running Realization 1
Running Realization 1

Hi @Gil ,

I need to reproduce a similar example to yours to see if there is a bug in the algorithm we had not noticed. I will come back to you asap.

The screen print-out you get when running uq_evalModel is normal because at each run of the finite element model, only one realization is passed to the FE model. So the counter stays at 1 for each. I guess you have a loop within myFunction. This makes me notice that the function above is not vectorized. Did you make sure that only one realization is passed to myFunction ?

Hi @moustapha,

If I run AK-MCS, myFunction is called for each realization, so I guess only one realization is passed. You can find my original code here, maybe it helps you a little. What I called myFunction before has the name RFmodel.

Thank you very much for your help!

RFmodel.m (622 Bytes) RFreliability.m (1.7 KB)

Thanks for the files.

The RFReliability.m seems fine to me. However I think that there is a problem with the way RFmodel is written. The function is not vectorized and since AK_MCS evaluates the initial experimental design points in a single batch, some of the parameters passed would be erroneous. You can vectorize the code using X(:,columnnumber) instead of X(columnnumber) as now.

In any case, I modified the code and put a loop. Could you please run this version and tell me if it changes anything? Also when running AK-MCS did you have a print-out I mentionned earlier telling the number of samples added? If not, then this would mean that AK-MCS is stuck in the building an initial ED. You may also want to check that the results you got with one of the runs you had is consistent with what you would expect (both the generated input file and the result).

RFmodel.m (818 Bytes)

1 Like


thank you for your fast reply.
Unfortunately, it runs behind MaxAddedED again. I set MaxAddedED = 1, but it never begins telling the number of samples added.

And yes the files generated are consistent with the output I get.

Dear @moustapha,

my apologies, I did a mistake that caused AKMCS not to run. Here a print screen of the result and it is consistent with a MCS


Thank you again very much for your help!

1 Like

Great, glad to know it’s working now!

If you have updated to UQLab v1.4, try to have a look at the new active learning reliability module. You may be able to solve your problem more efficiently.