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

ValueError: The precomputed distance matrix contains non-zero elements on the diagonal #4

Open
eam12 opened this issue Aug 11, 2023 · 0 comments

Comments

@eam12
Copy link

eam12 commented Aug 11, 2023

Hello! I'm using version 1.24 of pHierCC. I was trying to run HCCeval on the toy dataset provided using the code provided:

HCCeval -p YERwgMLST.cgMLSTv1.profile.gz -c YERwgMLST.cgMLSTv1.HierCC.HierCC.gz -o YERwgMLST.cgMLSTv1.HierCC.eval

However, I received the following error:

2023-08-11 12:35:23,232 | Calculating NMIs...
2023-08-11 12:35:23,233 |     NMIs between level 0 and greater levels
2023-08-11 12:35:26,324 |     NMIs between level 100 and greater levels
2023-08-11 12:35:28,664 |     NMIs between level 200 and greater levels
2023-08-11 12:35:31,335 |     NMIs between level 300 and greater levels
2023-08-11 12:35:33,425 |     NMIs between level 400 and greater levels
2023-08-11 12:35:35,383 |     NMIs between level 500 and greater levels
2023-08-11 12:35:36,819 |     NMIs between level 600 and greater levels
2023-08-11 12:35:38,604 |     NMIs between level 700 and greater levels
2023-08-11 12:35:39,819 |     NMIs between level 800 and greater levels
2023-08-11 12:35:41,393 |     NMIs between level 900 and greater levels
2023-08-11 12:35:42,390 |     NMIs between level 1000 and greater levels
2023-08-11 12:35:43,305 |     NMIs between level 1100 and greater levels
2023-08-11 12:35:43,674 |     NMIs between level 1200 and greater levels
2023-08-11 12:35:44,404 |     NMIs between level 1300 and greater levels
2023-08-11 12:35:44,596 |     NMIs between level 1400 and greater levels
2023-08-11 12:35:44,700 |     NMIs between level 1500 and greater levels
2023-08-11 12:35:44,722 | Calculating pairwise distance ...
2023-08-11 12:36:10,300 | Calculating Silhouette score ...
multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/home/johnsont/shared/.conda/envs/phiercc/lib/python3.8/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/home/johnsont/shared/.conda/envs/phiercc/lib/python3.8/multiprocessing/pool.py", line 48, in mapstar
    return list(map(*args))
  File "/home/johnsont/shared/.conda/envs/phiercc/lib/python3.8/site-packages/pHierCC/HCCeval.py", line 58, in get_silhouette2
    ss = silhouette_score(dist.astype(float), tag, metric = 'precomputed')
  File "/home/johnsont/shared/.conda/envs/phiercc/lib/python3.8/site-packages/sklearn/metrics/cluster/_unsupervised.py", line 118, in silhouette_score
    return np.mean(silhouette_samples(X, labels, metric=metric, **kwds))
  File "/home/johnsont/shared/.conda/envs/phiercc/lib/python3.8/site-packages/sklearn/metrics/cluster/_unsupervised.py", line 220, in silhouette_samples
    raise ValueError(
ValueError: The precomputed distance matrix contains non-zero elements on the diagonal. Use np.fill_diagonal(X, 0).
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/johnsont/shared/.conda/envs/phiercc/bin/HCCeval", line 11, in <module>
    sys.exit(evalHCC())
  File "/home/johnsont/shared/.conda/envs/phiercc/lib/python3.8/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/home/johnsont/shared/.conda/envs/phiercc/lib/python3.8/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/johnsont/shared/.conda/envs/phiercc/lib/python3.8/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/johnsont/shared/.conda/envs/phiercc/lib/python3.8/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/johnsont/shared/.conda/envs/phiercc/lib/python3.8/site-packages/pHierCC/HCCeval.py", line 94, in evalHCC
    silhouette = get_silhouette(profile, cluster, stepwise, pool)
  File "/home/johnsont/shared/.conda/envs/phiercc/lib/python3.8/site-packages/pHierCC/HCCeval.py", line 49, in get_silhouette
    silhouette = np.array(pool.map(get_silhouette2, [ [dist_buf, tag] for tag in cluster.T ]))
  File "/home/johnsont/shared/.conda/envs/phiercc/lib/python3.8/multiprocessing/pool.py", line 364, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
  File "/home/johnsont/shared/.conda/envs/phiercc/lib/python3.8/multiprocessing/pool.py", line 771, in get
    raise self._value
ValueError: The precomputed distance matrix contains non-zero elements on the diagonal. Use np.fill_diagonal(X, 0).

The error message makes sense, but I'm unsure why there would be non-zero elements on the diagonal. Any help would be much appreciated.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant