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

An error in the function 'get_one_hot' #14

Closed
Koiocs opened this issue Dec 4, 2023 · 1 comment
Closed

An error in the function 'get_one_hot' #14

Koiocs opened this issue Dec 4, 2023 · 1 comment

Comments

@Koiocs
Copy link

Koiocs commented Dec 4, 2023

when the getitem function is called, get_one_hot(smiles, 350) is called. In get_one_hot(smiles, 350) function, the array_length is limited within 350, but the index of numeric can exceed 350, causing the IndexError for one_hot in axis 0.

class SmilesDataset(Dataset):
    __PAD_LEN = 350

    def __init__(self, smiles_list):
        super().__init__()
        self.smiles_list = smiles_list

    def __getitem__(self, idx):
        smiles = self.smiles_list[idx]
        features = get_one_hot(smiles, 350)  //set pad_len = 350
        return features / features.shape[1]

    def __len__(self):
        return len(self.smiles_list)
def get_one_hot(smiles: str, pad_len: int = -1) -> np.ndarray:
    """Generate one-hot representation of a Smiles string.

    Args:
        smiles (str): Input molecule as Smiles
        pad_len (int, optional): Whether or not to pad to a given size. Defaults to -1.

    Returns:
        np.ndarray: Array containing the one-hot encoded Smiles
    """
    smiles = smiles + "."

    # initialize array
    array_length = len(smiles) if pad_len < 0 else pad_len
    vocab_size = len(__vocab)
    one_hot = np.zeros((array_length, vocab_size))

    tokens = tokenize(smiles)
    numeric = [__vocab_c2i.get(token, __unk) for token in tokens]

    for pos, num in enumerate(numeric):  //pos can exceed 350
        one_hot[pos, num] = 1    //IndexError

    return one_hot
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

Thanks for your comment. This has been fixed in 1.2.1

@renzph renzph closed this as completed Apr 1, 2024
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

2 participants