Skip to content

Commit a70d1a8

Browse files
author
William de Vazelhes
committed
FIX move docstrings from _fit to fit
1 parent 2dae03e commit a70d1a8

File tree

4 files changed

+59
-59
lines changed

4 files changed

+59
-59
lines changed

metric_learn/itml.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,6 @@ def _process_pairs(self, pairs, y, bounds):
8080
return pairs, y
8181

8282
def _fit(self, pairs, y, bounds=None):
83-
"""Learn the ITML model.
84-
85-
Parameters
86-
----------
87-
pairs: array-like, shape=(n_constraints, 2, n_features)
88-
Array of pairs. Each row corresponds to two points.
89-
y: array-like, of shape (n_constraints,)
90-
Labels of constraints. Should be -1 for dissimilar pair, 1 for similar.
91-
bounds : list (pos,neg) pairs, optional
92-
bounds on similarity, s.t. d(X[a],X[b]) < pos and d(X[c],X[d]) > neg
93-
94-
Returns
95-
-------
96-
self : object
97-
Returns the instance.
98-
"""
9983
pairs, y = self._process_pairs(pairs, y, bounds)
10084
gamma = self.gamma
10185
pos_pairs, neg_pairs = pairs[y == 1], pairs[y == -1]
@@ -154,6 +138,22 @@ def metric(self):
154138
class ITML(_BaseITML, _PairsClassifierMixin):
155139

156140
def fit(self, pairs, y, bounds=None):
141+
"""Learn the ITML model.
142+
143+
Parameters
144+
----------
145+
pairs: array-like, shape=(n_constraints, 2, n_features)
146+
Array of pairs. Each row corresponds to two points.
147+
y: array-like, of shape (n_constraints,)
148+
Labels of constraints. Should be -1 for dissimilar pair, 1 for similar.
149+
bounds : list (pos,neg) pairs, optional
150+
bounds on similarity, s.t. d(X[a],X[b]) < pos and d(X[c],X[d]) > neg
151+
152+
Returns
153+
-------
154+
self : object
155+
Returns the instance.
156+
"""
157157
return self._fit(pairs, y, bounds=bounds)
158158

159159

metric_learn/lsml.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,6 @@ def metric(self):
6262
return self.M_
6363

6464
def _fit(self, quadruplets, weights=None):
65-
"""Learn the LSML model.
66-
67-
Parameters
68-
----------
69-
quadruplets : array-like, shape=(n_constraints, 4, n_features)
70-
Each row corresponds to 4 points. In order to supervise the
71-
algorithm in the right way, we should have the four samples ordered
72-
in a way such that: d(pairs[i, 0],X[i, 1]) < d(X[i, 2], X[i, 3])
73-
for all 0 <= i < n_constraints.
74-
weights : (n_constraints,) array of floats, optional
75-
scale factor for each constraint
76-
77-
Returns
78-
-------
79-
self : object
80-
Returns the instance.
81-
"""
8265
self._prepare_quadruplets(quadruplets, weights)
8366
step_sizes = np.logspace(-10, 0, 10)
8467
# Keep track of the best step size and the loss at that step.
@@ -144,6 +127,23 @@ def _gradient(self, metric):
144127
class LSML(_BaseLSML, _QuadrupletsClassifierMixin):
145128

146129
def fit(self, quadruplets, weights=None):
130+
"""Learn the LSML model.
131+
132+
Parameters
133+
----------
134+
quadruplets : array-like, shape=(n_constraints, 4, n_features)
135+
Each row corresponds to 4 points. In order to supervise the
136+
algorithm in the right way, we should have the four samples ordered
137+
in a way such that: d(pairs[i, 0],X[i, 1]) < d(X[i, 2], X[i, 3])
138+
for all 0 <= i < n_constraints.
139+
weights : (n_constraints,) array of floats, optional
140+
scale factor for each constraint
141+
142+
Returns
143+
-------
144+
self : object
145+
Returns the instance.
146+
"""
147147
return self._fit(quadruplets, weights=weights)
148148

149149

metric_learn/mmc.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,6 @@ def __init__(self, max_iter=100, max_proj=10000, convergence_threshold=1e-3,
5858
self.verbose = verbose
5959

6060
def _fit(self, pairs, y):
61-
"""Learn the MMC model.
62-
63-
Parameters
64-
----------
65-
pairs: array-like, shape=(n_constraints, 2, n_features)
66-
Array of pairs. Each row corresponds to two points.
67-
y: array-like, of shape (n_constraints,)
68-
Labels of constraints. Should be -1 for dissimilar pair, 1 for similar.
69-
70-
Returns
71-
-------
72-
self : object
73-
Returns the instance.
74-
"""
7561
pairs, y = self._process_pairs(pairs, y)
7662
if self.diagonal:
7763
return self._fit_diag(pairs, y)
@@ -389,6 +375,20 @@ def transformer(self):
389375
class MMC(_BaseMMC, _PairsClassifierMixin):
390376

391377
def fit(self, pairs, y):
378+
"""Learn the MMC model.
379+
380+
Parameters
381+
----------
382+
pairs: array-like, shape=(n_constraints, 2, n_features)
383+
Array of pairs. Each row corresponds to two points.
384+
y: array-like, of shape (n_constraints,)
385+
Labels of constraints. Should be -1 for dissimilar pair, 1 for similar.
386+
387+
Returns
388+
-------
389+
self : object
390+
Returns the instance.
391+
"""
392392
return self._fit(pairs, y)
393393

394394

metric_learn/sdml.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ def metric(self):
5959
return self.M_
6060

6161
def _fit(self, pairs, y):
62+
loss_matrix = self._prepare_pairs(pairs, y)
63+
P = self.M_ + self.balance_param * loss_matrix
64+
emp_cov = pinvh(P)
65+
# hack: ensure positive semidefinite
66+
emp_cov = emp_cov.T.dot(emp_cov)
67+
_, self.M_ = graph_lasso(emp_cov, self.sparsity_param, verbose=self.verbose)
68+
return self
69+
70+
71+
class SDML(_BaseSDML, _PairsClassifierMixin):
72+
73+
def fit(self, pairs, y):
6274
"""Learn the SDML model.
6375
6476
Parameters
@@ -73,18 +85,6 @@ def _fit(self, pairs, y):
7385
self : object
7486
Returns the instance.
7587
"""
76-
loss_matrix = self._prepare_pairs(pairs, y)
77-
P = self.M_ + self.balance_param * loss_matrix
78-
emp_cov = pinvh(P)
79-
# hack: ensure positive semidefinite
80-
emp_cov = emp_cov.T.dot(emp_cov)
81-
_, self.M_ = graph_lasso(emp_cov, self.sparsity_param, verbose=self.verbose)
82-
return self
83-
84-
85-
class SDML(_BaseSDML, _PairsClassifierMixin):
86-
87-
def fit(self, pairs, y):
8888
return self._fit(pairs, y)
8989

9090

0 commit comments

Comments
 (0)