[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #42764] squareform in statistics package retur
From: |
JD Walsh |
Subject: |
[Octave-bug-tracker] [bug #42764] squareform in statistics package returns column vector, Matlab returns row vector |
Date: |
Fri, 07 Nov 2014 17:36:34 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0 Iceweasel/33.0 |
Follow-up Comment #1, bug #42764 (project octave):
TL;DR I've attached a patch to bring `squareform' into line with MatLab. With
this patch, it tests arguments and returns a row vector (when appropriate).
The lack of argument testing in the current `squareform' creates problems with
both vector and matrix input. Currently, `squareform' doesn't complain if the
input matrix fails to match the requirements of a distance matrix: a square
symmetric matrix with zeros along the diagonal. For example,
`squareform([1,2,3; 4,5,6; 7,8,9])' returns
4
7
8
When `squareform' is asked to convert a vector `x' to an n by n matrix, it
finds the value of n by solving the quadratic equation n^2 - n - 2k = 0, where
k = length(x). Because the current `squareform' does no error checking, it is
possible for `n' to take non-integer values. The function `zeros' which
creates the matrix strips off non-integers without displaying an error. This
can lead to unexpected results in the returned matrix. For instance,
`squareform ([1,2,3,4])' returns
0 1 2
1 0 3
2 3 0
In both the above cases, MatLab's `squareform' returns an error and aborts
computation.
Since the most recent maintainer of `squareform' stepped down in 2011, I have
attached a patch for these issues. My patched `squareform' converts matrices
to row vectors instead of column vectors. It also checks for incorrect input
types, matrices with an incorrect format, and vectors of an invalid length.
The MatLab description for `squareform' states that the routine requires a
symmetric matrix. However, MatLab 2013b does not throw an error when a
non-symmetric matrix is used as input. To maintain compatibility with existing
MatLab code which may rely on this lapse, when a non-symmetric matrix is
encountered by my version of `squareform', it gives a warning (which the user
can choose to turn off).
The patched `squareform' also includes minor formatting changes to bring the
code more into line with Octave's current recommendations.
(file #32389)
_______________________________________________________
Additional Item Attachment:
File name: squareform.patch Size:6 KB
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?42764>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #42764] squareform in statistics package returns column vector, Matlab returns row vector,
JD Walsh <=