geometry: wrong computation of axes in cov2ellipse

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

geometry: wrong computation of axes in cov2ellipse

Rafael Laboissière
The function cov2ellipse in the geometry package is not computing the
ellipse axes correctly.  The first problem is that the scale of the
axes is wrong.  This can be demonstrated with the code below

   ######################################################################
   function cov2ellipse_demo (K)
       L = chol(K,'lower');
       u = randn(1e3,2)*L';
       elli = cov2ellipse (K);
       figure(1)
       plot(u(:,1),u(:,2),'.r');
       hold on;
       drawEllipse(elli,'linewidth',2);
       hold off;
       axis tight;
   endfunction
   cov2ellipse_demo (K); ## This is what we get with "demo cov2ellipse"
   cov2ellipse_demo (10*K);
   cov2ellipse_demo (0.1*K);
   ######################################################################

This is fixed by taking the square root of the eigenvalues obtained by
svd().

The second problem is that the axis orientation is wrong, evidenced in
the code below:

   ######################################################################
   K = [2 -1; -1 2];
   cov2ellipse_demo (K)
   ######################################################################

This happens because the wrong elements of the eigenvectors are taken.

The patch attached below fixes both problems.

Rafael


------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev

cov2ellipse-fix-axes-scale-and-orientation.patch (433 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: geometry: wrong computation of axes in cov2ellipse

Juan Pablo Carbajal-2
On Sun, Nov 25, 2012 at 2:54 PM, Rafael Laboissiere
<[hidden email]> wrote:

> The function cov2ellipse in the geometry package is not computing the
> ellipse axes correctly.  The first problem is that the scale of the axes is
> wrong.  This can be demonstrated with the code below
>
>   ######################################################################
>   function cov2ellipse_demo (K)
>       L = chol(K,'lower');
>       u = randn(1e3,2)*L';
>       elli = cov2ellipse (K);
>       figure(1)
>       plot(u(:,1),u(:,2),'.r');
>       hold on;
>       drawEllipse(elli,'linewidth',2);
>       hold off;
>       axis tight;
>   endfunction
>   cov2ellipse_demo (K); ## This is what we get with "demo cov2ellipse"
>   cov2ellipse_demo (10*K);
>   cov2ellipse_demo (0.1*K);
>   ######################################################################
>
> This is fixed by taking the square root of the eigenvalues obtained by
> svd().
>
> The second problem is that the axis orientation is wrong, evidenced in the
> code below:
>
>   ######################################################################
>   K = [2 -1; -1 2];
>   cov2ellipse_demo (K)
>   ######################################################################
>
> This happens because the wrong elements of the eigenvectors are taken.
>
> The patch attached below fixes both problems.
>
> Rafael
>
>
> ------------------------------------------------------------------------------
> Monitor your physical, virtual and cloud infrastructure from a single
> web console. Get in-depth insight into apps, servers, databases, vmware,
> SAP, cloud infrastructure, etc. Download 30-day Free Trial.
> Pricing starts from $795 for 25 servers or applications!
> http://p.sf.net/sfu/zoho_dev2dev_nov
> _______________________________________________
> Octave-dev mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/octave-dev
>

Thank you again Rafael!

I applied the patch.

How did you find this bug?

------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev
Reply | Threaded
Open this post in threaded view
|

Re: geometry: wrong computation of axes in cov2ellipse

Rafael Laboissière

* Juan Pablo Carbajal <[hidden email]> [2012-11-27 12:54]:

>
> On Sun, Nov 25, 2012 at 2:54 PM, Rafael Laboissiere <[hidden email]> wrote:
>>
>> The function cov2ellipse in the geometry package is not computing the
>> ellipse axes correctly.  The first problem is that the scale of the axes is
>> wrong.  This can be demonstrated with the code below
>>
>> [snip]
>
> Thank you again Rafael!
>
> I applied the patch.
>
> How did you find this bug?

In the usual way: I tried to use the function and noticed it was buggy.

Rafael




------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev