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

 
 

bug #65178: [octave forge] (statistics) pdist2 BIST failures

Submitter:  Rafael Laboissière <rlaboiss>
Submitted:  Wed 17 Jan 2024 05:44:01 PM UTC
   
 
Category:  Octave Forge Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  None Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * other Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 19 Jan 2024 12:50:40 AM UTC, comment #5: 

If I remove the comma at line 318 of pdist2.m
and add "D14 = D(1,2) - D(4,2)"

D = reshape (D, size (Y, 1), size (X, 1))'
D14 = D(1,2) - D(4,2)


Then do

octave:1> format long
octave:2> x = [1, 1, 1; 2, 2, 2; 3, 3, 3];
octave:3> y =  [0, 0, 0; 1, 2, 3; 0, 2, 4; 4, 7, 1];
octave:4> [D, I] = pdist2 (y, x, "mahalanobis", "smallest", 2)


then on machine where the test passes I see

D =

   2.121320343559651   4.242640687119303   6.363961030678953
   1.224744871391590   2.449489742783189   4.415880433163943
   3.240370349203942   4.898979485566378   6.819090848492960
   2.738612787525838   4.242640687119302   6.123724356957971

D14 = 8.881784197001252e-16
D =

   1.224744871391590   2.449489742783189   4.415880433163943
   2.121320343559651   4.242640687119302   6.123724356957971

I =

   2   2   2
   1   4   4


and on the machine where the test fail:


D =

   2.121320343559651   4.242640687119303   6.363961030678956
   1.224744871391590   2.449489742783189   4.415880433163943
   3.240370349203942   4.898979485566378   6.819090848492960
   2.738612787525845   4.242640687119303   6.123724356957972

D14 = -8.881784197001252e-16
D =

   1.224744871391590   2.449489742783189   4.415880433163943
   2.121320343559651   4.242640687119303   6.123724356957972

I =

   2   2   2
   1   1   4


