0
$\begingroup$

I'm generating a series of (numerical) matrices, and testing each one for a certain property, and trying to estimate what proportion possesses that property. I write out the result at every million-th iteration. One of the calculations yielded

Orthogonalize::inf: Input matrix contains an infinite entry.

So, presumably the test could not be meaningfully performed in that case.

The program, nevertheless, continues to write out the number of results possessing the property in question at each million-th step.

Should I--to be precise--assume that rather than say, ten million, the number of matrices actually subject to the test was really "just"

9,999,999?

If additional such errors occur, will there be a record of the number of occurrences? (From another vantage point, it would seem that such errors might be reduced/eliminated by increasing the precision employed.)

$\endgroup$
3
  • 1
    $\begingroup$ I guess it would be safer to assume that the test was performed with only 9,999,999 matrices. I am not sure wether the number errors can be retrieved after the calculations have finished (maybe there is a log file somewhere where error messages are printed to). But you can set up a counter that is raised for every matrix generated and handle errors with Check so that the counter is decreased when an error occurs. $\endgroup$ Commented Jul 25, 2018 at 16:51
  • $\begingroup$ Thanks, Henrik, for bringing the command Check to my attention. I've incorporated it into my program, decreasing the counter if an error is reported, in the manner you suggested. $\endgroup$ Commented Jul 25, 2018 at 21:42
  • $\begingroup$ Internal`AddHandler might be of help. Other Q&A also show examples of usage. $\endgroup$
    – Michael E2
    Commented Jul 25, 2018 at 23:10

2 Answers 2

1
$\begingroup$

Turning a comment into an answer.

I guess it would be safer to assume that the test was performed with only 9,999,999 matrices. I am not sure whether the number errors can be retrieved after the calculations have finished (maybe there is a log file somewhere where error messages are printed to). But you can set up a counter that is raised for every matrix generated and handle errors with Check so that the counter is decreased when an error occurs.

$\endgroup$
1
  • $\begingroup$ Yes, I intend to proceed with the 9,999,999 count, unless I can go back and find the specific point (integer) at which the error occurred, and try again with increased precision (although as indicated in my first comment to the second answer it is inappropriate theoretically to just ignore the questionable iteration). In the future, I intend to record the specific value (integer) at which such errors occur. $\endgroup$ Commented Jul 26, 2018 at 4:07
1
$\begingroup$

The result of Orthogonalize in that case is simply to yield

Orthogonalize[TheInputMatrixThatCausedTheProblem]

So, what does the rest of your code do when it sees something like this instead of the usual bare matrix?

$\endgroup$
7
  • $\begingroup$ I've been using default precision in my calculations, so if the error arises I think I should try again with increased precision (and further again,...if necessary). Actually, I am implementing the quasirandom sequence procedure outlined by Martin Roberts in his answer mathematica.stackexchange.com/questions/143457/…, so each iteration is of theoretical significance, and it seems inappropriate to just pass it by for purely numerical reasons. $\endgroup$ Commented Jul 26, 2018 at 3:54
  • $\begingroup$ More specifically, in regard to the answer of John Doty, if the matrix is not successfully orthogonalized (yielding $U$), then the underlying equation (eq. (24) in arxiv.org/abs/0909.5094) is clearly invalid, and the ensuing calculation would seem meaningless. $\endgroup$ Commented Jul 26, 2018 at 4:02
  • $\begingroup$ The ensuing calculation may be meaningless, but what does it actually do with an expression with the head Orthogonalize? It might make sense to check the head in the code and do something affirmative rather than trying to guess what's happening. $\endgroup$
    – John Doty
    Commented Jul 26, 2018 at 10:36
  • $\begingroup$ How does one "check the head in the code"? My present thinking is that redoing the calculation with sufficiently increased precision should be able to address this very rare (it seems) occurrence. (I now see that there is a command "Head"--what might applying it indicate? Sorry for my relative obtuseness.) Actually, my immediate code in question is (Orthogonalize[ ArrayReshape[Take[P, {1, 16}], {4, 4}] + I ArrayReshape[Take[P, {17, 32}], {4, 4}]] + IdentityMatrix[4]).(ArrayReshape[Take[P, {33, 48}], {4, 4}] + I ArrayReshape[Take[P, {49, 64}], {4, 4}]) $\endgroup$ Commented Jul 26, 2018 at 13:14
  • $\begingroup$ But what do you do with the result of Orthogonalize? Maybe something like like this would help With[{orthM=Orthogonalize[whatever]},If[Head[Uevaluated[ortmM]]===Orthogonalize,manageFailure[],finishTheJob[orthM]]] $\endgroup$
    – John Doty
    Commented Jul 26, 2018 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.