I am running a lot of simulations to fit a model to randomly generated data. Sometimes the fitting converges properly sometimes it does not, but it will give you the fitting parameters anyway. I would like to know in which case the model works best by counting occasions of exceptions. The actual code is too long to put here, so I wrote a simple do loop to demonstrate the problem. I just want to know how many exceptions happened in the do loop.
nLoop = 100;
Int = RandomInteger[{0, 10}, nLoop];
reciprical = Table[0, {nLoop}];(*initialzation*)
Do[reciprical[[iR]] = 1/Int[[iR]], {iR, 1, nLoop}]
Power::infy: Infinite expression 1/0 encountered. >>
Power::infy: Infinite expression 1/0 encountered. >>
Power::infy: Infinite expression 1/0 encountered. >>
General::stop: Further output of Power::infy will be suppressed during this calculation. >>
It can bee seen that after three times of warning, the further output of warning message will be suppressed. If not suppressed, what is the actual times of occurrence of the warning message? Obviously you should not get the times by checking if the result is a real number or not. There may be different types of warning messages in different problems. I want to know how many times a warning message will occur in a loop if it is not suppressed.
Thanks a lot!
Checkto check for a particular message. – Szabolcs Oct 05 '15 at 16:29Position[Int, 0]shows you when you will be dividing by zero, andLength[Position[Int, 0]]shows how many there are. – bill s Oct 05 '15 at 16:31