integrated the faster implementation
@@ -216,7 +216,7 @@ def _all_combinations(vectors1, vectors2, func):
return value
-def _cosine_cov_weighted(vector1, vector2, sigma_k=None):
+def _cosine_cov_weighted_slow(vector1, vector2, sigma_k=None):
"""computes the cosine angles between two sets of vectors
Args:
@@ -249,9 +249,11 @@ def _cosine_cov_weighted(vector1, vector2, sigma_k=None):
vector2_m)).reshape((1, -1))
return cos
-def _cosine_cov_weighted_fast(vector1, vector2):
+
+def _cosine_cov_weighted(vector1, vector2, sigma_k=None):
"""computes the cosine angles between two sets of vectors
weighted by the covariance - linearCKA
+
Args:
vector1 (numpy.ndarray):
first vectors (2D)
@@ -263,6 +265,9 @@ def _cosine_cov_weighted_fast(vector1, vector2):
cosine angle between vectors (linear CKA)
"""
+ if sigma_k is not None:
+ cos = _cosine_cov_weighted_slow(vector1, vector2, sigma_k=sigma_k)
+ else:
# Compute the extended version of RDM vectors in whitened space
vector1_m = _cov_weighting(vector1)
vector2_m = _cov_weighting(vector2)
@@ -276,6 +281,7 @@ def _cosine_cov_weighted_fast(vector1, vector2):
vector2_m)).reshape((1, -1))
return cos
+
def _cov_weighting(vector):
"""Transforms a array of RDM vectors in to representation
in which the elements are isotropic. This is a stretched-out
@@ -304,6 +310,7 @@ def _cov_weighting(vector):
vector_w[:,:n_dist] = vector_w[:,:n_dist] * np.sqrt(2)
return vector_w
+
def _cosine(vector1, vector2):
"""computes the cosine angles between two sets of vectors
