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: Imaginary component #15

Open
parkyjmit opened this issue Mar 22, 2024 · 2 comments
Open

ValueError: Imaginary component #15

parkyjmit opened this issue Mar 22, 2024 · 2 comments

Comments

@parkyjmit
Copy link

Hello, I've got an issue for get_fcd function.

I reproduced this error in google colab

!pip install fcd
from fcd import get_fcd

smiles_list1 = ['COc1cccc(NC(=O)Cc2coc3ccc(OC)cc23)c1', 'Cc1noc(C)c1CN(C)C(=O)Nc1cc(F)cc(F)c1']
smiles_list2 = ['Oc1ccccc1-c1cccc2cnccc12', 'Cc1noc(C)c1CN(C)C(=O)Nc1cc(F)cc(F)c1']
get_fcd(smiles_list1, smiles_list2)

and I've got this result.


ValueError Traceback (most recent call last)
in <cell line: 3>()
1 smiles_list1 = ['COc1cccc(NC(=O)Cc2coc3ccc(OC)cc23)c1', 'Cc1noc(C)c1CN(C)C(=O)Nc1cc(F)cc(F)c1']
2 smiles_list2 = ['Oc1ccccc1-c1cccc2cnccc12', 'Cc1noc(C)c1CN(C)C(=O)Nc1cc(F)cc(F)c1']
----> 3 get_fcd(smiles_list1, smiles_list2)

1 frames
/usr/local/lib/python3.10/dist-packages/fcd/utils.py in calculate_frechet_distance(mu1, sigma1, mu2, sigma2, eps)
171 if not np.allclose(np.diagonal(covmean).imag, 0, atol=1e-3):
172 m = np.max(np.abs(covmean.imag))
--> 173 raise ValueError("Imaginary component {}".format(m))
174 covmean = covmean.real
175

ValueError: Imaginary component 1.90603044681631e+39

Do you have any idea to solve this?
I have to get fcd value for my project

@hogru
Copy link

hogru commented Mar 27, 2024

Just browsing here for a different reason... just to make sure... does this also happen with more than 2 molecules? (since it calculates the variance...)

renzph added a commit that referenced this issue Mar 29, 2024
1. Changes to `get_one_hot`
Problems are given in:
- #14
- #17
- #13

I discarded the changes in the PRs and and added more comprehensive handling of the input data in the
`SmilesDataset` class and the `get_one_hot` function.

2. Imaginary components
Frechet distance calculation fails to work for some cases because of badly conditioned matrices,
as described here #15.

Could not reproduce the error locally, but could do so on colab.

Fixed it in `calculate_frechet_distance` by checking if the first `covmean` computation  is real add a small value to the diagonal.
This made it work for me and I got the same result as the original implementation run locally.

3. Added some more tests and changed to pytest

4. As described in #16
I changed the data type of the activations to float32 in the `get_predictions` function,
which saves memory for larger datasets.
renzph added a commit that referenced this issue Apr 1, 2024
1. Changes to `get_one_hot`
Problems are given in:
- #14
- #17
- #13

I discarded the changes in the PRs and and added more comprehensive handling of the input data in the
`SmilesDataset` class and the `get_one_hot` function.

2. Imaginary components
Frechet distance calculation fails to work for some cases because of badly conditioned matrices,
as described here #15.

Could not reproduce the error locally, but could do so on colab.

Fixed it in `calculate_frechet_distance` by checking if the first `covmean` computation  is real add a small value to the diagonal.
This made it work for me and I got the same result as the original implementation run locally.

3. Added some more tests and changed to pytest

4. As described in #16
I changed the data type of the activations to float32 in the `get_predictions` function,
which saves memory for larger datasets.
renzph added a commit that referenced this issue Apr 1, 2024
1. Changes to `get_one_hot`
Problems are given in:
- #14
- #17
- #13

I discarded the changes in the PRs and and added more comprehensive handling of the input data in the
`SmilesDataset` class and the `get_one_hot` function.

2. Imaginary components
Frechet distance calculation fails to work for some cases because of badly conditioned matrices,
as described here #15.

Could not reproduce the error locally, but could do so on colab.

Fixed it in `calculate_frechet_distance` by checking if the first `covmean` computation  is real add a small value to the diagonal.
This made it work for me and I got the same result as the original implementation run locally.

3. Added some more tests and changed to pytest

4. As described in #16
I changed the data type of the activations to float32 in the `get_predictions` function,
which saves memory for larger datasets.
renzph added a commit that referenced this issue Apr 1, 2024
1. Changes to `get_one_hot`
Problems are given in:
- #14
- #17
- #13

I discarded the changes in the PRs and and added more comprehensive handling of the input data in the
`SmilesDataset` class and the `get_one_hot` function.

2. Imaginary components
Frechet distance calculation fails to work for some cases because of badly conditioned matrices,
as described here #15.

Could not reproduce the error locally, but could do so on colab.

Fixed it in `calculate_frechet_distance` by checking if the first `covmean` computation  is real add a small value to the diagonal.
This made it work for me and I got the same result as the original implementation run locally.

3. Added some more tests and changed to pytest

4. As described in #16
I changed the data type of the activations to float32 in the `get_predictions` function,
which saves memory for larger datasets.
renzph added a commit that referenced this issue Apr 1, 2024
1. Changes to `get_one_hot`
Problems are given in:
- #14
- #17
- #13

I discarded the changes in the PRs and and added more comprehensive handling of the input data in the
`SmilesDataset` class and the `get_one_hot` function.

2. Imaginary components
Frechet distance calculation fails to work for some cases because of badly conditioned matrices,
as described here #15.

Could not reproduce the error locally, but could do so on colab.

Fixed it in `calculate_frechet_distance` by checking if the first `covmean` computation  is real add a small value to the diagonal.
This made it work for me and I got the same result as the original implementation run locally.

3. Added some more tests and changed to pytest

4. As described in #16
I changed the data type of the activations to float32 in the `get_predictions` function,
which saves memory for larger datasets.
renzph added a commit that referenced this issue Apr 1, 2024
1. Changes to `get_one_hot`
Problems are given in:
- #14
- #17
- #13

I discarded the changes in the PRs and and added more comprehensive handling of the input data in the
`SmilesDataset` class and the `get_one_hot` function.

2. Imaginary components
Frechet distance calculation fails to work for some cases because of badly conditioned matrices,
as described here #15.

Could not reproduce the error locally, but could do so on colab.

Fixed it in `calculate_frechet_distance` by checking if the first `covmean` computation  is real add a small value to the diagonal.
This made it work for me and I got the same result as the original implementation run locally.

3. Added some more tests and changed to pytest

4. As described in #16
I changed the data type of the activations to float32 in the `get_predictions` function,
which saves memory for larger datasets.

5. Change to pyproject.toml
@renzph
Copy link
Member

renzph commented Apr 1, 2024

Hey @parkyjmit,
This never happened on the machines I used, but I could reproduce the error on Colab and on the machines used by GitHub actions.

It turned out to be a numerical issue. I fixed it in the new release and it should be working on colab now.

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

3 participants