22import numpy as np
33from numpy .testing import assert_array_almost_equal
44
5+
56def test_toy_distance ():
67 # Random generalized test for 2 points
78 d = 100
@@ -10,33 +11,34 @@ def test_toy_distance():
1011 v = np .random .rand (d )
1112
1213 mixin = OASIS ()
13- mixin .fit ([u , v ], [0 , 0 ]) # Dummy fit
14+ mixin .fit ([u , v ], [0 , 0 ]) # Dummy fit
1415
1516 # The distances must match, whether calc with get_metric() or score_pairs()
1617 dist1 = mixin .score_pairs ([[u , v ], [v , u ]])
1718 dist2 = [mixin .get_metric ()(u , v ), mixin .get_metric ()(v , u )]
18-
19+
1920 u_v = (np .dot (np .dot (u .T , mixin .get_bilinear_matrix ()), v ))
2021 v_u = (np .dot (np .dot (v .T , mixin .get_bilinear_matrix ()), u ))
2122 desired = [u_v , v_u ]
22-
23+
2324 assert_array_almost_equal (dist1 , desired )
2425 assert_array_almost_equal (dist2 , desired )
2526
2627 # Handmade example
27- u = np .array ([0 , 1 , 2 ])
28+ u = np .array ([0 , 1 , 2 ])
2829 v = np .array ([3 , 4 , 5 ])
2930
30- mixin .components_ = np .array ([[2 ,4 , 6 ], [6 ,4 , 2 ], [1 , 2 , 3 ]])
31+ mixin .components_ = np .array ([[2 , 4 , 6 ], [6 , 4 , 2 ], [1 , 2 , 3 ]])
3132 dists = mixin .score_pairs ([[u , v ], [v , u ]])
3233 assert_array_almost_equal (dists , [96 , 120 ])
3334
3435 # Symetric example
35- u = np .array ([0 , 1 , 2 ])
36+ u = np .array ([0 , 1 , 2 ])
3637 v = np .array ([3 , 4 , 5 ])
3738
38- mixin .components_ = np .identity (3 ) # Identity matrix
39+ mixin .components_ = np .identity (3 ) # Identity matrix
3940 dists = mixin .score_pairs ([[u , v ], [v , u ]])
4041 assert_array_almost_equal (dists , [14 , 14 ])
4142
42- test_toy_distance ()
43+
44+ test_toy_distance ()
0 commit comments