class_docstr: Mini-Batch Non-Negative Matrix Factorization (NMF).
  
  .. versionadded:: 1.1
  
  Find two non-negative matrices, i.e. matrices with all non-negative elements,
  (`W`, `H`) whose product approximates the non-negative matrix `X`. This
  factorization can be used for example for dimensionality reduction, source
  separation or topic extraction.
  
  The objective function is:
  
      .. math::
  
          L(W, H) &= 0.5 * ||X - WH||_{loss}^2
  
          &+ alpha\_W * l1\_ratio * n\_features * ||vec(W)||_1
  
          &+ alpha\_H * l1\_ratio * n\_samples * ||vec(H)||_1
  
          &+ 0.5 * alpha\_W * (1 - l1\_ratio) * n\_features * ||W||_{Fro}^2
  
          &+ 0.5 * alpha\_H * (1 - l1\_ratio) * n\_samples * ||H||_{Fro}^2
  
  Where:
  
  :math:`||A||_{Fro}^2 = \sum_{i,j} A_{ij}^2` (Frobenius norm)
  
  :math:`||vec(A)||_1 = \sum_{i,j} abs(A_{ij})` (Elementwise L1 norm)
  
  The generic norm :math:`||X - WH||_{loss}^2` may represent
  the Frobenius norm or another supported beta-divergence loss.
  The choice between options is controlled by the `beta_loss` parameter.
  
  The objective function is minimized with an alternating minimization of `W`
  and `H`.
  
  Note that the transformed data is named `W` and the components matrix is
  named `H`. In the NMF literature, the naming convention is usually the opposite
  since the data matrix `X` is transposed.
  
  Read more in the :ref:`User Guide <MiniBatchNMF>`.
  
  Parameters
  ----------
  n_components : int, default=None
      Number of components, if `n_components` is not set all features
      are kept.
  
  init : {'random', 'nndsvd', 'nndsvda', 'nndsvdar', 'custom'}, default=None
      Method used to initialize the procedure.
      Valid options:
  
      - `None`: 'nndsvda' if `n_components <= min(n_samples, n_features)`,
        otherwise random.
  
      - `'random'`: non-negative random matrices, scaled with:
        `sqrt(X.mean() / n_components)`
  
      - `'nndsvd'`: Nonnegative Double Singular Value Decomposition (NNDSVD)
        initialization (better for sparseness).
  
      - `'nndsvda'`: NNDSVD with zeros filled with the average of X
        (better when sparsity is not desired).
  
      - `'nndsvdar'` NNDSVD with zeros filled with small random values
        (generally faster, less accurate alternative to NNDSVDa
        for when sparsity is not desired).
  
      - `'custom'`: Use custom matrices `W` and `H` which must both be provided.
  
  batch_size : int, default=1024
      Number of samples in each mini-batch. Large batch sizes
      give better long-term convergence at the cost of a slower start.
  
  beta_loss : float or {'frobenius', 'kullback-leibler',             'itakura-saito'}, default='frobenius'
      Beta divergence to be minimized, measuring the distance between `X`
      and the dot product `WH`. Note that values different from 'frobenius'
      (or 2) and 'kullback-leibler' (or 1) lead to significantly slower
      fits. Note that for `beta_loss <= 0` (or 'itakura-saito'), the input
      matrix `X` cannot contain zeros.
  
  tol : float, default=1e-4
      Control early stopping based on the norm of the differences in `H`
      between 2 steps. To disable early stopping based on changes in `H`, set
      `tol` to 0.0.
  
  max_no_improvement : int, default=10
      Control early stopping based on the consecutive number of mini batches
      that does not yield an improvement on the smoothed cost function.
      To disable convergence detection based on cost function, set
      `max_no_improvement` to None.
  
  max_iter : int, default=200
      Maximum number of iterations over the complete dataset before
      timing out.
  
  alpha_W : float, default=0.0
      Constant that multiplies the regularization terms of `W`. Set it to zero
      (default) to have no regularization on `W`.
  
  alpha_H : float or "same", default="same"
      Constant that multiplies the regularization terms of `H`. Set it to zero to
      have no regularization on `H`. If "same" (default), it takes the same value as
      `alpha_W`.
  
  l1_ratio : float, default=0.0
      The regularization mixing parameter, with 0 <= l1_ratio <= 1.
      For l1_ratio = 0 the penalty is an elementwise L2 penalty
      (aka Frobenius Norm).
      For l1_ratio = 1 it is an elementwise L1 penalty.
      For 0 < l1_ratio < 1, the penalty is a combination of L1 and L2.
  
  forget_factor : float, default=0.7
      Amount of rescaling of past information. Its value could be 1 with
      finite datasets. Choosing values < 1 is recommended with online
      learning as more recent batches will weight more than past batches.
  
  fresh_restarts : bool, default=False
      Whether to completely solve for W at each step. Doing fresh restarts will likely
      lead to a better solution for a same number of iterations but it is much slower.
  
  fresh_restarts_max_iter : int, default=30
      Maximum number of iterations when solving for W at each step. Only used when
      doing fresh restarts. These iterations may be stopped early based on a small
      change of W controlled by `tol`.
  
  transform_max_iter : int, default=None
      Maximum number of iterations when solving for W at transform time.
      If None, it defaults to `max_iter`.
  
  random_state : int, RandomState instance or None, default=None
      Used for initialisation (when ``init`` == 'nndsvdar' or
      'random'), and in Coordinate Descent. Pass an int for reproducible
      results across multiple function calls.
      See :term:`Glossary <random_state>`.
  
  verbose : bool, default=False
      Whether to be verbose.
  
  Attributes
  ----------
  components_ : ndarray of shape (n_components, n_features)
      Factorization matrix, sometimes called 'dictionary'.
  
  n_components_ : int
      The number of components. It is same as the `n_components` parameter
      if it was given. Otherwise, it will be same as the number of
      features.
  
  reconstruction_err_ : float
      Frobenius norm of the matrix difference, or beta-divergence, between
      the training data `X` and the reconstructed data `WH` from
      the fitted model.
  
  n_iter_ : int
      Actual number of started iterations over the whole dataset.
  
  n_steps_ : int
      Number of mini-batches processed.
  
  n_features_in_ : int
      Number of features seen during :term:`fit`.
  
  feature_names_in_ : ndarray of shape (`n_features_in_`,)
      Names of features seen during :term:`fit`. Defined only when `X`
      has feature names that are all strings.
  
  See Also
  --------
  NMF : Non-negative matrix factorization.
  MiniBatchDictionaryLearning : Finds a dictionary that can best be used to represent
      data using a sparse code.
  
  References
  ----------
  .. [1] :doi:`"Fast local algorithms for large scale nonnegative matrix and tensor
     factorizations" <10.1587/transfun.E92.A.708>`
     Cichocki, Andrzej, and P. H. A. N. Anh-Huy. IEICE transactions on fundamentals
     of electronics, communications and computer sciences 92.3: 708-721, 2009.
  
  .. [2] :doi:`"Algorithms for nonnegative matrix factorization with the
     beta-divergence" <10.1162/NECO_a_00168>`
     Fevotte, C., & Idier, J. (2011). Neural Computation, 23(9).
  
  .. [3] :doi:`"Online algorithms for nonnegative matrix factorization with the
     Itakura-Saito divergence" <10.1109/ASPAA.2011.6082314>`
     Lefevre, A., Bach, F., Fevotte, C. (2011). WASPA.
  
  Examples
  --------
  >>> import numpy as np
  >>> X = np.array([[1, 1], [2, 1], [3, 1.2], [4, 1], [5, 0.8], [6, 1]])
  >>> from sklearn.decomposition import MiniBatchNMF
  >>> model = MiniBatchNMF(n_components=2, init='random', random_state=0)
  >>> W = model.fit_transform(X)
  >>> H = model.components_
