- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 6.9k
 
More intuitive way of plot_covariance_ellipse() #407
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
More intuitive way of plot_covariance_ellipse() #407
Conversation
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.
Thank you for your PR. I agree the original code is not intuitive. Let's fix it. I have some comments. PTAL.
| rot = np.array([[math.cos(angle), math.sin(angle)], | ||
| [-math.sin(angle), math.cos(angle)]]) | ||
| angle = math.atan2(eigvec[1, bigind], eigvec[0, bigind]) | ||
| rot = np.array([[math.cos(angle), -math.sin(angle)], | 
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 please use scipy Rot?
| rot = Rot.from_euler('z', angle).as_matrix()[0:2, 0:2] | 
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.
Ok, I've changed the rotation matrix to scipy.spatial.transform.Rotation.from_euler() in 7a49ca9
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.
Thank you for fixing it. This is the last review. PTAL.
| x = [a * math.cos(it) for it in t] | ||
| y = [b * math.sin(it) for it in t] | ||
| angle = math.atan2(eig_vec[big_ind, 1], eig_vec[big_ind, 0]) | ||
| angle = math.atan2(eigvec[1, bigind], eigvec[0, bigind]) | 
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.
typo? eigvec -> eig_vec, bigind -> big_ind?
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.
Sorry, those were typos. I fixed it in a0d1c74.
| x = [a * math.cos(it) for it in t] | ||
| y = [b * math.sin(it) for it in t] | ||
| angle = math.atan2(eig_vec[big_ind, 1], eig_vec[big_ind, 0]) | ||
| angle = math.atan2(eigvec[1, bigind], eigvec[0, bigind]) | 
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.
typo? eigvec -> eig_vec, bigind -> big_ind?
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.
Sorry, those were typos. I fixed it in a0d1c74.
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.
LGTM. Thank you so much for your contribution!!
Reference issue
What does this implement/fix?
This change suggests a more intuitive way of
plot_covariance_ellipse()inextended_kalman_filter.pyandunscented_kalman_filter.py. (This change doesn't affect the result.)In
plot_covariance_ellipse(),np.linalg.eig(Pxy)returnseigvalandeigveclike below.So, I think it would be more plausible if the
angleof the ellipse and therotmatrix are calculated byAdditional information
The result is the same between before and after.
Before:
↓
After:
The reason why is because the eigenvectors v1 and v2 are orthogonal and the norm is 1.
Therefore, v2_x = -v1_y,
So,