I am doing some numeric computations, involving FindMinimum
and FindDistributionParameters
. I think these functions have some stochastic element because the answers I get on identical input sometimes are different. In rare occasions, I get an error message indicating no convergence. If this happens, I would like to repeat the calculation from the start, and repeat until convergence. If possible, I do not want to generate any messages, since in the end I am sure it will converge.
So I am looking for a wrapper of the form:
wrap[computation[]]
where computation[]
is a complicated function involving FindMinimum
and FindDistributionParameters
that might generate messages. If messages are generated, I want wrap
to detect these messages, not print them, and simply attempt to execute computation[]
again. Repeat this until computation[]
does not generate messages, and simply return the output of computation[]
.
Update: Sometimes computation[]
seems to get stuck, taking a very long time. Is it possible to add a second argument to wrap[..., time]
, so that if computation[]
takes longer than time
to complete, it aborts, and starts running computation[]
again?
While[$MessageList =!= {}, computation[]]
? $\endgroup$