def _johnson_lindenstrauss_min_dim(n_samples: int, eps: float = 0.1) -> int | np.integer:
        """Find a 'safe' number of components for random projection.

        Implements the Johnson-Lindenstrauss lemma to determine the minimum number
        of components needed to approximately preserve distances.

        Args:
            n_samples (int): Number of samples in the dataset.
            eps (float, optional): Minimum distortion rate. Defaults to ``0.1``.

        Returns:
            int: Minimum number of components required.

        References:
            .. [1] Dasgupta, S. and Gupta, A., "An elementary proof of a theorem
               of Johnson and Lindenstrauss," Random Struct. Algor., 22: 60-65,
               2003.
        """
        denominator = (eps**2 / 2) - (eps**3 / 3)
        return (4 * np.log(n_samples) / denominator).astype(np.int64)
Find a 'safe' number of components for random projection.

        Implements the Johnson-Lindenstrauss lemma to determine the minimum number
        of components needed to approximately preserve distances.

        Args:
            n_samples (int): Number of samples in the dataset.
            eps (float, optional): Minimum distortion rate. Defaults to ``0.1``.

        Returns:
            int: Minimum number of components required.

        References:
            .. [1] Dasgupta, S. and Gupta, A., "An elementary proof of a theorem
               of Johnson and Lindenstrauss," Random Struct. Algor., 22: 60-65,
               2003.
        
src/anomalib/models/components/dimensionality_reduction/random_projection.py