You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @DominikMuhle
Thanks for your work on this project. I noticed that the confidence_ellipse function uses pearson correlation and a fixed 45-degree rotation instead of calculating the ellipse from eigenvectors and eigenvalues. Could you clarify why this approach was chosen?
Thanks!
def confidence_ellipse(
mean: Tuple[float, float],
cov: torch.Tensor,
ax: Axes,
scale: float = 3.0,
linewidth: float = 1.0,
facecolor: str = "none",
**kwargs
):
"""
Create a plot of the covariance confidence ellipse of *x* and *y*.
Parameters
----------
x, y : array-like, shape (n, )
Input data.
ax : matplotlib.axes.Axes
The axes object to draw the ellipse into.
scale : float
Scale the covariance sizes of all for better visualization.
**kwargs
Forwarded to `~matplotlib.patches.Ellipse`
Returns
-------
matplotlib.patches.Ellipse
"""
n_std = 3.0
pearson = cov[0, 1] / torch.sqrt(cov[0, 0] * cov[1, 1])
# Using a special case to obtain the eigenvalues of this
# two-dimensional dataset.
ell_radius_x = torch.sqrt(1 + pearson).item()
ell_radius_y = torch.sqrt(1 - pearson).item()
ellipse = Ellipse(
(0, 0), width=ell_radius_x * 2, height=ell_radius_y * 2, facecolor=facecolor, linewidth=linewidth, **kwargs
)
# Calculating the standard deviation of x from
# the squareroot of the variance and multiplying
# with the given number of standard deviations.
scale_x = torch.sqrt(cov[0, 0]).item() * n_std * scale
mean_x = mean[0]
# calculating the standard deviation of y ...
scale_y = torch.sqrt(cov[1, 1]).item() * n_std * scale
mean_y = mean[1]
transf = transforms.Affine2D().rotate_deg(45).scale(scale_x, scale_y).translate(mean_x, mean_y)
ellipse.set_transform(transf + ax.transData)
return ax.add_patch(ellipse)
```
The text was updated successfully, but these errors were encountered:
RBJin
changed the title
Clarification on Using Pearson Correlation and Fixed Rotation in confidence_ellipse
Why is pearson correlation and a fixed rotation used in the confidence_ellipse function for visualizing covariance
Aug 28, 2024
Hi @DominikMuhle
Thanks for your work on this project. I noticed that the
confidence_ellipse
function uses pearson correlation and a fixed 45-degree rotation instead of calculating the ellipse from eigenvectors and eigenvalues. Could you clarify why this approach was chosen?Thanks!
The text was updated successfully, but these errors were encountered: