@@ -202,8 +202,8 @@ class ITML_Supervised(_BaseITML, TransformerMixin):
202202 """
203203
204204 def __init__ (self , gamma = 1. , max_iter = 1000 , convergence_threshold = 1e-3 ,
205- num_labeled = 'deprecated' , num_constraints = None , bounds = None ,
206- A0 = None , verbose = False , preprocessor = None ):
205+ num_labeled = 'deprecated' , num_constraints = None ,
206+ bounds = 'deprecated' , A0 = None , verbose = False , preprocessor = None ):
207207 """Initialize the supervised version of `ITML`.
208208
209209 `ITML_Supervised` creates pairs of similar sample by taking same class
@@ -222,14 +222,11 @@ def __init__(self, gamma=1., max_iter=1000, convergence_threshold=1e-3,
222222 be removed in 0.6.0.
223223 num_constraints: int, optional
224224 number of constraints to generate
225- bounds : `list` of two numbers
226- Bounds on similarity, aside slack variables, s.t.
227- ``d(a, b) < bounds_[0]`` for all given pairs of similar points ``a``
228- and ``b``, and ``d(c, d) > bounds_[1]`` for all given pairs of
229- dissimilar points ``c`` and ``d``, with ``d`` the learned distance.
230- If not provided at initialization, bounds_[0] and bounds_[1] will be
231- set to the 5th and 95th percentile of the pairwise distances among all
232- points in the training data `X`.
225+ bounds : Not used
226+ .. deprecated:: 0.5.0
227+ `bounds` was deprecated in version 0.5.0 and will
228+ be removed in 0.6.0. Set `bounds` at fit time instead :
229+ `itml_supervised.fit(X, y, bounds=...)`
233230 A0 : (d x d) matrix, optional
234231 initial regularization matrix, defaults to identity
235232 verbose : bool, optional
@@ -245,7 +242,7 @@ def __init__(self, gamma=1., max_iter=1000, convergence_threshold=1e-3,
245242 self .num_constraints = num_constraints
246243 self .bounds = bounds
247244
248- def fit (self , X , y , random_state = np .random ):
245+ def fit (self , X , y , random_state = np .random , bounds = None ):
249246 """Create constraints from labels and learn the ITML model.
250247
251248
@@ -259,11 +256,26 @@ def fit(self, X, y, random_state=np.random):
259256
260257 random_state : numpy.random.RandomState, optional
261258 If provided, controls random number generation.
259+
260+ bounds : `list` of two numbers
261+ Bounds on similarity, aside slack variables, s.t.
262+ ``d(a, b) < bounds_[0]`` for all given pairs of similar points ``a``
263+ and ``b``, and ``d(c, d) > bounds_[1]`` for all given pairs of
264+ dissimilar points ``c`` and ``d``, with ``d`` the learned distance.
265+ If not provided at initialization, bounds_[0] and bounds_[1] will be
266+ set to the 5th and 95th percentile of the pairwise distances among all
267+ points in the training data `X`.
262268 """
269+ # TODO: remove these in v0.6.0
263270 if self .num_labeled != 'deprecated' :
264271 warnings .warn ('"num_labeled" parameter is not used.'
265272 ' It has been deprecated in version 0.5.0 and will be'
266273 'removed in 0.6.0' , DeprecationWarning )
274+ if self .bounds != 'deprecated' :
275+ warnings .warn ('"bounds" parameter from initialization is not used.'
276+ ' It has been deprecated in version 0.5.0 and will be'
277+ 'removed in 0.6.0. Use the "bounds" parameter of this '
278+ 'fit method instead.' , DeprecationWarning )
267279 X , y = self ._prepare_inputs (X , y , ensure_min_samples = 2 )
268280 num_constraints = self .num_constraints
269281 if num_constraints is None :
@@ -274,4 +286,4 @@ def fit(self, X, y, random_state=np.random):
274286 pos_neg = c .positive_negative_pairs (num_constraints ,
275287 random_state = random_state )
276288 pairs , y = wrap_pairs (X , pos_neg )
277- return _BaseITML ._fit (self , pairs , y , bounds = self . bounds )
289+ return _BaseITML ._fit (self , pairs , y , bounds = bounds )
0 commit comments