Repository navigation
Commit 3183ac1
[FIX] ASR: use a real PSD square root in asr_calibrate
asr_calibrate computed M = linalg.sqrtm(np.real(Uavg)), which only strips a
pre-existing imaginary part but does not make Uavg positive-semidefinite. If
the robust average covariance Uavg has even a tiny negative eigenvalue
(realistic for average-referenced / rank-deficient EEG covariance means),
scipy.linalg.sqrtm of the resulting indefinite symmetric matrix returns a
complex M, which then silently propagates through eigh(M) into V and the
threshold matrix T.
asr_process already guards against this by taking np.real() of its
eigen-quantities after eigh, but asr_calibrate lacked the equivalent guard.
Add _psd_sqrtm(), a real symmetric PSD square root that symmetrizes its input
and clamps numerically-negative eigenvalues to zero before taking the square
root, and use it in asr_calibrate. For a genuinely PSD Uavg (the normal case)
this is the same principal square root sqrtm would return, so calibration is
numerically unchanged; when Uavg is slightly indefinite it now yields a real
M, and hence real V/T.1 parent f71758d commit 3183ac1
2 files changed
Lines changed: 43 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
444 | 444 | | |
445 | 445 | | |
446 | 446 | | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
447 | 461 | | |
448 | 462 | | |
449 | 463 | | |
| |||
544 | 558 | | |
545 | 559 | | |
546 | 560 | | |
547 | | - | |
| 561 | + | |
548 | 562 | | |
549 | 563 | | |
550 | 564 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
217 | 245 | | |
218 | 246 | | |
219 | 247 | | |
| |||
0 commit comments