octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #50377] pdist2 function returns complex result


From: Georg Wiora
Subject: [Octave-bug-tracker] [bug #50377] pdist2 function returns complex results
Date: Wed, 22 Feb 2017 03:09:22 -0500 (EST)
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0

URL:
  <http://savannah.gnu.org/bugs/?50377>

                 Summary: pdist2 function returns complex results
                 Project: GNU Octave
            Submitted by: gwiora
            Submitted on: Wed 22 Feb 2017 09:09:21 AM CET
                Category: Octave Forge Package
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Inaccurate Result
                  Status: None
             Assigned to: None
         Originator Name: gwiora
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 4.2.0
        Operating System: Any

    _______________________________________________________

Details:

For certain cases the pdist2 function from statistics package may return
complex results leading to unexpected behaviour in following calculations. The
complex results are caused by a negative result for "dists" in the distEucSq()
local function:


function dists = distEucSq (x, y)
  xx = sumsq (x, 2);
  yy = sumsq (y, 2)';
  dists = bsxfun (@plus, xx, yy) - 2 * x * (y');
endfunction


The negative results are caused by rounding errors and are in the range of
-1e-16. A single negative value in dists array causes the whole result array
in case of euclidian distance calculation (default for pdist2) to become
complex data type.

Suggested solution:
Add an abs() function for squared distances_


function dists = distEucSq (x, y)
  xx = sumsq (x, 2);
  yy = sumsq (y, 2)';
  dists = abs(bsxfun (@plus, xx, yy) - 2 * x * (y'));
endfunction


I have appended a patched version of pdist2.m.




    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Wed 22 Feb 2017 09:09:21 AM CET  Name: pdist2.m  Size: 5kB   By: gwiora
Patched version of pdist2 function.
<http://savannah.gnu.org/bugs/download.php?file_id=39810>

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?50377>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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