Commit d98c453
committed
Fix elementwise variance accumulation in lsqr (closes #639)
lsqr's optional `var` output estimates the diagonal of (A^H A)^-1, one
variance per unknown. The update accumulated `ncp.dot(self.dk, self.dk)`,
which is the scalar sum of squares of `dk`, so the same value was added to
every entry of `var` and all returned variances came out identical (and
wrong).
Accumulate the elementwise square `ncp.square(self.dk)` instead, matching
Paige & Saunders (1982, p.53) and scipy's lsqr. The solution path is
unchanged; only the `var` output is corrected.
Add test_lsqr_calc_var asserting the variances are not all identical and
match both scipy's lsqr and the dense diag(inv(A^H A)) on full-column-rank
systems.1 parent ebe4e15 commit d98c453
2 files changed
Lines changed: 33 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1248 | 1248 | | |
1249 | 1249 | | |
1250 | 1250 | | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
1251 | 1256 | | |
1252 | | - | |
| 1257 | + | |
1253 | 1258 | | |
1254 | 1259 | | |
1255 | 1260 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
377 | 377 | | |
378 | 378 | | |
379 | 379 | | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
380 | 407 | | |
381 | 408 | | |
382 | 409 | | |
| |||
0 commit comments