Skip to content

Commit

Permalink
numpify normalisation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromekelleher committed Dec 1, 2023
1 parent ea8b6ca commit 54f1fd4
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions python/tskit/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -8142,16 +8142,11 @@ def genetic_relatedness_matrix(
def _normalise(B):
if len(B) == 0:
return B
K = np.zeros_like(B)
N = K.shape[0]
B_mean = np.mean(B)
Bi_mean = np.mean(B, axis=0)
# TODO numpify - should be easy enough by creating full matrices
# for the row and column means.
for i in range(N):
for j in range(N):
K[i, j] = B[i, j] - Bi_mean[i] - Bi_mean[j] + B_mean
# FIXME I don't know what this factor -2 is about
K = B + np.mean(B)
y = np.mean(B, axis=0)
X = y[:, np.newaxis] + y[np.newaxis, :]
K -= X
# FIXME I don't know what this factor of -2 is about
return K / -2

if windows is None:
Expand Down

0 comments on commit 54f1fd4

Please sign in to comment.