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

Add visualization of Stiefel Manifold #1807

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Add visualization of Stiefel Manifold #1807

wants to merge 11 commits into from

Conversation

olokevin
Copy link
Collaborator

@olokevin olokevin commented Jan 29, 2023

Checklist

  • My pull request has a clear and explanatory title.
  • If necessary, my code is vectorized.
  • I added appropriate unit tests.
  • I made sure the code passes all unit tests. (refer to comment below)
  • My PR follows PEP8 guidelines. (refer to comment below)
  • My PR follows geomstats coding style and API.
  • My code is properly documented and I made sure the documentation renders properly. (Link)
  • I linked to issues and PRs that are relevant to this PR.

Description

Add visualization of Stiefel Manifold and corresponding unit test code

Issue

Additional context

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@codecov
Copy link

codecov bot commented Jan 29, 2023

Codecov Report

Merging #1807 (a0bbd4b) into master (1865fd0) will increase coverage by 6.82%.
The diff coverage is 87.98%.

❗ Current head a0bbd4b differs from pull request most recent head bd02e71. Consider uploading reports for the commit bd02e71 to get more accurate results

@@            Coverage Diff             @@
##           master    #1807      +/-   ##
==========================================
+ Coverage   80.29%   87.11%   +6.82%     
==========================================
  Files         121      125       +4     
  Lines       12830    12809      -21     
==========================================
+ Hits        10301    11157     +856     
+ Misses       2529     1652     -877     
Flag Coverage Δ
numpy 87.11% <87.98%> (?)
pytorch ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
geomstats/visualization/stiefel_manifold.py 87.98% <87.98%> (ø)
geomstats/geometry/sub_riemannian_metric.py 30.40% <0.00%> (-62.74%) ⬇️
geomstats/geometry/pullback_metric.py 32.05% <0.00%> (-58.56%) ⬇️
geomstats/learning/geodesic_regression.py 31.17% <0.00%> (-48.70%) ⬇️
...eomstats/information_geometry/fisher_rao_metric.py 21.88% <0.00%> (-46.87%) ⬇️
geomstats/geometry/fiber_bundle.py 66.67% <0.00%> (-28.20%) ⬇️
geomstats/geometry/connection.py 76.98% <0.00%> (-17.76%) ⬇️
geomstats/geometry/riemannian_metric.py 78.63% <0.00%> (-10.34%) ⬇️
geomstats/learning/geometric_median.py 92.31% <0.00%> (-2.56%) ⬇️
geomstats/_backend/pytorch/_common.py
... and 56 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@olokevin olokevin changed the title Yq zhao Add visualization of Stiefel Manifold Jan 31, 2023
Copy link
Collaborator

@ninamiolane ninamiolane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename the ipynb to stiefel.ipynb

@@ -0,0 +1,450 @@
"""Stiefel manifold module."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename file to stiefel.py

from geomstats.visualization import Sphere

# %%
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this in the docstring of the class StiefelSphere

from geomstats.geometry.hypersphere import Hypersphere
from geomstats.visualization import Sphere

# %%
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this unnecessary comment

@@ -0,0 +1,149 @@
"""Stiefel manifold visualization test module."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename this file: test_visualization_stiefel.py

Copy link
Collaborator

@ninamiolane ninamiolane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looking great!

Please submit a review of this PR with the following changes:

  • Instead of copy-pasting code from the visualization of Kendall shape spaces, you should import that code and have your methods call their methods. You will be, in effect, wrapping that code into a new object, which is cleaner.
  • Address DeepSource issues.
  • See my comment regarding the line that you can add to avoid getting the errors in pytorch.
  • Try adding a section "Setup" to your notebook, as in this example, so that the import error goes away.


# %%
"""
Consider <n=3, p=1> Stiefel Manifold.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be n=3, p=2? A pair of two orthonormal vectors in 3D? Double check


class StiefelSphere:
"""
Class used to plot something in Stiefel shape space of 2D triangles.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add reference showing that the stiefel space St(2, 3) is indeed the shape space of triangles.
Look at other code in geomstats repo to see how to properly add a reference in a docstring


