octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

compatibility of cov - past discussions and how to interpret for current


From: Nicholas Jankowski
Subject: compatibility of cov - past discussions and how to interpret for current bugfix?
Date: Tue, 17 Jan 2017 12:32:01 -0500

I was revisiting my patch for bug #48690 [1].  I initially thought cov
to be the simplest since it only takes a 2d argument, but I missed the
multiple argument aspect. trying to cover that, I just realized that
tests I'm generating to try to maintain matlab compatibility may be
running afoul of the previous decision for a planned
non-compatibility.

I see a few past discussions [2-3], but the short version being that
the following is expected to be different:
cov([1 2 3 4],[1 2 3 4])
Octave:  ans = 1.6667
Matlab: ans = [1.6667,1.6667; 1.6667,1.6667]

and here's the blurb from the help:

Compatibility Note:: Octave always treats rows of X and Y as
     multivariate random variables.  For two inputs, however, MATLAB
     treats X and Y as two univariate distributions regardless of their
     shapes, and will calculate 'cov ([X(:), Y(:)])' whenever the number
     of elements in X and Y are equal.  This will result in a 2x2
     matrix.  Code relying on MATLAB's definition will need to be
     changed when running in Octave.



So, how this relates to the bug:

Matlab output, desired compatibility the focus of the bug report:

cov ([]) = NaN
cov (NaN) = NaN

but, as with the other statistics functions, Matlab output gets odd
for other forms of empty and nan:

cov([],[]) = NaN(2,2)

cov(NaN(0,2)) = NaN(2,2)
cov(NaN(2,0)) = []

I figured out a fairly simple ruleset for producing compatible output
for the other stat functions, but here I'm not sure what desired
output should be based on the previous discussions. scalar? matrix?


also, going through tests:

1-
current test:
%!error cov (1, 3)
(currently errors for any scalar for y that is not 0 or 1. seems to
not accept a scalar y if nargin==2. is this intended?)

matlab output
>> cov(1,3)
ans =
     0     0
     0     0

(first issue is this is not an error, second is that scalars produce a
matrix output, which I believe relates to the previous compatibility
discussion. so I'm not sure what the 'correct' output should be. Leave
it an error? correct it to a scalar 0? )

2 -
current output:
>> cov (5, [1 2])
ans = 0
(code at line 97 shortcuts any other code if x is scalar to produce a 0 output)

matlab output:
>> cov (5,[1 2])
Error using cov (line 107)
The number of elements in x and y must match.



So, summary: there seemed to be a consensus years ago to keep the
incompatibility. with that in mind, what should target output look
like for this 'compatibility' bugfix?

Nick J.


[1] http://savannah.gnu.org/bugs/?48690
[2] 
http://octave.1599824.n4.nabble.com/covariance-matrix-td1607376.html#a1607378
[3] http://octave.1599824.n4.nabble.com/cov-x-y-matrix-or-number-td4465087.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]