def fit(self, data: torch.Tensor) -> None:
        """Fit the GMM to the input data using EM algorithm.

        Args:
            data (torch.Tensor): Input data to fit the model to.
                Shape: ``(n_samples, n_features)``.
        """
        self._initialize_parameters_kmeans(data)

        log_likelihood_old = 0
        converged = False
        for _ in range(self.n_iter):
            # E-step
            log_likelihood_new, resp = self._e_step(data)
            # M-step
            self._m_step(data, resp)

            # Check for convergence
            if torch.abs(log_likelihood_new - log_likelihood_old) < self.tol:
                converged = True
                break
            log_likelihood_old = log_likelihood_new

        if not converged:
            logger.warning(
                f"GMM did not converge after {self.n_iter} iterations. Consider increasing the number of iterations.",
            )
Fit the GMM to the input data using EM algorithm.

        Args:
            data (torch.Tensor): Input data to fit the model to.
                Shape: ``(n_samples, n_features)``.
        
src/anomalib/models/components/cluster/gmm.py