def fit(self, dataset: torch.Tensor) -> None:
        """Fit the KDE model to the input dataset.

        Computes the bandwidth matrix using Scott's rule and transforms the data
        accordingly.

        Args:
            dataset (torch.Tensor): Input dataset of shape ``(N, D)`` where ``N``
                is the number of samples and ``D`` is the dimension.

        Example:
            >>> kde = GaussianKDE()
            >>> features = torch.randn(100, 10)
            >>> kde.fit(features)
        """
        num_samples, dimension = dataset.shape

        # compute scott's bandwidth factor
        factor = num_samples ** (-1 / (dimension + 4))

        cov_mat = self.cov(dataset.T)
        inv_cov_mat = torch.linalg.inv(cov_mat)
        inv_cov = inv_cov_mat / factor**2

        # transform data to account for bandwidth
        bw_transform = torch.linalg.cholesky(inv_cov)
        dataset = torch.matmul(dataset, bw_transform)

        norm = torch.prod(torch.diag(bw_transform))
        norm *= math.pow((2 * math.pi), (-dimension / 2))

        self.bw_transform = bw_transform
        self.dataset = dataset
        self.norm = norm
Fit the KDE model to the input dataset.

        Computes the bandwidth matrix using Scott's rule and transforms the data
        accordingly.

        Args:
            dataset (torch.Tensor): Input dataset of shape ``(N, D)`` where ``N``
                is the number of samples and ``D`` is the dimension.

        Example:
            >>> kde = GaussianKDE()
            >>> features = torch.randn(100, 10)
            >>> kde.fit(features)
        
src/anomalib/models/components/stats/kde.py