8000 Simplify computations of the FrechetMean for the ElasticMetric by ninamiolane · Pull Request #1592 · geomstats/geomstats · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Simplify computations of the FrechetMean for the ElasticMetric #1592

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

Merged
merged 25 commits into from
Jun 27, 2022

Conversation

ninamiolane
Copy link
Collaborator
@ninamiolane ninamiolane commented Jun 22, 2022

This PR aimed to simplify the computation of the FrechetMean for the ElasticMetric, and ended up solving a series of bugs on elastic curves.

The method for the FrechetMean on elastic curves works as follows:

  • transforming the data point through the f transform
  • computing their linear mean
  • transforming the mean back into the curve space with the f transform inverse.

This PR also:

  • adds better docstrings for the SRVMetric and the ElasticMetric
  • brings back unit-tests about the f_transform and polar coordinates that were deleted
  • vectorize the computations of the functions cartesian <> polar coordinates , and f_transform with its inverse
  • adds corresponding unit-tests

Checklist

  • My pull request has a clear and explanatory title.
  • If neccessary, my code is vectorized.
  • I have added apropriate unit tests.
  • I have 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 have linked to issues and PRs that are relevant to this PR.

Description

Issue

Additional context

@ninamiolane ninamiolane marked this pull request as draft June 22, 2022 13:58
@ninamiolane ninamiolane requested a review from alebrigant June 22, 2022 19:12
@codecov
Copy link
codecov bot commented Jun 22, 2022

Codecov Report

Merging #1592 (781741d) into master (ae20cf4) will increase coverage by 1.06%.
The diff coverage is 77.00%.

@@            Coverage Diff             @@
##           master    #1592      +/-   ##
==========================================
+ Coverage   88.65%   89.70%   +1.06%     
==========================================
  Files         107      107              
  Lines       10694    10669      -25     
==========================================
+ Hits         9480     9570      +90     
+ Misses       1214     1099     -115     
Flag Coverage Δ
numpy 87.04% <77.00%> (+0.54%) ⬆️
pytorch 79.75% <75.00%> (?)
tensorflow ?

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

Impacted Files Coverage Δ
geomstats/geometry/discrete_curves.py 88.42% <74.73%> (+9.76%) ⬆️
geomstats/learning/frechet_mean.py 95.36% <100.00%> (ø)
geomstats/errors.py 88.89% <0.00%> (-11.11%) ⬇️
geomstats/learning/geodesic_regression.py 81.82% <0.00%> (-3.89%) ⬇️
geomstats/geometry/special_euclidean.py 88.44% <0.00%> (-0.48%) ⬇️
geomstats/_backend/tensorflow/linalg.py
geomstats/_backend/tensorflow/random.py
geomstats/_backend/tensorflow/autodiff.py
geomstats/_backend/tensorflow/__init__.py
geomstats/_backend/pytorch/random.py 80.96% <0.00%> (ø)
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f986828...781741d. Read the comment docs.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@ninamiolane ninamiolane marked this pull request as ready for review June 23, 2022 18:47
@ninamiolane
Copy link
Collaborator Author

The failing tests are not related to this PR.

Copy link
Collaborator
@alebrigant alebrigant left a comment

Choose a reason for hiding this comment

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

Looks good to me ! I may be missing something, but the version to which the changes are compared does not seem to be the current version of the master branch.

@@ -464,7 +465,7 @@ def __init__(
" equipped with a metric."
)
self.ambient_manifold = ambient_manifold
self.l2_metric = L2CurvesMetric(ambient_manifold=ambient_manifold)
self.l2_curve_metric = L2CurvesMetric(ambient_manifold=ambient_manifold)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe rename to l2_curves_metric for coherence, or L2CurvesMetric to L2CurveMetric?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, done!

@@ -670,7 +671,7 @@ def f_transform_inverse(self, f, starting_point):
)
if gs.ndim(f) != gs.ndim(starting_point):
starting_point = gs.to_ndarray(starting_point, to_ndim=f.ndim, axis=-2)
self.l2_metric
self.l2_curve_metric
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this line do ? I don't see it in the current version of the master branch. For some reason, the current version used to compare changes in this PR does not seem to correspond to the current version of the master branch.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was a left over,thanks for catching it

distance = 2 * self.b * gs.arccos(gs.clip(cosine, -1, 1))
else:
distance = l2_dist(f_1, f_2)
# elastic_metric.dist
Copy link
Collaborator

Choose a reason for hiding this comment

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

Leftover comments ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, thanks

@ninamiolane ninamiolane merged commit 783ad01 into geomstats:master Jun 27, 2022
@ninamiolane ninamiolane deleted the curv-refactor2 branch June 27, 2022 15:54
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

Successfully merging this pull request may close these issues.

2 participants
0