-
Notifications
You must be signed in to change notification settings - Fork 11
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
Support non-simplicial complexes #26
Open
trevorkarn
wants to merge
6
commits into
scikit-tda:master
Choose a base branch
from
trevorkarn:nonsimplicial
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
70a6298
Add check for simplicial filtration
trevorkarn c792e99
Fix key
trevorkarn f24ba2e
Update BaseFiltration to accept optional 'simplicial' argument
trevorkarn 3997774
Add diagrams to CustomFiltration with default to make simplicial
trevorkarn 1d23c38
Change default behavior of phat_diagrams to take simplicial to be false
trevorkarn 5ddaa30
Add examples to BasicUsage notebook
trevorkarn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
import phat | ||
|
||
|
||
def phat_diagrams(simplices, show_inf=False, verbose=True): | ||
def phat_diagrams(simplices, show_inf=False, verbose=True, simplicial=False): | ||
""" | ||
Compute the persistence diagram for :code:`simplices` using Phat. | ||
|
||
|
@@ -19,12 +19,21 @@ def phat_diagrams(simplices, show_inf=False, verbose=True): | |
show_inf: Boolean | ||
Determines whether or not to return points that never die. | ||
|
||
simplicial: Boolean | ||
Asserts that the filtration is a simplicial complex at every "dist," | ||
not some other kind of topological complex. Defaults to not checking | ||
to ensure speed of existing filtrations. | ||
|
||
Returns | ||
-------- | ||
dgms: list of diagrams | ||
the persistence diagram for Hk | ||
""" | ||
|
||
## Check that the filtration is a simplicial complex at every time step | ||
if simplicial: | ||
simplices = _assert_simplicial(simplices) | ||
|
||
## Convert simplices representation to sparse pivot column | ||
# -- sort by birth time, if tie, use order of simplex | ||
ordered_simplices = sorted(simplices, key=lambda x: (x[1], len(x[0]))) | ||
|
@@ -59,6 +68,36 @@ def phat_diagrams(simplices, show_inf=False, verbose=True): | |
|
||
return dgms | ||
|
||
def _assert_simplicial(simplices): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please run |
||
|
||
# Initialize a set to keep track of simplices | ||
existing_simplices = set() | ||
|
||
# Initialize a list which is the (sub)filtration | ||
# where the filtration is properly a simplicial | ||
# complex at each point | ||
simplicial_filtration = list() | ||
|
||
# Sort the filtration by the time at which each simplex is | ||
for s,t in sorted(simplices, key = lambda x: (x[1],x[0])): | ||
|
||
# Sort to ensure a uniform representation | ||
sorted_simplex = tuple(sorted(s)) | ||
|
||
if sorted_simplex in existing_simplices: | ||
continue | ||
|
||
else: | ||
existing_simplices.add(sorted_simplex) | ||
|
||
# Don't sort in the final filtration because the | ||
# user might care about the order in which the | ||
# 0-faces are listed | ||
|
||
simplicial_filtration.append((s,t)) | ||
|
||
return simplicial_filtration | ||
|
||
|
||
def _simplices_to_sparse_pivot_column(ordered_simplices, verbose=False): | ||
""" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you help me understand why this one should default to true while the others default to false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thought was that in all of the others, the simplicial complex is being generated in a way that we know it will be a simplicial complex. I thought it would be faster to pass
False
because we don't need to check it. My thought was not that the other ones are nonsimplicial, it's just that we don't need to assert that they are. For this one, we are generating the complex in a way that may not be simplicial. I assumed that most users would want the default behavior to be a simplicial complex, and they could choose to make something more subtle by passingsimplicial=False