I am not sure if this is a bug with an algorithm (which should be robust WRT such things; or just the test case data needs to be changed.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Wed 17 Jan 2024 09:39:41 PM UTC, comment #4: 

The same 3 failures on Fedora39/aarch64. They are fine on Fedora39/x86_64

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Wed 17 Jan 2024 07:54:32 PM UTC, comment #3: 

I have 3 failures on aarch64 (raspberry pi 4) Ubuntu 23.10:

 ***** test
 d = [1.2247, 2.4495, 4.4159; 2.1213, 4.2426, 6.1237];
 i = [2, 2, 2; 1, 4, 4];
 [D, I] = pdist2 (y, x, "mahalanobis", "smallest", 2);
 assert ({D, I}, {d, i}, 1e-4);
!!!!! test failed
ASSERT errors for:  assert (cond {i},expected {i},tol)

  Location  |  Observed  |  Expected  |  Reason
   (2,2)          1            4         Abs err 3 exceeds tol 0.0001 by 3
shared variables
    x =

       1   1   1
       2   2   2
       3   3   3

    y =

       0   0   0
       1   2   3
       0   2   4
       4   7   1

    xx =

       1   2   3
       4   5   6
       7   8   9
       3   2   1

***** test
 d = [3.2404, 4.8990, 6.8191; 2.7386, 4.2426, 6.3640];
 i = [3, 3, 3; 4, 1, 1];
 [D, I] = pdist2 (y, x, "mahalanobis", "largest", 2);
 assert ({D, I}, {d, i}, 1e-4);
!!!!! test failed
ASSERT errors for:  assert (cond {i},expected {i},tol)

  Location  |  Observed  |  Expected  |  Reason
   (2,2)          4            1         Abs err 3 exceeds tol 0.0001 by 3
shared variables
    x =

       1   1   1
       2   2   2
       3   3   3

    y =

       0   0   0
       1   2   3
       0   2   4
       4   7   1

    xx =

       1   2   3
       4   5   6
       7   8   9
       3   2   1

***** test
 yy = [1 2 3;5 6 7;9 5 1];
 d = [0, 8.4853, 18.0416; 2.4495, 10.0995, 19.4808; ...
      2.4495, 10.6771, 19.7104; 2.4495, 10.6771, 20.4573];
 i = [2, 2, 2; 1, 4, 4; 4, 1, 1; 3, 3, 3];
 [D, I] = pdist2 (y, yy, "mahalanobis", "smallest", 4);
 assert ({D, I}, {d, i}, 1e-4);
!!!!! test failed
ASSERT errors for:  assert (cond {i},expected {i},tol)

  Location  |  Observed  |  Expected  |  Reason
   (3,1)          3            4         Abs err 1 exceeds tol 0.0001 by 1
   (4,1)          4            3         Abs err 1 exceeds tol 0.0001 by 1
shared variables
    x =

       1   1   1
       2   2   2
       3   3   3

    y =

       0   0   0
       1   2   3
       0   2   4
       4   7   1

    xx =

       1   2   3
       4   5   6
       7   8   9
       3   2   1


The test passes on the same Ubuntu 23.10 but on x86_64 (Intel(R) Core(TM)2 Duo CPU     T9900 ).

So my guess is that some of the data is marginal and the results depends on FP unit in use (core-II uses SSE and my other systems have AVX).

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Wed 17 Jan 2024 06:09:57 PM UTC, comment #2: 

Also passes on octave 8.4 (from flatpak).
In case it matters:
Flatpak has Openblas 0.3.25 and lapack 3.11.

(Host linux has Openblas 0.3.21 and lapack 3.9)

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Wed 17 Jan 2024 06:01:00 PM UTC, comment #1: 

What is your octave version? With 9.0.1 it passes for me:

octave:3> pkg load statistics
octave:4> test pdist2 verbose
>>>>> /home/dima/.local/share/octave/api-v58/packages/statistics-1.6.1/pdist2.m
***** shared x, y, xx
 x = [1, 1, 1; 2, 2, 2; 3, 3, 3];
 y = [0, 0, 0; 1, 2, 3; 0, 2, 4; 4, 7, 1];
 xx = [1 2 3; 4 5 6; 7 8 9; 3 2 1];
***** test
 d = sqrt([3, 5, 11, 45; 12, 2, 8, 30; 27, 5, 11, 21]);
 assert (pdist2 (x, y), d);
***** test
 d = [5.1962, 2.2361, 3.3166, 6.7082; ...
      3.4641, 2.2361, 3.3166, 5.4772];
 i = [3, 1, 1, 1; 2, 3, 3, 2];
 [D, I] = pdist2 (x, y, "euclidean", "largest", 2);
 assert ({D, I}, {d, i}, 1e-4);
***** test
 d = [1.7321, 1.4142, 2.8284, 4.5826; ...
      3.4641, 2.2361, 3.3166, 5.4772];
 i = [1, 2, 2, 3;2, 1, 1, 2];
 [D, I] = pdist2 (x, y, "euclidean", "smallest", 2);
 assert ({D, I}, {d, i}, 1e-4);
***** test
 yy = [1 2 3;5 6 7;9 5 1];
 d = [0, 6.1644, 5.3852; 1.4142, 6.9282, 8.7750; ...
      3.7417, 7.0711, 9.9499; 6.1644, 10.4881, 10.3441];
 i = [2, 4, 4; 3, 2, 2; 1, 3, 3; 4, 1, 1];
 [D, I] = pdist2 (y, yy, "euclidean", "smallest", 4);
 assert ({D, I}, {d, i}, 1e-4);
***** test
 yy = [1 2 3;5 6 7;9 5 1];
 d = [0, 38, 29; 2, 48, 77; 14, 50, 99; 38, 110, 107];
 i = [2, 4, 4; 3, 2, 2; 1, 3, 3; 4, 1, 1];
 [D, I] = pdist2 (y, yy, "squaredeuclidean", "smallest", 4);
 assert ({D, I}, {d, i}, 1e-4);
***** test
 yy = [1 2 3;5 6 7;9 5 1];
 d = [0, 3.3256, 2.7249; 0.7610, 3.3453, 4.4799; ...
      1.8514, 3.3869, 5.0703; 2.5525, 5.0709, 5.1297];
 i = [2, 2, 4; 3, 4, 2; 1, 3, 1; 4, 1, 3];
 [D, I] = pdist2 (y, yy, "seuclidean", "smallest", 4);
 assert ({D, I}, {d, i}, 1e-4);
***** test
 d = [2.1213, 4.2426, 6.3640; 1.2247, 2.4495, 4.4159; ...
      3.2404, 4.8990, 6.8191; 2.7386, 4.2426, 6.1237];
 assert (pdist2 (y, x, "mahalanobis"), d, 1e-4);
***** test
 d = [1.2247, 2.4495, 4.4159; 2.1213, 4.2426, 6.1237];
 i = [2, 2, 2; 1, 4, 4];
 [D, I] = pdist2 (y, x, "mahalanobis", "smallest", 2);
 assert ({D, I}, {d, i}, 1e-4);
***** test
 d = [3.2404, 4.8990, 6.8191; 2.7386, 4.2426, 6.3640];
 i = [3, 3, 3; 4, 1, 1];
 [D, I] = pdist2 (y, x, "mahalanobis", "largest", 2);
 assert ({D, I}, {d, i}, 1e-4);
***** test
 yy = [1 2 3;5 6 7;9 5 1];
 d = [0, 8.4853, 18.0416; 2.4495, 10.0995, 19.4808; ...
      2.4495, 10.6771, 19.7104; 2.4495, 10.6771, 20.4573];
 i = [2, 2, 2; 1, 4, 4; 4, 1, 1; 3, 3, 3];
 [D, I] = pdist2 (y, yy, "mahalanobis", "smallest", 4);
 assert ({D, I}, {d, i}, 1e-4);
***** test
 d = [3, 3, 5, 9; 6, 2, 4, 8; 9, 3, 5, 7];
 assert (pdist2 (x, y, "cityblock"), d);
***** test
 d = [1, 2, 3, 6; 2, 1, 2, 5; 3, 2, 3, 4];
 assert (pdist2 (x, y, "chebychev"), d);
***** test
 d = repmat ([NaN, 0.0742, 0.2254, 0.1472], [3, 1]);
 assert (pdist2 (x, y, "cosine"), d, 1e-4);
***** test
 yy = [1 2 3;5 6 7;9 5 1];
 d = [0, 0, 0.5; 0, 0, 2; 1.5, 1.5, 2; NaN, NaN, NaN];
 i = [2, 2, 4; 3, 3, 2; 4, 4, 3; 1, 1, 1];
 [D, I] = pdist2 (y, yy, "correlation", "smallest", 4);
 assert ({D, I}, {d, i}, eps);
 [D, I] = pdist2 (y, yy, "spearman", "smallest", 4);
 assert ({D, I}, {d, i}, eps);
***** test
 d = [1, 2/3, 1, 1; 1, 2/3, 1, 1; 1, 2/3, 2/3, 2/3];
 i = [1, 1, 1, 2; 2, 2, 3, 3; 3, 3, 2, 1];
 [D, I] = pdist2 (x, y, "hamming", "largest", 4);
 assert ({D, I}, {d, i}, eps);
 [D, I] = pdist2 (x, y, "jaccard", "largest", 4);
 assert ({D, I}, {d, i}, eps);
***** test
 xx = [1, 2, 3, 4; 2, 3, 4, 5; 3, 4, 5, 6];
 yy = [1, 2, 2, 3; 2, 3, 3, 4];
 [D, I] = pdist2 (x, y, "euclidean", "Smallest", 4);
 eucldist = @(v,m) sqrt(sumsq(repmat(v,rows(m),1)-m,2));
 [d, i] = pdist2 (x, y, eucldist, "Smallest", 4);
 assert ({D, I}, {d, i});
***** warning<pdist2: matrix is close to singular> ...
 pdist2 (xx, xx, "mahalanobis");
***** error<pdist2: too few input arguments.> pdist2 (1)
***** error<pdist2: X and Y must have equal number of columns.> ...
 pdist2 (ones (4, 5), ones (4))
***** error<pdist2: X and Y must be 2 dimensional matrices.> ...
 pdist2 (ones (4, 2, 3), ones (3, 2))
***** error<pdist2: missing value in optional name/value paired arguments.> ...
 pdist2 (ones (3), ones (3), "euclidean", "Largest")
***** error<pdist2: missing value in optional name/value paired arguments.> ...
 pdist2 (ones (3), ones (3), "minkowski", 3, "Largest")
***** error<pdist2: invalid NAME in optional pairs of arguments.> ...
 pdist2 (ones (3), ones (3), "minkowski", 3, "large", 4)
***** error<pdist2: you can only use either Smallest or Largest.> ...
 pdist2 (ones (3), ones (3), "minkowski", 3, "Largest", 4, "smallest", 5)
***** error<pdist2: Smallest or Largest must be specified to compute second output.> ...
 [d, i] = pdist2(ones (3), ones (3), "minkowski", 3)
***** error<pdist2: DistParameter for standardized euclidean must be a vector of> ...
 pdist2 (ones (3), ones (3), "seuclidean", 3)
***** error<pdist2: DistParameter for standardized euclidean must be a nonnegative> ...
 pdist2 (ones (3), ones (3), "seuclidean", [1, -1, 3])
***** error<pdist2: DistParameter for mahalanobis distance must be a covariance> ...
 pdist2 (ones (3), eye (3), "mahalanobis", eye(2))
***** error<pdist2: covariance matrix for mahalanobis distance must be symmetric> ...
 pdist2 (ones (3), eye (3), "mahalanobis", ones(3))
***** error<pdist2: DistParameter for minkowski distance must be a positive scalar.> ...
 pdist2 (ones (3), eye (3), "minkowski", 0)
***** error<pdist2: DistParameter for minkowski distance must be a positive scalar.> ...
 pdist2 (ones (3), eye (3), "minkowski", -5)
***** error<pdist2: DistParameter for minkowski distance must be a positive scalar.> ...
 pdist2 (ones (3), eye (3), "minkowski", [1, 2])
***** error<pdist2: invalid function handle for distance metric.> ...
 pdist2 (ones (3), ones (3), @(v,m) sqrt(repmat(v,rows(m),1)-m,2))
***** error<pdist2: custom distance function produces wrong output size.> ...
 pdist2 (ones (3), ones (3), @(v,m) sqrt(sum(sumsq(repmat(v,rows(m),1)-m,2))))
PASSES 34 out of 34 tests
octave:5> d = [1.2247, 2.4495, 4.4159; 2.1213, 4.2426, 6.1237];
octave:6> i = [2, 2, 2; 1, 4, 4];
octave:7> [D, I] = pdist2 (y, x, "mahalanobis", "smallest", 2);
error: 'y' undefined near line 1, column 18
octave:8> x = [ 1   1   1
       2   2   2
       3   3   3 ]
x =

   1   1   1
   2   2   2
   3   3   3

octave:9> y = [0   0   0
       1   2   3
       0   2   4
       4   7   1
]
y =

   0   0   0
   1   2   3
   0   2   4
   4   7   1

octave:10> [D, I] = pdist2 (y, x, "mahalanobis", "smallest", 2);
octave:11> I
I =

   2   2   2
   1   4   4

octave:12> i
i =

   2   2   2
   1   4   4


Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Wed 17 Jan 2024 05:44:01 PM UTC, original submission:  

In version 1.6.1 of the statistics package, two of the BISTs in  the pdist2.m file:


octave:1> pkg load statistics
octave:2> test pdist2 verbose
***** test
 d = [1.2247, 2.4495, 4.4159; 2.1213, 4.2426, 6.1237];
 i = [2, 2, 2; 1, 4, 4];
 [D, I] = pdist2 (y, x, "mahalanobis", "smallest", 2);
 assert ({D, I}, {d, i}, 1e-4);
!!!!! test failed
ASSERT errors for:  assert (cond {i},expected {i},tol)

  Location  |  Observed  |  Expected  |  Reason
   (2,2)          1            4         Abs err 3 exceeds tol 0.0001 by 3
shared variables     x =

       1   1   1
       2   2   2
       3   3   3

    y =

       0   0   0
       1   2   3
       0   2   4
       4   7   1

    xx =

       1   2   3
       4   5   6
       7   8   9
       3   2   1

***** test
 d = [3.2404, 4.8990, 6.8191; 2.7386, 4.2426, 6.3640];
 i = [3, 3, 3; 4, 1, 1];
 [D, I] = pdist2 (y, x, "mahalanobis", "largest", 2);
 assert ({D, I}, {d, i}, 1e-4);
!!!!! test failed
ASSERT errors for:  assert (cond {i},expected {i},tol)

  Location  |  Observed  |  Expected  |  Reason
   (2,2)          4            1         Abs err 3 exceeds tol 0.0001 by 3
shared variables     x =

       1   1   1
       2   2   2
       3   3   3

    y =

       0   0   0
       1   2   3
       0   2   4
       4   7   1

    xx =

       1   2   3
       4   5   6
       7   8   9
       3   2   1


Indeed, we have this:


octave:3> d = [1.2247, 2.4495, 4.4159; 2.1213, 4.2426, 6.1237];
octave:4> i = [2, 2, 2; 1, 4, 4];
octave:5> [D, I] = pdist2 (y, x, "mahalanobis", "smallest", 2);
octave:6> disp (I)
   2   2   2
   1   1   4
octave:7> disp (i)
   2   2   2
   1   4   4


Rafael Laboissière <rlaboiss>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by dasergatskov (Posted a comment)
  • -email is unavailable- added by rlaboiss (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.12.
    Corresponding source code