mode returns a wrong answer for row vectors
Ben Abbott
bpabbott at mac.com
Sat Mar 15 19:11:05 CDT 2008
On Mar 15, 2008, at 4:48 PM, Thomas Weber wrote:
> Hi,
>
> I'm forwarding below a bug report against Octave 3.0.0.
>
> mode.m makes a distinction between a row and a column vector. I think
> this happens in the "if" statement around line 77, but I'm not sure
> how
> to fix it or what exactly happens there.
>
> ----- Forwarded message from Francesco Potorti`
> <Potorti at isti.cnr.it> -----
>
> From: Francesco Potorti` <Potorti at isti.cnr.it>
> Date: Wed, 12 Mar 2008 12:36:28 +0100
> To: Debian Bug Tracking System <submit at bugs.debian.org>
> Subject: [Pkg-octave-devel] Bug#470632: octave3.0: mode returns a
> wrong
> answer for row vectors
> Organization: ISTI-CNR, via Moruzzi 1, I-56124 Pisa, +39-0503153058
> Reply-To: Francesco Potorti` <Potorti at isti.cnr.it>, 470632 at bugs.debian.org
>
> Package: octave3.0
> Version: 3.0.0-1
> Severity: normal
>
> octave3.0> mode([2 3 1 2 3 4])
> ans = 1
> octave3.0> mode([2 3 1 2 3 4]')
> ans = 2
>
> The second is the correct answer.
> ----- End forwarded message -----
>
> Thanks
> Thomas
There has been some work on reconciling a similar problem for
calculation of quantiles on the thread below.
http://www.nabble.com/Statistics-function-incorrectly-computing-median-tc14644111.html
That work is still in progress, but the part respecting the present
problem has been solved.
Based upon a very superficial examination, it appears the problem can
be resolved by,
perm = 1:ndims(x);
perm(1) = dim;
perm(dim) = 1;
x = permute (x, perm);
sx = size (x);
sx2d = [sx(1), prod (sx(2:end))];
x = reshape (x, sx2d);
# Do the usual for dim==1
.
.
.
sx(1) = 1;
m = reshape (m, sx);
f = reshape (f, sx);
c = reshape (c, sx);
m = ipermute (m, perm);
f = ipermute (f, perm);
c = ipermute (c, perm);
I'm presently distracted by a rather significant build problem for the
most recent mercurial sources on Mac OSX complied using gfortran. If
anyone is inclined to tackle this (mode) problem, please let me know,
Otherwise, I'll get to it in a day or two.
Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20080315/0b462330/attachment.html
More information about the Bug-octave
mailing list