bugGNU Octave - Bugs: bug #50377, [octave forge] (statistics) pdist2...


bug #50377: [octave forge] (statistics) pdist2 function returns complex results

Submitted by:  Georg Wiora <gwiora>
Submitted on:  Wed 22 Feb 2017 08:09:21 AM UTC  
Category:  Octave Forge Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  None Assigned to:  None
Originator Name:  gwiora Open/Closed:  Open
Release:  4.2.0 Operating System:  Any

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Wed 01 Mar 2017 03:13:13 PM UTC, comment #3:

I reviewed your "max()" suggestion and now aggree that this is the better solution. The code segement below should the be changed to the following code:

Georg Wiora <gwiora>
Wed 22 Feb 2017 09:55:15 AM UTC, comment #2:

I thought about that too. I think the numeric result is in both cases equal to a precision of eps. But the abs function is in terms of memory use and complexity maybe more efficient than the solution using max().

Please correct me if my understanding is wrong. The max solution is definitely "more" precise in its result.

Georg Wiora <gwiora>
Wed 22 Feb 2017 09:47:51 AM UTC, comment #1:

What about using max (., 0) instead of abs (.) ?

Guillaume <gyom>
Wed 22 Feb 2017 08:09:21 AM UTC, original submission:

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:

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_

I have appended a patched version of pdist2.m.

Georg Wiora <gwiora>


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

Attach Files:

Attached Files
file #39810:  pdist2.m added by gwiora (5KiB - application/octet-stream - Patched version of pdist2 function.)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by gyom (Posted a comment)
  • -email is unavailable- added by gwiora (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-08-12 jwe Summarypdist2 function returns complex results => [octave forge] (statistics) pdist2 function returns complex results
    2017-02-22 gwiora Attached File- => Added pdist2.m, #39810

    Back to the top

    Powered by Savane 3.3