References
----------
Absil, Pierre-Antoine. "Stiefel Manifolds and their Applications." (2009)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format this reference, using examples from other docstring in geomstats' code.
Otherwise, this will not render properly on the documentation website of geomstats, geomstats.ai


class StiefelSphere:
"""
Class used to plot something in Stiefel shape space of 2D triangles.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one liner of the docstring should come direclty after """


Attributes
----------
ax : NoneType
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No indent before ax

matplotlib.use("Agg") # NOQA


class TestStiefelManifold(tests.conftest.TestCase):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be TestStiefelSphere or TestStiefelCircle
--> one test class per class being tested, and the classs names should match

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, the names of the test methods do not need to be prefixed by "test_stiefel_circle" or "test_stiefel_sphere" because they are already in a class named TestStiefelCircle or TestStiefelSphere

self.v21 = Stiefel(2, 1)
self.v22 = Stiefel(2, 2)
self.v31 = Stiefel(3, 1)
self.St_sph = StiefelSphere()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no uppercase letters in python, unless the variable is a Class, which it is not here (it is an object)

self.St_cir.add_points(group1_points_to_circle[:, :, 0])
self.St_cir.draw_curve(color="b", lw=3, label="geodesic line")

def test_stifel_circle_draw_tangent_space(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: stiefel not stifel

self.St_sph.clear_points()
self.St_sph.draw_points(self.sph_ax)

def test_stiefel_sphere_draw_mesh(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this line above the test functions that fail in pytorch:
@geomstats.tests.np_only

after importing geomstats.tests at the top of the file.

The github actions errors will go away

def test_stiefel_circle_plot_rendering(self):
"""Test drawing the manifold with regularly sampled data."""
self.St_cir.plot_rendering(self.v21, 100)
# self.St_cir.plot_rendering(self.v22, 100)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rm leftover comment

@review-notebook-app
Copy link

review-notebook-app bot commented Feb 13, 2023

View / edit / reply to this conversation on ReviewNB

ninamiolane commented on 2023-02-13T17:17:55Z
----------------------------------------------------------------

Rename this notebook to stiefel.py (no _)


@review-notebook-app
Copy link

review-notebook-app bot commented Feb 13, 2023

View / edit / reply to this conversation on ReviewNB

ninamiolane commented on 2023-02-13T17:17:56Z
----------------------------------------------------------------

Change "In this presentation" to "Here,"

Change "This rest of the presentation is" to "This notebook is"


@review-notebook-app
Copy link

review-notebook-app bot commented Feb 13, 2023

View / edit / reply to this conversation on ReviewNB

ninamiolane commented on 2023-02-13T17:17:57Z
----------------------------------------------------------------

Line #2.    # begin

Remove the comments here (they are unnecessary)


@review-notebook-app
Copy link

review-notebook-app bot commented Feb 13, 2023

View / edit / reply to this conversation on ReviewNB

ninamiolane commented on 2023-02-13T17:17:58Z
----------------------------------------------------------------

Line #1.    ###########################################################################

Remove unnecessary comments in the code, and put a markdown block with clean text instead.


@review-notebook-app
Copy link

review-notebook-app bot commented Feb 13, 2023

View / edit / reply to this conversation on ReviewNB

ninamiolane commented on 2023-02-13T17:17:59Z
----------------------------------------------------------------

Ditto: remove comments and put a well-written text in a markdown cell instead


@review-notebook-app
Copy link

review-notebook-app bot commented Feb 13, 2023

View / edit / reply to this conversation on ReviewNB

ninamiolane commented on 2023-02-13T17:18:00Z
----------------------------------------------------------------

Ditto re comments and text


@review-notebook-app
Copy link

review-notebook-app bot commented Feb 13, 2023

View / edit / reply to this conversation on ReviewNB

ninamiolane commented on 2023-02-13T17:18:00Z
----------------------------------------------------------------

NIT: implemented


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

Successfully merging this pull request may close these issues.

None yet

2 participants