Skip to content

Commit 3e6adb7

Browse files
author
mvargas33
committed
Minor details
1 parent 97c1fcc commit 3e6adb7

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

test/test_bilinear_mixin.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313

1414
class IdentityBilinearMixin(BilinearMixin):
1515
"""A simple Identity bilinear mixin that returns an identity matrix
16-
M as learned. Can change M for a random matrix calling random_M.
17-
Class for testing purposes.
16+
M as learned. Can change M for a random matrix specifying random=True
17+
at fit(). Class for testing purposes.
1818
"""
1919
def __init__(self, preprocessor=None):
2020
super().__init__(preprocessor=preprocessor)
2121

2222
def fit(self, X, y, random=False):
2323
"""
24-
Checks input's format. Sets M matrix to identity of shape (d,d)
25-
where d is the dimension of the input.
24+
Checks input's format. If random=False, sets M matrix to
25+
identity of shape (d,d) where d is the dimension of the input.
26+
Otherwise, a random (d,d) matrix is set.
2627
"""
2728
X, y = self._prepare_inputs(X, y, ensure_min_samples=2)
2829
self.d = np.shape(X[0])[-1]
@@ -32,19 +33,14 @@ def fit(self, X, y, random=False):
3233
self.components_ = np.identity(self.d)
3334
return self
3435

35-
def random_M(self):
36-
"""
37-
Changes the matrix M for a random one of shape (d,d)
38-
"""
39-
self.components_ = np.random.rand(self.d, self.d)
40-
4136

4237
def identity_fit(d=100, n=100, n_pairs=None, random=False):
4338
"""
4439
Creates 'n' d-dimentional arrays. Also generates 'n_pairs'
4540
sampled from the 'n' arrays. Fits an IdentityBilinearMixin()
4641
and then returns the arrays, the pairs and the mixin. Only
47-
generates the pairs if n_pairs is not None
42+
generates the pairs if n_pairs is not None. If random=True,
43+
the matrix M fitted will be random.
4844
"""
4945
X = np.array([np.random.rand(d) for _ in range(n)])
5046
mixin = IdentityBilinearMixin()
@@ -107,7 +103,7 @@ def test_check_handmade_symmetric_example():
107103
"""
108104
When the Bilinear matrix is the identity. The similarity
109105
between two arrays must be equal: S(u,v) = S(v,u). Also
110-
checks the random case: when the matrix is pd and symetric.
106+
checks the random case: when the matrix is spd and symetric.
111107
"""
112108
# Random pairs for M = Identity
113109
d, n, n_pairs = 100, 100, 1000
@@ -128,8 +124,8 @@ def test_check_handmade_symmetric_example():
128124
def test_score_pairs_finite():
129125
"""
130126
Checks for 'n' score_pairs() of 'd' dimentions, that all
131-
similarities are finite numbers, not NaN, +inf or -inf.
132-
Considering a random M for bilinear similarity.
127+
similarities are finite numbers: not NaN, +inf or -inf.
128+
Considers a random M for bilinear similarity.
133129
"""
134130
d, n, n_pairs = 100, 100, 1000
135131
_, random_pairs, mixin = identity_fit(d=d, n=n, n_pairs=n_pairs, random=True)

0 commit comments

Comments
 (0)