0

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.)

Paul B. Slater
  • 2,335
  • 10
  • 16
  • 1
    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. – Henrik Schumacher Jul 25 '18 at 16:51
  • 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. – Paul B. Slater Jul 25 '18 at 21:42
  • [Internal`AddHandler](https://mathematica.stackexchange.com/questions/20367/how-to-catch-complete-error-message-information-including-the-message-text-as-i) might be of help. Other Q&A also show examples of usage. – Michael E2 Jul 25 '18 at 23:10

2 Answers2

1

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.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
Henrik Schumacher
  • 106,770
  • 7
  • 179
  • 309
  • 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. – Paul B. Slater Jul 26 '18 at 04:07
1

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?

John Doty
  • 13,712
  • 1
  • 22
  • 42
  • 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 https://mathematica.stackexchange.com/questions/143457/how-can-one-generate-an-open-ended-sequence-of-low-discrepancy-points-in-3d, so each iteration is of theoretical significance, and it seems inappropriate to just pass it by for purely numerical reasons. – Paul B. Slater Jul 26 '18 at 03:54
  • 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 https://arxiv.org/abs/0909.5094) is clearly invalid, and the ensuing calculation would seem meaningless. – Paul B. Slater Jul 26 '18 at 04:02
  • 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. – John Doty Jul 26 '18 at 10:36
  • 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}]) – Paul B. Slater Jul 26 '18 at 13:14
  • 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]]] – John Doty Jul 26 '18 at 15:35
  • A little too technically sophisticated for me, presently--although I did try (so far unsuccessfully) implementing the indicated With command. In any case, it seems that I can address this error problem by sufficiently upping the working precision. So, I'm rather content at the moment. Thanks to all for the helpful suggestions. It's been somewhat of a learning/broadening experience. Actually, in the original code I was testing the result of the Orthogonalize-based command with PositiveDefiniteQ, a test only passed about 7% of the time. When the error message was generated, the test wasn't passe – Paul B. Slater Jul 26 '18 at 17:42
  • PositiveDefiniteMatrixQ yields false if its argument isn't a matrix. The unevaluated Orthogonalize expression you get when Orthogonalize fails is not a matrix, so that would seem to be what you want. – John Doty Jul 26 '18 at 18:03