17
17
18
18
from ..base import BaseEstimator , TransformerMixin , ClassNamePrefixFeaturesOutMixin
19
19
from ..utils import check_array , check_random_state , gen_even_slices , gen_batches
20
- from ..utils import deprecated
21
20
from ..utils ._param_validation import Hidden , Interval , StrOptions
22
21
from ..utils ._param_validation import validate_params
23
22
from ..utils .extmath import randomized_svd , row_norms , svd_flip
@@ -627,7 +626,7 @@ def _dict_learning(
627
626
def _check_warn_deprecated (param , name , default , additional_message = None ):
628
627
if param != "deprecated" :
629
628
msg = (
630
- f"'{ name } ' is deprecated in version 1.1 and will be removed in version 1.3 ."
629
+ f"'{ name } ' is deprecated in version 1.1 and will be removed in version 1.4 ."
631
630
)
632
631
if additional_message :
633
632
msg += f" { additional_message } "
@@ -647,7 +646,7 @@ def dict_learning_online(
647
646
return_code = True ,
648
647
dict_init = None ,
649
648
callback = None ,
650
- batch_size = "warn" ,
649
+ batch_size = 256 ,
651
650
verbose = False ,
652
651
shuffle = True ,
653
652
n_jobs = None ,
@@ -717,11 +716,11 @@ def dict_learning_online(
717
716
callback : callable, default=None
718
717
A callable that gets invoked at the end of each iteration.
719
718
720
- batch_size : int, default=3
719
+ batch_size : int, default=256
721
720
The number of samples to take in each batch.
722
721
723
722
.. versionchanged:: 1.3
724
- The default value of `batch_size` will change from 3 to 256 in version 1.3.
723
+ The default value of `batch_size` changed from 3 to 256 in version 1.3.
725
724
726
725
verbose : bool, default=False
727
726
To control the verbosity of the procedure.
@@ -747,7 +746,7 @@ def dict_learning_online(
747
746
initialization.
748
747
749
748
.. deprecated:: 1.1
750
- `iter_offset` serves internal purpose only and will be removed in 1.3 .
749
+ `iter_offset` serves internal purpose only and will be removed in 1.4 .
751
750
752
751
random_state : int, RandomState instance or None, default=None
753
752
Used for initializing the dictionary when ``dict_init`` is not
@@ -763,7 +762,7 @@ def dict_learning_online(
763
762
ignored.
764
763
765
764
.. deprecated:: 1.1
766
- `return_inner_stats` serves internal purpose only and will be removed in 1.3 .
765
+ `return_inner_stats` serves internal purpose only and will be removed in 1.4 .
767
766
768
767
inner_stats : tuple of (A, B) ndarrays, default=None
769
768
Inner sufficient statistics that are kept by the algorithm.
@@ -773,13 +772,13 @@ def dict_learning_online(
773
772
`B` `(n_features, n_components)` is the data approximation matrix.
774
773
775
774
.. deprecated:: 1.1
776
- `inner_stats` serves internal purpose only and will be removed in 1.3 .
775
+ `inner_stats` serves internal purpose only and will be removed in 1.4 .
777
776
778
777
return_n_iter : bool, default=False
779
778
Whether or not to return the number of iterations.
780
779
781
780
.. deprecated:: 1.1
782
- `return_n_iter` will be removed in 1.3 and n_iter will always be returned.
781
+ `return_n_iter` will be removed in 1.4 and n_iter will never be returned.
783
782
784
783
positive_dict : bool, default=False
785
784
Whether to enforce positivity when finding the dictionary.
@@ -848,15 +847,15 @@ def dict_learning_online(
848
847
return_inner_stats ,
849
848
"return_inner_stats" ,
850
849
default = False ,
851
- additional_message = "From 1.3 inner_stats will never be returned." ,
850
+ additional_message = "From 1.4 inner_stats will never be returned." ,
852
851
)
853
852
inner_stats = _check_warn_deprecated (inner_stats , "inner_stats" , default = None )
854
853
return_n_iter = _check_warn_deprecated (
855
854
return_n_iter ,
856
855
"return_n_iter" ,
857
856
default = False ,
858
857
additional_message = (
859
- "From 1.3 'n_iter' will never be returned. Refer to the 'n_iter_' and "
858
+ "From 1.4 'n_iter' will never be returned. Refer to the 'n_iter_' and "
860
859
"'n_steps_' attributes of the MiniBatchDictionaryLearning object instead."
861
860
),
862
861
)
@@ -891,20 +890,13 @@ def dict_learning_online(
891
890
code = est .transform (X )
892
891
return code , est .components_
893
892
894
- # TODO remove the whole old behavior in 1.3
893
+ # TODO(1.4) remove the whole old behavior
895
894
# Fallback to old behavior
896
895
897
896
n_iter = _check_warn_deprecated (
898
897
n_iter , "n_iter" , default = 100 , additional_message = "Use 'max_iter' instead."
899
898
)
900
899
901
- if batch_size == "warn" :
902
- warnings .warn (
903
- "The default value of batch_size will change from 3 to 256 in 1.3." ,
904
- FutureWarning ,
905
- )
906
- batch_size = 3
907
-
908
900
if n_components is None :
909
901
n_components = X .shape [1 ]
910
902
@@ -1903,11 +1895,11 @@ class MiniBatchDictionaryLearning(_BaseSparseCoding, BaseEstimator):
1903
1895
``-1`` means using all processors. See :term:`Glossary <n_jobs>`
1904
1896
for more details.
1905
1897
1906
- batch_size : int, default=3
1898
+ batch_size : int, default=256
1907
1899
Number of samples in each mini-batch.
1908
1900
1909
1901
.. versionchanged:: 1.3
1910
- The default value of `batch_size` will change from 3 to 256 in version 1.3.
1902
+ The default value of `batch_size` changed from 3 to 256 in version 1.3.
1911
1903
1912
1904
shuffle : bool, default=True
1913
1905
Whether to shuffle the samples before forming batches.
@@ -2006,17 +1998,6 @@ class MiniBatchDictionaryLearning(_BaseSparseCoding, BaseEstimator):
2006
1998
components_ : ndarray of shape (n_components, n_features)
2007
1999
Components extracted from the data.
2008
2000
2009
- inner_stats_ : tuple of (A, B) ndarrays
2010
- Internal sufficient statistics that are kept by the algorithm.
2011
- Keeping them is useful in online settings, to avoid losing the
2012
- history of the evolution, but they shouldn't have any use for the
2013
- end user.
2014
- `A` `(n_components, n_components)` is the dictionary covariance matrix.
2015
- `B` `(n_features, n_components)` is the data approximation matrix.
2016
-
2017
- .. deprecated:: 1.1
2018
- `inner_stats_` serves internal purpose only and will be removed in 1.3.
2019
-
2020
2001
n_features_in_ : int
2021
2002
Number of features seen during :term:`fit`.
2022
2003
@@ -2031,19 +2012,6 @@ class MiniBatchDictionaryLearning(_BaseSparseCoding, BaseEstimator):
2031
2012
n_iter_ : int
2032
2013
Number of iterations over the full dataset.
2033
2014
2034
- iter_offset_ : int
2035
- The number of iteration on data batches that has been performed before.
2036
-
2037
- .. deprecated:: 1.1
2038
- `iter_offset_` has been renamed `n_steps_` and will be removed in 1.3.
2039
-
2040
- random_state_ : RandomState instance
2041
- RandomState instance that is generated either from a seed, the random
2042
- number generattor or by `np.random`.
2043
-
2044
- .. deprecated:: 1.1
2045
- `random_state_` serves internal purpose only and will be removed in 1.3.
2046
-
2047
2015
n_steps_ : int
2048
2016
Number of mini-batches processed.
2049
2017
@@ -2100,10 +2068,7 @@ class MiniBatchDictionaryLearning(_BaseSparseCoding, BaseEstimator):
2100
2068
"max_iter" : [Interval (Integral , 0 , None , closed = "left" ), None ],
2101
2069
"fit_algorithm" : [StrOptions ({"cd" , "lars" })],
2102
2070
"n_jobs" : [None , Integral ],
2103
- "batch_size" : [
2104
- Interval (Integral , 1 , None , closed = "left" ),
2105
- Hidden (StrOptions ({"warn" })),
2106
- ],
2071
+ "batch_size" : [Interval (Integral , 1 , None , closed = "left" )],
2107
2072
"shuffle" : ["boolean" ],
2108
2073
"dict_init" : [None , np .ndarray ],
2109
2074
"transform_algorithm" : [
@@ -2131,7 +2096,7 @@ def __init__(
2131
2096
max_iter = None ,
2132
2097
fit_algorithm = "lars" ,
2133
2098
n_jobs = None ,
2134
- batch_size = "warn" ,
2099
+ batch_size = 256 ,
2135
2100
shuffle = True ,
2136
2101
dict_init = None ,
2137
2102
transform_algorithm = "omp" ,
@@ -2173,27 +2138,6 @@ def __init__(
2173
2138
self .max_no_improvement = max_no_improvement
2174
2139
self .tol = tol
2175
2140
2176
- @deprecated ( # type: ignore
2177
- "The attribute `iter_offset_` is deprecated in 1.1 and will be removed in 1.3."
2178
- )
2179
- @property
2180
- def iter_offset_ (self ):
2181
- return self .n_iter_
2182
-
2183
- @deprecated ( # type: ignore
2184
- "The attribute `random_state_` is deprecated in 1.1 and will be removed in 1.3."
2185
- )
2186
- @property
2187
- def random_state_ (self ):
2188
- return self ._random_state
2189
-
2190
- @deprecated ( # type: ignore
2191
- "The attribute `inner_stats_` is deprecated in 1.1 and will be removed in 1.3."
2192
- )
2193
- @property
2194
- def inner_stats_ (self ):
2195
- return self ._inner_stats
2196
-
2197
2141
def _check_params (self , X ):
2198
2142
# n_components
2199
2143
self ._n_components = self .n_components
@@ -2205,8 +2149,7 @@ def _check_params(self, X):
2205
2149
self ._fit_algorithm = "lasso_" + self .fit_algorithm
2206
2150
2207
2151
# batch_size
2208
- if hasattr (self , "_batch_size" ):
2209
- self ._batch_size = min (self ._batch_size , X .shape [0 ])
2152
+ self ._batch_size = min (self .batch_size , X .shape [0 ])
2210
2153
2211
2154
def _initialize_dict (self , X , random_state ):
2212
2155
"""Initialization of the dictionary."""
@@ -2245,11 +2188,10 @@ def _update_inner_stats(self, X, code, batch_size, step):
2245
2188
theta = batch_size ** 2 + step + 1 - batch_size
2246
2189
beta = (theta + 1 - batch_size ) / (theta + 1 )
2247
2190
2248
- A , B = self ._inner_stats
2249
- A *= beta
2250
- A += code .T @ code
2251
- B *= beta
2252
- B += X .T @ code
2191
+ self ._A *= beta
2192
+ self ._A += code .T @ code
2193
+ self ._B *= beta
2194
+ self ._B += X .T @ code
2253
2195
2254
2196
def _minibatch_step (self , X , dictionary , random_state , step ):
2255
2197
"""Perform the update on the dictionary for one minibatch."""
@@ -2277,13 +2219,12 @@ def _minibatch_step(self, X, dictionary, random_state, step):
2277
2219
self ._update_inner_stats (X , code , batch_size , step )
2278
2220
2279
2221
# Update dictionary
2280
- A , B = self ._inner_stats
2281
2222
_update_dict (
2282
2223
dictionary ,
2283
2224
X ,
2284
2225
code ,
2285
- A ,
2286
- B ,
2226
+ self . _A ,
2227
+ self . _B ,
2287
2228
verbose = self .verbose ,
2288
2229
random_state = random_state ,
2289
2230
positive = self .positive_dict ,
@@ -2378,14 +2319,6 @@ def fit(self, X, y=None):
2378
2319
"""
2379
2320
self ._validate_params ()
2380
2321
2381
- self ._batch_size = self .batch_size
2382
- if self .batch_size == "warn" :
2383
- warnings .warn (
2384
- "The default value of batch_size will change from 3 to 256 in 1.3." ,
2385
- FutureWarning ,
2386
- )
2387
- self ._batch_size = 3
2388
-
2389
2322
X = self ._validate_data (
2390
2323
X , dtype = [np .float64 , np .float32 ], order = "C" , copy = False
2391
2324
)
@@ -2419,10 +2352,10 @@ def fit(self, X, y=None):
2419
2352
print ("[dict_learning]" )
2420
2353
2421
2354
# Inner stats
2422
- self ._inner_stats = (
2423
- np .zeros ((self ._n_components , self ._n_components ), dtype = X_train .dtype ),
2424
- np .zeros ((n_features , self ._n_components ), dtype = X_train .dtype ),
2355
+ self ._A = np .zeros (
2356
+ (self ._n_components , self ._n_components ), dtype = X_train .dtype
2425
2357
)
2358
+ self ._B = np .zeros ((n_features , self ._n_components ), dtype = X_train .dtype )
2426
2359
2427
2360
if self .max_iter is not None :
2428
2361
@@ -2483,7 +2416,7 @@ def fit(self, X, y=None):
2483
2416
2484
2417
return self
2485
2418
2486
- def partial_fit (self , X , y = None , iter_offset = "deprecated" ):
2419
+ def partial_fit (self , X , y = None ):
2487
2420
"""Update the model using the data in X as a mini-batch.
2488
2421
2489
2422
Parameters
@@ -2495,15 +2428,6 @@ def partial_fit(self, X, y=None, iter_offset="deprecated"):
2495
2428
y : Ignored
2496
2429
Not used, present for API consistency by convention.
2497
2430
2498
- iter_offset : int, default=None
2499
- The number of iteration on data batches that has been
2500
- performed before this call to `partial_fit`. This is optional:
2501
- if no number is passed, the memory of the object is
2502
- used.
2503
-
2504
- .. deprecated:: 1.1
2505
- ``iter_offset`` will be removed in 1.3.
2506
-
2507
2431
Returns
2508
2432
-------
2509
2433
self : object
@@ -2518,27 +2442,17 @@ def partial_fit(self, X, y=None, iter_offset="deprecated"):
2518
2442
X , dtype = [np .float64 , np .float32 ], order = "C" , reset = not has_components
2519
2443
)
2520
2444
2521
- if iter_offset != "deprecated" :
2522
- warnings .warn (
2523
- "'iter_offset' is deprecated in version 1.1 and "
2524
- "will be removed in version 1.3" ,
2525
- FutureWarning ,
2526
- )
2527
- self .n_steps_ = iter_offset
2528
- else :
2529
- self .n_steps_ = getattr (self , "n_steps_" , 0 )
2530
-
2531
2445
if not has_components :
2532
2446
# This instance has not been fitted yet (fit or partial_fit)
2533
2447
self ._check_params (X )
2534
2448
self ._random_state = check_random_state (self .random_state )
2535
2449
2536
2450
dictionary = self ._initialize_dict (X , self ._random_state )
2537
2451
2538
- self ._inner_stats = (
2539
- np . zeros (( self . _n_components , self . _n_components ), dtype = X . dtype ),
2540
- np .zeros ((X . shape [ 1 ] , self ._n_components ), dtype = X .dtype ),
2541
- )
2452
+ self .n_steps_ = 0
2453
+
2454
+ self . _A = np .zeros ((self . _n_components , self ._n_components ), dtype = X .dtype )
2455
+ self . _B = np . zeros (( X . shape [ 1 ], self . _n_components ), dtype = X . dtype )
2542
2456
else :
2543
2457
dictionary = self .components_
2544
2458
0 commit comments