bugGNU Octave - Bugs: bug #40751, cov(x, x) doesn't return the same...

 
 

bug #40751: cov(x, x) doesn't return the same result as in Matlab

Submitter:  Julien Bect <jbect>
Submitted:  Fri 29 Nov 2013 04:56:22 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Wont Fix Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 03 Jan 2014 08:37:56 PM UTC, comment #7: 

I added a note documenting the intentional Matlab incompatability to cov.m in this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/48dafd739840).  Closing report.

Rik <rik5>
Group administrator
Mon 02 Dec 2013 01:46:08 PM UTC, comment #6: 

PMFJI
cov's doc string (help cov) doesn't explicitly mention the Matlab incompatibility.

From my own experience, supported by the discussion in the mentioned thread, I think Octave's behavior is the preferred choice. I never used ML's cov, otherwise I would surely have hit this limitation.

Could this be fixed with a 4th input argument for cov turning ML compatible behavior on/off? (+ similar 3rd arg in corrcoef as well?), default value TBA?

Philip Nienhuis <philipnienhuis>
Group Member
Sun 01 Dec 2013 06:40:52 PM UTC, comment #5: 

Yes, I think it should be documented.  I thought the doc string for cov already mentioned this incompatibility.

It's also fine with me if we revisit whether we should remove this incompatibility.  But whatever we do, we should NOT should make any change to cov on the stable branch for the 3.8 release.

John W. Eaton <jwe>
Group administrator
Sun 01 Dec 2013 05:45:56 PM UTC, comment #4: 

Ok, sorry about that, I hadn't found these threads.

Would it be acceptable to document this intentional incompatibility somewhere, e.g., in the help text of the function or at least as a comment in the code ?

Julien Bect <jbect>
Sun 01 Dec 2013 04:52:35 PM UTC, comment #3: 

This has come up a number of times in the past and we have always decided to keep Octave's definition of cov.

Please take a look at:

http://octave.1599824.n4.nabble.com/Re-cov-m-patch-td4466691.html

and the thread that it references:

http://octave.1599824.n4.nabble.com/covariance-matrix-td1607376.html#a1607378

John W. Eaton <jwe>
Group administrator
Sun 01 Dec 2013 08:12:36 AM UTC, comment #2: 

As far as I can tell, Matlab's cov() has always behaved like this.

corr(), on the other hand, has a different behaviour. Perhaps because it is a function from the statistics toolbox, not a base Matlab function.

By the way, corrcoef() suffers from exactly the same problem. (Why is there currently a warning indicating that corrcoef will be removed in a future version of Octave ?)

So, it seems that both cov() and corrcoef() have to be fixed. In fact, corrcoef() should be fixed automatically once cov() is fixed, since it is based on it.

I will do this when I have time, if nobody does it before ;-)

Julien Bect <jbect>
Sun 01 Dec 2013 06:51:27 AM UTC, comment #1: 

According to Matlab's documentation, cov (x,y) is equivalent to


cov ([x(:), y(:)]


and in Octave doing


x = reshape ((1:16).^2, 4, 4);
cov ([x(:), x(:)])
ans =

   6.9315e+03   6.9315e+03
   6.9315e+03   6.9315e+03


I don't know if this is a recent change in Matlab's behavior or not, but the fix looks simple.  The m-file can just be changed to use the new definition.

Rik <rik5>
Group administrator
Fri 29 Nov 2013 04:56:22 PM UTC, original submission:  

In Octave 3.7.7+ I get:


>>  x = reshape ((1:16).^2, 4, 4); cov (x, x)
ans =

     43.000    109.667    176.333    243.000
    109.667    283.000    456.333    629.667
    176.333    456.333    736.333   1016.333
    243.000    629.667   1016.333   1403.000


In Matlab R2012a:


>> x = reshape ((1:16).^2, 4, 4); cov (x, x)

ans =

   1.0e+03 *

    6.9315    6.9315
    6.9315    6.9315


Julien Bect <jbect>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by jbect (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-01-03 rik5 StatusNone Wont Fix
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code