r"""Calculate the normalized effective sample size :math:`ESS` [LC95]_
    of samples with ``weights`` :math:`\omega_i`.  :math:`ESS=0` is
    terrible and :math:`ESS=1` is perfect.

    .. math::

        ESS = \frac{1}{1+C^2}

    where

    .. math::

        C^2 = \frac{1}{N} \sum_{i=1}^N (N \bar{\omega}_i - 1)^2

    .. math::

        \bar{\omega}_i = \frac{\omega_i}{\sum_i \omega_i}

    :param weights:

        Vector-like array; the samples' weights

def ess(weights):
    r"""Calculate the normalized effective sample size :math:`ESS` [LC95]_
    of samples with ``weights`` :math:`\omega_i`.  :math:`ESS=0` is
    terrible and :math:`ESS=1` is perfect.

    .. math::

        ESS = \frac{1}{1+C^2}

    where

    .. math::

        C^2 = \frac{1}{N} \sum_{i=1}^N (N \bar{\omega}_i - 1)^2

    .. math::

        \bar{\omega}_i = \frac{\omega_i}{\sum_i \omega_i}

    :param weights:

        Vector-like array; the samples' weights

    """
    # normalize weights
    w = _np.asarray(weights) / _np.sum(weights)

    # ess
    coeff_var = _np.sum((len(w) * w - 1)**2) / len(w)

    return  1.0 / (1.0 + coeff_var)