Skip to content

Commit c57f662

Browse files
committed
refine pearson by recalculating it using cov
1 parent 7fcb69a commit c57f662

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

stumpy/stump.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,8 @@ def _compute_diagonal(
151151
n_A = T_A.shape[0]
152152
n_B = T_B.shape[0]
153153
m_inverse = 1.0 / m
154-
m_inverse_half = 0.5 * m_inverse
155-
156154
constant = (m - 1) * m_inverse * m_inverse # (m - 1)/(m * m)
157155

158-
x = np.empty(m, dtype=np.float64)
159-
y = np.empty(m, dtype=np.float64)
160156
for diag_idx in range(diags_start_idx, diags_stop_idx):
161157
k = diags[diag_idx]
162158

@@ -197,16 +193,15 @@ def _compute_diagonal(
197193
if pearson > ρ[thread_idx, i, 0] or (
198194
ignore_trivial and pearson > ρ[thread_idx, i + k, 0]
199195
):
200-
x[:] = (T_A[i : i + m] - μ_Q[i]) * σ_Q_inverse[i]
201-
y[:] = (T_B[i + k : i + k + m] - M_T[i + k]) * Σ_T_inverse[
202-
i + k
203-
]
204-
D_squared = (
205-
np.sum(np.square(x))
206-
+ np.sum(np.square(y))
207-
- 2 * np.dot(x, y)
196+
pearson = (
197+
np.dot(
198+
(T_B[i + k : i + k + m] - M_T[i + k]),
199+
(T_A[i : i + m] - μ_Q[i]),
200+
)
201+
* m_inverse
202+
* Σ_T_inverse[i + k]
203+
* σ_Q_inverse[i]
208204
)
209-
pearson = 1.0 - m_inverse_half * D_squared
210205

211206
if pearson > 1.0:
212207
pearson = 1.0

0 commit comments

Comments
 (0)