Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated square root computation for sparse matrices #51

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions cleanfid/fid.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ def frechet_distance(mu1, sigma1, mu2, sigma2, eps=1e-6):
diff = mu1 - mu2

# Product might be almost singular
covmean, _ = linalg.sqrtm(sigma1.dot(sigma2), disp=False)
covmean = linalg.fractional_matrix_power(sigma1.dot(sigma2), 0.5)
if not np.isfinite(covmean).all():
msg = ('fid calculation produces singular product; '
'adding %s to diagonal of cov estimates') % eps
print(msg)
offset = np.eye(sigma1.shape[0]) * eps
covmean = linalg.sqrtm((sigma1 + offset).dot(sigma2 + offset))
covmean = linalg.fractional_matrix_power((sigma1 + offset).dot(sigma2 + offset), 0.5)

# Numerical error might give slight imaginary component
if np.iscomplexobj(covmean):
Expand Down