Skip to content

Commit 96dc4a7

Browse files
committed
Fix covariance_matrix and correlation_matrix image functions
1 parent 8b31975 commit 96dc4a7

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

psdist/image.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def radial_density(
9797
return np.array(values_r)
9898

9999

100-
def mean(values: np.ndarray, coords: list[np.ndarray] = None) -> np.ndarray:
100+
def centroid(values: np.ndarray, coords: list[np.ndarray] = None) -> np.ndarray:
101101
"""Compute the n-dimensional mean.
102102
103103
Parameters
@@ -119,7 +119,7 @@ def mean(values: np.ndarray, coords: list[np.ndarray] = None) -> np.ndarray:
119119
return mean
120120

121121

122-
def cov(values: np.ndarray, coords: list[np.ndarray] = None) -> np.ndarray:
122+
def covariance_matrix(values: np.ndarray, coords: list[np.ndarray] = None) -> np.ndarray:
123123
"""Compute the n x n covariance matrix.
124124
125125
Parameters
@@ -134,7 +134,7 @@ def cov(values: np.ndarray, coords: list[np.ndarray] = None) -> np.ndarray:
134134
The covariance matrix.
135135
"""
136136

137-
def get_cov_2x2(values: np.ndarray, coords: list[np.ndarray]) -> np.ndarray:
137+
def covariance_matrix_2x2(values: np.ndarray, coords: list[np.ndarray]) -> np.ndarray:
138138
COORDS = np.meshgrid(*coords, indexing="ij")
139139
cov = np.zeros((values.ndim, values.ndim))
140140
values_sum = np.sum(values)
@@ -154,7 +154,7 @@ def get_cov_2x2(values: np.ndarray, coords: list[np.ndarray]) -> np.ndarray:
154154
coords = [np.arange(s) for s in values.shape]
155155

156156
if values.ndim < 3:
157-
return cov_2x2(values, coords)
157+
return covariance_matrix_2x2(values, coords)
158158

159159
cov = np.zeros((values.ndim, values.ndim))
160160
for i in range(values.ndim):
@@ -163,16 +163,16 @@ def get_cov_2x2(values: np.ndarray, coords: list[np.ndarray]) -> np.ndarray:
163163
_values = project(values, axis=axis)
164164
_coords = [coords[i] for i in axis]
165165
# Compute 2 x 2 covariance matrix from this projection.
166-
_cov = get_cov_2x2(_values, _coords)
166+
cov_2x2 = covariance_matrix_2x2(_values, _coords)
167167
# Update elements of n x n covariance matrix. This will update
168168
# some elements multiple times, but it should not matter.
169-
cov[i, i] = _cov[0, 0]
170-
cov[j, j] = _cov[1, 1]
171-
cov[i, j] = Sigma[j, i] = _cov[0, 1]
169+
cov[i, i] = cov_2x2[0, 0]
170+
cov[j, j] = cov_2x2[1, 1]
171+
cov[i, j] = cov[j, i] = cov_2x2[0, 1]
172172
return cov
173173

174174

175-
def cov(values: np.ndarray, coords: list[np.ndarray] = None) -> np.ndarray:
175+
def correlation_matrix(values: np.ndarray, coords: list[np.ndarray] = None) -> np.ndarray:
176176
"""Compute the n x n correlation matrix.
177177
178178
Parameters
@@ -186,7 +186,7 @@ def cov(values: np.ndarray, coords: list[np.ndarray] = None) -> np.ndarray:
186186
ndarray, shape (n, n).
187187
The correlation matrix.
188188
"""
189-
return cov_to_corr(cov(values, coords))
189+
return cov_to_corr(covariance_matrix(values, coords))
190190

191191

192192
# Higher order moments (experimental)

0 commit comments

Comments
 (0)