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

Create a persistence diagram type #84

Closed
raphaelreinauer opened this issue May 10, 2022 · 0 comments · Fixed by #93
Closed

Create a persistence diagram type #84

raphaelreinauer opened this issue May 10, 2022 · 0 comments · Fixed by #93
Assignees
Labels
enhancement New feature or request top priority The issue is to be solved as soon as possible, as it may block the usage of the library

Comments

@raphaelreinauer
Copy link
Collaborator

raphaelreinauer commented May 10, 2022

Issue:
When using persistence diagrams as pytorch tensors one always has to check if they
the input has the right format (2 dimensional, one-hot-encoded homology typ ...) which
is a huge overhead.

Suggestion:
We could use the typing module to define a subtype of tensor which represents
one-hot-encoded persistence diagrams. This would allow to stafely pass around
persistence diagrams without having the overhead of additional assertions everywhere.

Sample code:

from typing import NewType

# Create a subtype of tensor representing one-hot persistence diagrams with`
# almost zero runtime overhead.`
OneHotPersistenceDiagram = NewType('OneHotPersistenceDiagram', torch.Tensor)`


def one_hot_persistence_diagram(persistence_diagram: torch.Tensor) \
    -> OneHotPersistenceDiagram:
    """Convert a persistence diagram to one-hot encoding."""
    assert persistence_diagram.ndim == 2
    # ..... additional assertions here ...


    return OneHotPersistenceDiagram(persistence_diagram)
x = torch.tensor([[0.0, 1.0, 0.0, 1.0],
                  [0.2, 0.4, 1.0, 0.0]])

pd = one_hot_persistence_diagram(x)

def get_number_of_homology_type(persistence_diagram: OneHotPersistenceDiagram) \
    -> int:
    """Get the number of homology types in a persistence diagram."""
    return persistence_diagram.shape[1] - 2

get_number_of_homology_type(pd) # = 2
get_number_of_homology_type(x)  # Will cause a TypeError

 # Otherwise we can use pd as a usual pytorch tensor
@raphaelreinauer raphaelreinauer added the enhancement New feature or request label May 10, 2022
@raphaelreinauer raphaelreinauer self-assigned this May 10, 2022
@matteocao matteocao added this to the Giotto-deep release milestone May 12, 2022
@matteocao matteocao added the top priority The issue is to be solved as soon as possible, as it may block the usage of the library label May 17, 2022
@matteocao matteocao linked a pull request Jun 17, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request top priority The issue is to be solved as soon as possible, as it may block the usage of the library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants