Repository: scikit-learn/scikit-learn
File: sklearn/covariance/_robust_covariance.py (Python)

Code before:
    location, covariance, det, support_indices, dist = results
    # Convert from list of indices to boolean mask.
    support = np.bincount(support_indices, minlength=n_samples).astype(bool)
    return location, covariance, det, support, dist


def _consistency_factor(n_features, alpha):
    """Multiplicative factor to make covariance estimate consistent
    at the normal distribution, as described in [Pison2002]_.

    Parameters
    ----------
    n_features : int
        Number of features.

    alpha : float
        Parameter related to the proportion of discarded points.
        This parameter must be in the range (0, 1).

    Returns
    -------
    c_alpha : float
        Scaling factor to make covariance matrix consistent.

    References
    ----------
    .. [Croux1999] Croux, C., Haesbroeck, G. "Influence Function and
        Efficiency of the Minimum Covariance Determinant Scatter Matrix
        Estimator" Journal of Multivariate Analysis 71(2) (1999) 161-190

    .. [Pison2002] Pison, G., Van Aelst, S., Willems, G., "Small sample
        corrections for LTS and MCD" Metrika 55(1) (2002) 111-123
    """
    # Formulas as in Sec 3 of Pison 2002, derived from Eq 4.2 in Croux 1999
    q_alpha = chi2.ppf(alpha, df=n_features)
    c_alpha = alpha / chi2.cdf(q_alpha, n_features + 2)
    return c_alpha


def select_candidates(
    X,
    n_support,
    n_trials,
    select=1,
    n_iter=30,
    verbose=False,
    cov_computation_method=empirical_covariance,
    random_state=None,
):
    """Finds the best pure subset of observations to compute MCD from it.


Review comment (suggestion):
```suggestion
    ----------
    .. [Butler1993] R. W. Butler. P. L. Davies. M. Jhun. "Asymptotics for the Minimum Covariance Determinant Estimator." Ann. Statist. 21 (3) 1385 - 1400, September, 1993. https://doi.org/10.1214/aos/1176349264]
```

Code after:
    location, covariance, det, support_indices, dist = results
    # Convert from list of indices to boolean mask.
    support = np.bincount(support_indices, minlength=n_samples).astype(bool)
    return location, covariance, det, support, dist


def _consistency_factor(n_features, alpha):
    """Multiplicative factor to make covariance estimate consistent
    at the normal distribution, as described in [Pison2002]_.

    Parameters
    ----------
    n_features : int
        Number of features.

    alpha : float
        Parameter related to the proportion of discarded points.
        This parameter must be in the range (0, 1).

    Returns
    -------
    c_alpha : float
        Scaling factor to make covariance matrix consistent.

    References
    ----------
    .. [Butler1993] R. W. Butler. P. L. Davies. M. Jhun. "Asymptotics for the
        Minimum Covariance Determinant Estimator." Ann. Statist. 21 (3)
        1385 - 1400, September, 1993. https://doi.org/10.1214/aos/1176349264]

    .. [Croux1999] Croux, C., Haesbroeck, G. "Influence Function and
        Efficiency of the Minimum Covariance Determinant Scatter Matrix
        Estimator" Journal of Multivariate Analysis 71(2) (1999) 161-190

    .. [Pison2002] Pison, G., Van Aelst, S., Willems, G., "Small sample
        corrections for LTS and MCD" Metrika 55(1) (2002) 111-123
    """
    # Formulas as in Sec 3 of Pison 2002, derived from Eq 4.2 in Croux 1999
    q_alpha = chi2.ppf(alpha, df=n_features)
    c_alpha = alpha / chi2.cdf(q_alpha, n_features + 2)
    return c_alpha


def select_candidates(
    X,
    n_support,
    n_trials,
    select=1,
    n_iter=30,
    verbose=False,
    cov_computation_method=empirical_covariance,