In my last post about Bivariate Normal Distributions [BVD] I have discussed why contour lines of a BVD’s probability density function [pdf] are concentric ellipses. These contour ellipses are defined by constant values of the so called Mahalanobis distance. In addition, I have discussed a method to create these ellipses from values of the elements of the BVD’s (variance-) covariance matrix. The method was based on an eigendecomposition of the covariance matrix and respective eigenvalues and eigenvectors. However, practical evaluations in Machine Learning contexts sometimes require an explicit parameterization of the x-, y-coordinates of points on a contour ellipse.
Below, I give you a parameterization of the (x,y)-coordinates of points on a BVD’s contour ellipse. The parameterization will be given in terms of the Mahalanobis distance and an angle 0 ≤ φ ≤ 2π. The approach is based on previous results regarding a Cholesky decomposition of the covariance matrix (or its inverse, if you like); see this previous post.
Related posts
- Bivariate Normal Distribution – Mahalanobis distance and contour ellipses
- Bivariate normal distribution – derivation by linear transformation of a random vector of two independent Gaussians
- Bivariate normal distribution – explicit reconstruction of a BVD random vector via Cholesky decomposition of the covariance matrix
Reminder 1: Density function of a Bivariate Normal Distribution
I summarize some results about BVDs derived in other posts of this blog. For the sake of simplicity, I will only discuss BVDs centered in a Cartesian coordinate system [CCS]. The probability density function g2c(x,y) of a BVD and a respective random vector V = (X,Y)T (composed of two statistical variables X and Y) can be written as:
ρ is the Pearson correlation coefficient of the statistical variables X and Y (see below). σx and σy are standard deviations for the X– and Y-distributions. Using the following notations
and inserting the symmetric matrix Σ-1
we can rewrite the density of a centered BVD ( μ = 0) in the form
T symbolizes the transposition operation. The inverse Σ of Σ-1 is the variance-covariance matrix, with ρ coupling X and Y :
We require that Σ and Σ-1 are invertible matrices to avoid a discussion of so called degenerate cases (where the ellipse collapses to a 1-dimensional object). ρ is related to the covariance of the distributions X,Y:
g2c(x,y) depends on the inverse of Σ, only. The scalar dm given by the exponent of a BVD’s pdf
is called Mahalanobis distance. Setting dm = const. defines a contour line. Reason: A quadratic form like
(for a symmetric, invertible and positive definite matrix Σ-1) defines vectors whose end-points reside on the border of a centered ellipse. The contour ellipses of a centered BVD are concentric. Their half-axes and orientation in the CCS can be calculated with the help of the eigenvalues, eigenvectors of Σ-1 or Σ. See ; see this post for details and formulas.
Reminder 2: Cholesky decomposition of the covariance matrix and explicit construction of a BVD’s random vector
In yet another post, we saw that a decomposition of a symmetric, real valued matrices Σ-1 or Σ is not unique. Instead of an eigendecomposition we can also apply a Cholesky decomposition. It involves a lower triangular, real-valued matrix U, which fulfills
As our Σ is positive definite, the Cholesky decomposition into triangular matrices is unique – and U‘s diagonal contains positive values, only. With the help of U, the random vector V = (X, Y)T of a centered BVD (with marginals X and Y) can be created in the following explicit form from a random vector Z = (Z1, Z2)T of two independent centered Gaussians Z1, Z2:
Application of Cholesky decomposition to vectors z defining a contour of Z
As we have seen in other posts in this blog, vectors v of a BVD can in general be generated by a linear transformation of vectors z pointing to a contour line of the pdf of Z by some positive-definite, real-value matrix M:
Vectors z pointing to a contour line of the pdf for Z are thereby mapped to vector v fulfilling
Among other valid solutions, we can set M = U. (In the named post on the Cholesky decomposition of Σ, I have discussed where this degree of freedom comes from.) This in turn means means that we can pick concrete vectors z with end-points on a circle with radius r and apply the transformation (11) to get our contour line determined by dm = r in the target BVD. We can set the components of such z-vectors to
Using transformation (11) we get for the set of contour vectors vc ( r =const., φ )
This is a very convenient parameterization of the contour ellipse for dm = r – given by parameters coming from the BVD’s covariance matrix Σ and an variable angle φ. It can easily be handled in numerical applications.
Check of the Mahalanobis distance
We check that the transformed vectors vc really fulfill dm = r. We indeed get
As expected.
Steps to construct BVD contour ellipses for a defined Mahalanobis distance
We have found a simple method to numerically construct a contour ellipse for a given constant value r of the Mahalanobis distance dm= r :
Method based on Cholesky decomposition
- Step 1: Get the parameters of the (approximate) BVD’s central covariance matrix. If necessary, determine them numerically from given data.
- Step 2: Take vectors z = ( r* cosφ, r* sinφ)T for a sufficiently dense covering of 0 ≤ φ ≤ 2π.
- Step 3: Apply the transformation given by eqs. (15) and (16) to these vectors z and get a list of transformed vectors v.
- Step 4: Plot the end-points of the vectors v in a coordinate system.
Conclusion
The Cholesky decomposition and a resulting vector transformation is helpful to construct contour ellipses of a BVD for a defined Mahalanobis distance dm with the help of the elements of the BVD’s covariance matrix. The necessary are relatively simple to implement. In a forthcoming post we will use a respective procedure to get a clearer impression of the effects of covariance matrix parameters on the shape of contour ellipses.
Stay tuned …