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

BUG: Fix machine precision errors in eigen value calculation #355

Merged
merged 2 commits into from Mar 7, 2018

Conversation

JoostJM
Copy link
Collaborator

@JoostJM JoostJM commented Mar 7, 2018

If the segmentation in the dataset represents a 2D segmentation, the smallest of the 3 eigenvectors should be 0.
But because a transform to physical coordinates (taking into account rotation and scaling), this can actually compute very small (~1e-16) negative numbers.

This in turn causes an error in numpy.sqrt. This commit implements a 3-fold fix.

  1. Because we do not need the eigen vectors, we can also calculate the eigenvalues using just the scaled coordinates, without rotation. In case of a 2D segmentation, this then results in correct calculation of 0 for the smallest eigen value.
  2. After computation of eigen values. They are checked if they are negative, but > -1e-10. If that is the case, a warning is logged and they are rounded to 0.
  3. Add additional checks to ensure the eigenvectors are not < 0 (effectively < -1e-10) in the feature functions. If that is the case, a warning is logged and nan is returned.

If the segmentation in the dataset represents a 2D segmentation, the smallest of the 3 eigenvectors should be 0.
But because a transform to physical coordinates (taking into account rotation and scaling), this can actually compute very small (~1e-16) negative numbers.

This in turn causes an error in numpy.sqrt. This commit implements a 3-fold fix.

1) Because we do not need the eigen vectors, we can also calculate the eigenvalues using just the scaled coordinates, without rotation. In case of a 2D segmentation, this then results in correct calculation of 0 for the smallest eigen value.
2) After computation of eigen values. They are checked if they are negative, but > -1e-10. If that is the case, a warning is logged and they are rounded to 0.
3) Add additional checks to ensure the eigenvectors are not < 0 (effectively < -1e-10) in the feature functions. If that is the case, a warning is logged and nan is returned.
@JoostJM
Copy link
Collaborator Author

JoostJM commented Mar 7, 2018

fixes #354

@JoostJM JoostJM merged commit 5358d21 into AIM-Harvard:master Mar 7, 2018
@JoostJM JoostJM deleted the eigenvalue-bug branch March 7, 2018 10:44
@JoostJM JoostJM added this to Bugfixes in Feature definitions Mar 13, 2018
@JoostJM JoostJM added the bug label Aug 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Feature definitions
  
Bugfixes
Development

Successfully merging this pull request may close these issues.

None yet

1 participant