Repository navigation
Commit 3ec2d1b
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 3721224 commit 3ec2d1b
2 files changed
Lines changed: 43 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
402 | 416 | | |
403 | 417 | | |
404 | 418 | | |
| |||
492 | 506 | | |
493 | 507 | | |
494 | 508 | | |
495 | | - | |
| 509 | + | |
496 | 510 | | |
497 | 511 | | |
498 | 512 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
174 | 202 | | |
175 | 203 | | |
176 | 204 | | |
| |||
0 commit comments