Repository navigation
Commit ded6cee
committed
[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 107cd1b commit ded6cee
2 files changed
Lines changed: 43 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
420 | 434 | | |
421 | 435 | | |
422 | 436 | | |
| |||
517 | 531 | | |
518 | 532 | | |
519 | 533 | | |
520 | | - | |
| 534 | + | |
521 | 535 | | |
522 | 536 | | |
523 | 537 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| 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 | + | |
216 | 244 | | |
217 | 245 | | |
218 | 246 | | |
| |||
0 commit comments