class_docstr_tok: ["Mini-Batch","Non-Negative","Matrix","Factorization","(","NMF",")",".","..","versionadded",":",":","1.1","Find","two","non-negative","matrices",",","i.e",".","matrices","with","all","non-negative","elements",",","(","`","W","`",",","`","H","`",")","whose","product","approximates","the","non-negative","matrix","`","X","`",".","This","factorization","can","be","used","for","example","for","dimensionality","reduction",",","source","separation","or","topic","extraction",".","The","objective","function","is",":","..","math",":",":","L","(","W",",","H",")","&","=","0.5","*","||X","-","WH||_","{","loss","}","^2","&","+","alpha\\_W","*","l1\\_ratio","*","n\\_features","*","||vec","(","W",")","||_1","&","+","alpha\\_H","*","l1\\_ratio","*","n\\_samples","*","||vec","(","H",")","||_1","&","+","0.5","*","alpha\\_W","*","(","1","-","l1\\_ratio",")","*","n\\_features","*","||W||_","{","Fro","}","^2","&","+","0.5","*","alpha\\_H","*","(","1","-","l1\\_ratio",")","*","n\\_samples","*","||H||_","{","Fro","}","^2","Where",":",":","math",":","`","||A||_","{","Fro","}","^2","=","\\sum_","{","i",",","j","}","A_","{","ij","}","^2","`","(","Frobenius","norm",")",":","math",":","`","||vec","(","A",")","||_1","=","\\sum_","{","i",",","j","}","abs","(","A_","{","ij","}",")","`","(","Elementwise","L1","norm",")","The","generic","norm",":","math",":","`","||X","-","WH||_","{","loss","}","^2","`","may","represent","the","Frobenius","norm","or","another","supported","beta-divergence","loss",".","The","choice","between","options","is","controlled","by","the","`","beta_loss","`","parameter",".","The","objective","function","is","minimized","with","an","alternating","minimization","of","`","W","`","and","`","H","`",".","Note","that","the","transformed","data","is","named","`","W","`","and","the","components","matrix","is","named","`","H","`",".","In","the","NMF","literature",",","the","naming","convention","is","usually","the","opposite","since","the","data","matrix","`","X","`","is","transposed",".","Read","more","in","the",":","ref",":","`","User","Guide","<","MiniBatchNMF",">","`",".","Parameters","--","--","--","--","--","n_components",":","int",",","default=None","Number","of","components",",","if","`","n_components","`","is","not","set","all","features","are","kept",".","init",":","{","'random","'",",","'nndsvd","'",",","'nndsvda","'",",","'nndsvdar","'",",","'custom","'","}",",","default=None","Method","used","to","initialize","the","procedure",".","Valid","options",":","-","`","None","`",":","'nndsvda","'","if","`","n_components","<","=","min","(","n_samples",",","n_features",")","`",",","otherwise","random",".","-","`","'random","'","`",":","non-negative","random","matrices",",","scaled","with",":","`","sqrt","(","X.mean","(",")","\/","n_components",")","`","-","`","'nndsvd","'","`",":","Nonnegative","Double","Singular","Value","Decomposition","(","NNDSVD",")","initialization","(","better","for","sparseness",")",".","-","`","'nndsvda","'","`",":","NNDSVD","with","zeros","filled","with","the","average","of","X","(","better","when","sparsity","is","not","desired",")",".","-","`","'nndsvdar","'","`","NNDSVD","with","zeros","filled","with","small","random","values","(","generally","faster",",","less","accurate","alternative","to","NNDSVDa","for","when","sparsity","is","not","desired",")",".","-","`","'custom","'","`",":","Use","custom","matrices","`","W","`","and","`","H","`","which","must","both","be","provided",".","batch_size",":","int",",","default=1024","Number","of","samples","in","each","mini-batch",".","Large","batch","sizes","give","better","long-term","convergence","at","the","cost","of","a","slower","start",".","beta_loss",":","float","or","{","'frobenius","'",",","'kullback-leibler","'",",","'itakura-saito","'","}",",","default='frobenius'","Beta","divergence","to","be","minimized",",","measuring","the","distance","between","`","X","`","and","the","dot","product","`","WH","`",".","Note","that","values","different","from","'frobenius'","(","or","2",")","and","'kullback-leibler","'","(","or","1",")","lead","to","significantly","slower","fits",".","Note","that","for","`","beta_loss","<","=","0","`","(","or","'itakura-saito","'",")",",","the","input","matrix","`","X","`","can","not","contain","zeros",".","tol",":","float",",","default=1e-4","Control","early","stopping","based","on","the","norm","of","the","differences","in","`","H","`","between","2","steps",".","To","disable","early","stopping","based","on","changes","in","`","H","`",",","set","`","tol","`","to","0.0.","max_no_improvement",":","int",",","default=10","Control","early","stopping","based","on","the","consecutive","number","of","mini","batches","that","does","not","yield","an","improvement","on","the","smoothed","cost","function",".","To","disable","convergence","detection","based","on","cost","function",",","set","`","max_no_improvement","`","to","None",".","max_iter",":","int",",","default=200","Maximum","number","of","iterations","over","the","complete","dataset","before","timing","out",".","alpha_W",":","float",",","default=0.0","Constant","that","multiplies","the","regularization","terms","of","`","W","`",".","Set","it","to","zero","(","default",")","to","have","no","regularization","on","`","W","`",".","alpha_H",":","float","or","``","same","''",",","default=","''","same","''","Constant","that","multiplies","the","regularization","terms","of","`","H","`",".","Set","it","to","zero","to","have","no","regularization","on","`","H","`",".","If","``","same","''","(","default",")",",","it","takes","the","same","value","as","`","alpha_W","`",".","l1_ratio",":","float",",","default=0.0","The","regularization","mixing","parameter",",","with","0","<","=","l1_ratio","<","=","1",".","For","l1_ratio","=","0","the","penalty","is","an","elementwise","L2","penalty","(","aka","Frobenius","Norm",")",".","For","l1_ratio","=","1","it","is","an","elementwise","L1","penalty",".","For","0","<","l1_ratio","<","1",",","the","penalty","is","a","combination","of","L1","and","L2",".","forget_factor",":","float",",","default=0.7","Amount","of","rescaling","of","past","information",".","Its","value","could","be","1","with","finite","datasets",".","Choosing","values","<","1","is","recommended","with","online","learning","as","more","recent","batches","will","weight","more","than","past","batches",".","fresh_restarts",":","bool",",","default=False","Whether","to","completely","solve","for","W","at","each","step",".","Doing","fresh","restarts","will","likely","lead","to","a","better","solution","for","a","same","number","of","iterations","but","it","is","much","slower",".","fresh_restarts_max_iter",":","int",",","default=30","Maximum","number","of","iterations","when","solving","for","W","at","each","step",".","Only","used","when","doing","fresh","restarts",".","These","iterations","may","be","stopped","early","based","on","a","small","change","of","W","controlled","by","`","tol","`",".","transform_max_iter",":","int",",","default=None","Maximum","number","of","iterations","when","solving","for","W","at","transform","time",".","If","None",",","it","defaults","to","`","max_iter","`",".","random_state",":","int",",","RandomState","instance","or","None",",","default=None","Used","for","initialisation","(","when","``","init","``","==","'nndsvdar","'","or","'random","'",")",",","and","in","Coordinate","Descent",".","Pass","an","int","for","reproducible","results","across","multiple","function","calls",".","See",":","term",":","`","Glossary","<","random_state",">","`",".","verbose",":","bool",",","default=False","Whether","to","be","verbose",".","Attributes","--","--","--","--","--","components_",":","ndarray","of","shape","(","n_components",",","n_features",")","Factorization","matrix",",","sometimes","called","'dictionary","'",".","n_components_",":","int","The","number","of","components",".","It","is","same","as","the","`","n_components","`","parameter","if","it","was","given",".","Otherwise",",","it","will","be","same","as","the","number","of","features",".","reconstruction_err_",":","float","Frobenius","norm","of","the","matrix","difference",",","or","beta-divergence",",","between","the","training","data","`","X","`","and","the","reconstructed","data","`","WH","`","from","the","fitted","model",".","n_iter_",":","int","Actual","number","of","started","iterations","over","the","whole","dataset",".","n_steps_",":","int","Number","of","mini-batches","processed",".","n_features_in_",":","int","Number","of","features","seen","during",":","term",":","`","fit","`",".","feature_names_in_",":","ndarray","of","shape","(","`","n_features_in_","`",",",")","Names","of","features","seen","during",":","term",":","`","fit","`",".","Defined","only","when","`","X","`","has","feature","names","that","are","all","strings",".","See","Also","--","--","--","--","NMF",":","Non-negative","matrix","factorization",".","MiniBatchDictionaryLearning",":","Finds","a","dictionary","that","can","best","be","used","to","represent","data","using","a","sparse","code",".","References","--","--","--","--","--","..","[","1","]",":","doi",":","`","``","Fast","local","algorithms","for","large","scale","nonnegative","matrix","and","tensor","factorizations","''","<","10.1587\/transfun.E92.A.708",">","`","Cichocki",",","Andrzej",",","and","P.","H.","A.","N.","Anh-Huy",".","IEICE","transactions","on","fundamentals","of","electronics",",","communications","and","computer","sciences","92.3",":","708-721",",","2009",".","..","[","2","]",":","doi",":","`","``","Algorithms","for","nonnegative","matrix","factorization","with","the","beta-divergence","''","<","10.1162\/NECO_a_00168",">","`","Fevotte",",","C.",",","&","Idier",",","J",".","(","2011",")",".","Neural","Computation",",","23","(","9",")",".","..","[","3","]",":","doi",":","`","``","Online","algorithms","for","nonnegative","matrix","factorization","with","the","Itakura-Saito","divergence","''","<","10.1109\/ASPAA.2011.6082314",">","`","Lefevre",",","A.",",","Bach",",","F.",",","Fevotte",",","C.","(","2011",")",".","WASPA",".","Examples","--","--","--","--",">",">",">","import","numpy","as","np",">",">",">","X","=","np.array","(","[","[","1",",","1","]",",","[","2",",","1","]",",","[","3",",","1.2","]",",","[","4",",","1","]",",","[","5",",","0.8","]",",","[","6",",","1","]","]",")",">",">",">","from","sklearn.decomposition","import","MiniBatchNMF",">",">",">","model","=","MiniBatchNMF","(","n_components=2",",","init='random","'",",","random_state=0",")",">",">",">","W","=","model.fit_transform","(","X",")",">",">",">","H","=","model.components_"]
code: def __init__(
      self,
      n_components=None,
      *,
      init=None,
      batch_size=1024,
      beta_loss="frobenius",
      tol=1e-4,
      max_no_improvement=10,
      max_iter=200,
      alpha_W=0.0,
      alpha_H="same",
      l1_ratio=0.0,
      forget_factor=0.7,
      fresh_restarts=False,
      fresh_restarts_max_iter=30,
      transform_max_iter=None,
      random_state=None,
      verbose=0,
  ):
      super().__init__(
          n_components=n_components,
          init=init,
          beta_loss=beta_loss,
          tol=tol,
          max_iter=max_iter,
          random_state=random_state,
          alpha_W=alpha_W,
          alpha_H=alpha_H,
          l1_ratio=l1_ratio,
          verbose=verbose,
      )
  
      self.max_no_improvement = max_no_improvement
      self.batch_size = batch_size
      self.forget_factor = forget_factor
      self.fresh_restarts = fresh_restarts
      self.fresh_restarts_max_iter = fresh_restarts_max_iter
      self.transform_max_iter = transform_max_iter
  
imports: import itertools
  import time
  import warnings
  from abc import ABC
  from math import sqrt
  from numbers import Integral, Real
  import numpy
  import scipy.sparse
  from scipy import linalg
  from .._config import config_context
  from ..base import BaseEstimator, ClassNamePrefixFeaturesOutMixin, TransformerMixin, _fit_context
  from ..exceptions import ConvergenceWarning
  from ..utils import check_array, check_random_state, gen_batches, metadata_routing
  from ..utils._param_validation import Interval, StrOptions, validate_params
  from ..utils.extmath import randomized_svd, safe_sparse_dot, squared_norm
  from ..utils.validation import check_is_fitted, check_non_negative
  from ._cdnmf_fast import _update_cdnmf_fast
label_desc: Use image node_id 1 to create a new MiniBatchNMF object from inherited base classes: _BaseNMF with example: obj = MiniBatchNMF(n_components)