Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Covariance Matrix of an Ellipse

I've been trying to solve a problem. I'm surprised I haven't been able to find anything really useful on the net.

I know that from the eigenvalues of the covariance matrix of the ellipse, the major and the minor axis of the ellipse can be computed. As the following:

a1 = 2*sqrt(e1)
a2 = 2*sqrt(e2)

where a1 and a2 are the major and minor axis, e1 and e2 are the eigenvalues of covariance matrix.

My question is: given an edge points (xi,yi) of the image ellipse, how it possible to find the 2×2 covariance matrix of that ellipse?

like image 469
Omar14 Avatar asked Mar 03 '14 12:03

Omar14


People also ask

What is a covariance matrix?

The covariance matrix can be considered as a matrix that linearly transformed some original data to obtain the currently observed data. In a previous article about eigenvectors and eigenvalues we showed that the direction vectors along such a linear transformation are the eigenvectors of the transformation matrix.

What is the relationship between the ellipse axis and variance?

Table 1. Covariance matrix of the data shown in Figure 2 Furthermore, it is clear that the magnitudes of the ellipse axes depend on the variance of the data. In our case, the largest variance is in the direction of the X-axis, whereas the smallest variance lies in the direction of the Y-axis.

What is the difference between eigen vectors and covariance ellipses?

Covariance Ellipses. It is more precise to say that the eigen vectors describe the maximum variance portfolio and the next largest variance portfolio that has zero covariance with the first portfolio, but when there are only two eigen values, this amounts to the same thing.

What is the difference between eigenvalues and covariance matrix?

). The eigenvalues represent the spread in the direction of the eigenvectors, which are the variances under a rotated coordinate system. By definition a covariance matrix is positive definite therefore all eigenvalues are positive and can be seen as a linear transformation to the data.


1 Answers

Just by pure reverse engineering (I'm not familiar anymore with this material), I can do this:

%// Generate circle
R = 189;
t = linspace(0, 2*pi, 1000).';
x = R*cos(t);
y = R*sin(t);

%// Find the radius?
[~,L] = eig( cov([x,y]) );

%// ...hmm, seems off by a factor of sqrt(2)
2*sqrt( diag(L) )        

%// so it would come out right when I'd include a factor of 1/2 in the sqrt():
2*sqrt( diag(L)/2 )        

So, let's test that theory for general ellipses:

%// Random radii
a1 = 1000*rand;
a2 = 1000*rand;

%// Random rotation matrix
R = @(a)[
    +cos(a) +sin(a); 
    -sin(a) +cos(a)];

%// Generate pionts on the ellipse 
t = linspace(0, 2*pi, 1000).';
xy = [a1*cos(t)  a2*sin(t);] * R(rand);

%// Find the deviation from the known radii
%// (taking care of that the ordering may be different)
[~,L] = eig(cov(xy));
min(abs(1-bsxfun(@rdivide, 2*sqrt( diag(L)/2 ), [a1 a2; a2 a1])),[],2)

which always returns something acceptably small.

So, seems to work :) Can anyone verify that this is indeed correct?

like image 152
Rody Oldenhuis Avatar answered Sep 17 '22 22:09

Rody Oldenhuis