|
15 | 15 | from scipy.spatial.distance import cdist |
16 | 16 | from scipy.special import sph_harm |
17 | 17 |
|
18 | | -from .fixes import jit, mean, _get_img_fdata |
| 18 | +from .fixes import jit, _get_img_fdata |
19 | 19 | from ._fiff.constants import FIFF |
20 | 20 | from ._fiff.open import fiff_open |
21 | 21 | from ._fiff.tag import read_tag |
@@ -1466,16 +1466,12 @@ def _fit_matched_points(p, x, weights=None, scale=False): |
1466 | 1466 | assert p.ndim == 2 |
1467 | 1467 | assert p.shape[1] == 3 |
1468 | 1468 | # (weighted) centroids |
1469 | | - if weights is None: |
1470 | | - mu_p = mean(p, axis=0) # eq 23 |
1471 | | - mu_x = mean(x, axis=0) |
1472 | | - dots = np.dot(p.T, x) |
1473 | | - dots /= p.shape[0] |
1474 | | - else: |
1475 | | - weights_ = np.reshape(weights / weights.sum(), (weights.size, 1)) |
1476 | | - mu_p = np.dot(weights_.T, p)[0] |
1477 | | - mu_x = np.dot(weights_.T, x)[0] |
1478 | | - dots = np.dot(p.T, weights_ * x) |
| 1469 | + weights_ = np.full((p.shape[0], 1), 1.0 / max(p.shape[0], 1)) |
| 1470 | + if weights is not None: |
| 1471 | + weights_[:] = np.reshape(weights / weights.sum(), (weights.size, 1)) |
| 1472 | + mu_p = np.dot(weights_.T, p)[0] |
| 1473 | + mu_x = np.dot(weights_.T, x)[0] |
| 1474 | + dots = np.dot(p.T, weights_ * x) |
1479 | 1475 | Sigma_px = dots - np.outer(mu_p, mu_x) # eq 24 |
1480 | 1476 | # x and p should no longer be used |
1481 | 1477 | A_ij = Sigma_px - Sigma_px.T |
|
0 commit comments