FIX online updates in MiniBatchDictionaryLearning
@@ -2053,8 +2053,8 @@ class MiniBatchDictionaryLearning(_BaseSparseCoding, BaseEstimator):
We can check the level of sparsity of `X_transformed`:
- >>> np.mean(X_transformed == 0)
- 0.38...
+ >>> np.mean(X_transformed == 0) < 0.5
+ True
We can compare the average squared euclidean norm of the reconstruction
error of the sparse coded signal relative to the squared euclidean norm of
@@ -2062,7 +2062,7 @@ class MiniBatchDictionaryLearning(_BaseSparseCoding, BaseEstimator):
>>> X_hat = X_transformed @ dict_learner.components_
>>> np.mean(np.sum((X_hat - X) ** 2, axis=1) / np.sum(X ** 2, axis=1))
- 0.059...
+ 0.057...
"""
_parameter_constraints: dict = {
@@ -2196,9 +2196,9 @@ class MiniBatchDictionaryLearning(_BaseSparseCoding, BaseEstimator):
beta = (theta + 1 - batch_size) / (theta + 1)
self._A *= beta
- self._A += code.T @ code
+ self._A += code.T @ code / batch_size
self._B *= beta
- self._B += X.T @ code
+ self._B += X.T @ code / batch_size
def _minibatch_step(self, X, dictionary, random_state, step):
"""Perform the update on the dictionary for one minibatch."""
