Skip to content

Commit c21d283

Browse files
mvargas33mvargas33
authored and
mvargas33
committed
Handmade tests incorporated
1 parent 2f3c3e1 commit c21d283

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

metric_learn/oasis.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ def fit(self, X, y):
1717
"""
1818
X = self._prepare_inputs(X, y, ensure_min_samples=2)
1919

20-
# Handmade dummy fit
21-
#self.components_ = np.identity(np.shape(X[0])[-1]) # Identity matrix
22-
#self.components_ = np.array([[2,4,6], [6,4,2], [1, 2, 3]])
23-
2420
# Dummy fit
2521
self.components_ = np.random.rand(np.shape(X[0])[-1], np.shape(X[0])[-1])
2622
return self

test_bilinear.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from numpy.testing import assert_array_almost_equal
44

55
def test_toy_distance():
6+
# Random generalized test for 2 points
67
d = 100
78

89
u = np.random.rand(d)
@@ -22,4 +23,20 @@ def test_toy_distance():
2223
assert_array_almost_equal(dist1, desired)
2324
assert_array_almost_equal(dist2, desired)
2425

26+
# Handmade example
27+
u = np.array([0, 1 ,2])
28+
v = np.array([3, 4, 5])
29+
30+
mixin.components_= np.array([[2,4,6], [6,4,2], [1, 2, 3]])
31+
dists = mixin.score_pairs([[u, v], [v, u]])
32+
assert_array_almost_equal(dists, [96, 120])
33+
34+
# Symetric example
35+
u = np.array([0, 1 ,2])
36+
v = np.array([3, 4, 5])
37+
38+
mixin.components_= np.identity(3) # Identity matrix
39+
dists = mixin.score_pairs([[u, v], [v, u]])
40+
assert_array_almost_equal(dists, [14, 14])
41+
2542
test_toy_distance()

0 commit comments

Comments
 (0)