Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions superblockify/metrics/measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,12 +755,14 @@ def __calculate_high_bc_anisotropy(coord_high_bc):
)
# Covariance matrix
cov = np.cov(coord_high_bc.T)
# Eigenvalues
eigvals = np.linalg.eigvals(cov)
# Sort eigenvalues
eigvals = np.sort(eigvals)[::-1]
# Anisotropy
return eigvals[0] / eigvals[1]
# Eigenvalues - the covariance matrix is symmetric, so use eigvalsh, which
# always returns real eigenvalues in ascending order (eigvals returns them as
# complex dtype on NumPy >= 2)
eigvals = np.linalg.eigvalsh(cov)
# Anisotropy - ratio of largest to smallest eigenvalue, infinite if degenerate;
# clip numerical-noise negative eigenvalues to zero
with np.errstate(divide="ignore", invalid="ignore"):
return float(eigvals[-1] / max(eigvals[0], 0.0))


def add_ltn_means(components, edge_attr):
Expand Down
Loading