-
Notifications
You must be signed in to change notification settings - Fork 441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xORBDB6 performs numerically unadvisable operations #634
Comments
A test highlighting the problem can be found in christoph-conrads/qr+cs-gsvd branch in commit 6c576c4. The test does not trigger yet in double precision because |
Lines 241 to 247 in 5d4180c
This should be SCL = REALZERO
SSQ = REALONE
CALL SLASSQ( M1, X1, INCX1, SCL, SSQ )
CALL SLASSQ( M2, X2, INCX2, SCL, SSQ )
NORMSQ2 = SCL**2 * SSQ |
In my opinion, the functions xORBDB6/xUNBDB6 should be modified to enhance numerical stability. The first issue is that there are no restrictions on the norm of Line 247 in 5d4180c
The expression might over- or underflow. An underflow is one of the causes of the problem observed in the pull request #406 test SCL = REALZERO
SSQ = REALONE
CALL SLASSQ( M1, X1, INCX1, SCL, SSQ )
CALL SLASSQ( M2, X2, INCX2, SCL, SSQ )
NORM = SCL * SQRT(SSQ) Lines 257 to 259 in 5d4180c
edit For xORBDB6, the right-hand side constant could be This branch is only taken if if norm_after_gs <= (m1 + m2) * eps * norm:
x(:) = 0
return Lines 283 to 289 in 5d4180c
After the second Gram-Schmidt orthogonalization, Lines 290 to 295 in 5d4180c
This comparison might fail if the right-hand side underflows; this can happen if the vector For completeness, a pull request should fix the vector increments as Brian Sutton correctly noted and also check or handle negative increments like other LAPACK functions. @briansutton @langou @weslleyspereira Please comment on my proposal. edit |
Hi @christoph-conrads. Thanks for the time of explaining all of this! I talked to @langou last week. He had something else to say about the precision of the final orthogonal vector depending on how Q is far from being a true orthogonal matrix. I'm not sure if he will be able to comment on this thread this week, so here are my comments:
I agree. I would go with updating the documentation.
I agree.
I agree.
I agree the condition should either be removed or be changed another one involving some tolerance. I'm not sure which tolerance. I think it makes sense to use something like Lines 223 to 226 in 5d4180c
should be modified using the same pattern.
Oh... this is a bug!
Suppose we use a more appropriate check for
I agree.
I agree. The new value would be |
The factor is essentially the error bound In Highman Accuracy and Stability of Numerical Algorithms (2002) the norm-wise error bound for matrix-vector multiplication
With the improved error bounds in Jeannerod, Rump: Improved Error Bounds for Inner Products in Floating-Point Arithmetic (2013) it might be possible to consider the function
If xORBDB6 considers a vector to be numerically zero, then it is set to zero, see
|
I do not think so. If the input vector |
I have been wondering why we do not use some Householder reflections for these routines, as opposed to Gram-Schmidt. This seems doable. And we would not be worried about numerical stability. The proof of 2005 for stability of CGS2 requires the assumption that the input matrix is numerically nonsingular. (So "twice is enough" if something like "epsilon * kappa < 1".) I do not know whether this condition will hold in this piece of code. There are a few places in LAPACK where we use Gram-Schmidt and I think we should make an effort to use Householder reflections instead. Cheers, |
The caller must ensure that |
The matrix |
Hi Christoph, Even if Q is a perfectly orthonormal basis, we can imagine that we run into issues with a two-projection Gram-Schmidt scheme. If x has many components in Span(Q) ( ||Q^Tx || ~ || x || ), then the first projection will essentially returns a random vector. It is possible (unlikely but possible) that this random vector is again in Span(Q). So the second projection is again a random vector, which is unlikely to be orthogonal to Span(Q). Therefore we can imagine that we do not have orthogonality after two steps. The trick to prove that With all that being said, I think the code works with high probability and is very well written so all good with me Julien. |
Description
xORBDB5 and xORBDB6 compute vector norms differently causing disagreement on when a vector is numerically zero.
Given an isometric matrix
Q
and a vectorx
, xORBDB5 computes a vectorx'
that is orthogonal to the span of the columns ofQ
. (Q
isometric means that the following two properties hold:Q
has at most as many columns as rows andQ^* Q = I
). Internally xORBDB5 calls xORBDB6. Given an isometric matrixQ
and a vectorx
, xORBDB6 projectsx
onto the complement of the column span ofQ
. The code contains only the ominous comment thatis applied. Probably this means that xORBDB6 uses at most two iterations of classical Gram-Schmidt orthogonalization to compute its results. This approach is known as CGS2, see BarlowS2011 or GiraudLR2002 and it matches the matrix-vector multiplications inside this function. The problem are the computation of the vector norm.
For a xORBDB5, the norm of the vector computed by xORBDB6 is computed with
SNRM2
:lapack/SRC/sorbdb5.f
Lines 223 to 226 in 5d4180c
For xORBDB6, the vector norm is computed as follows:
lapack/SRC/sorbdb6.f
Lines 241 to 247 in 5d4180c
Consider the input to xORBDB6 below:
With
x = e_2
(i.e., the second standard basis vector), the xORBDB6 variableNORMSQ2
is zero whereasSNRM2
is nonzero causing xORBDB5 to return an incorrect vector.Checklist
The text was updated successfully, but these errors were encountered: