def kendalltau_dist(params1, params2=None):
assert params2 is None or len(params1) == len(params2)<EOL>ranks1 = rankdata(params1, method="<STR_LIT>")<EOL>if params2 is None:<EOL><INDENT>ranks2 = np.arange(<NUM_LIT:1>, len(params1) + <NUM_LIT:1>, dtype=float)<EOL><DEDENT>else:<EOL><INDENT>ranks2 = rankdata(params2, method="<STR_LIT>")<EOL><DEDENT>tau, _ = kendalltau(ranks1, ranks2)<EOL>n_items = len(params1)<EOL>n_pairs = n_items * (n_items - <NUM_LIT:1>) / <NUM_LIT:2><EOL>return round((n_pairs - n_pairs * tau) / <NUM_LIT:2>)<EOL>
r"""Compute the Kendall tau distance between two models.

    This function computes the Kendall tau distance between the rankings
    induced by two parameter vectors. Let :math:`\sigma_i` be the rank of item
    ``i`` in the model described by ``params1``, and :math:`\tau_i` be its rank
    in the model described by ``params2``. The Kendall tau distance is defined
    as the number of pairwise disagreements between the two rankings, i.e.,

    .. math::

      \sum_{i=1}^N \sum_{j=1}^N
        \mathbf{1} \{ \sigma_i > \sigma_j \wedge \tau_i < \tau_j \}

    By convention, items with the lowest parameters are ranked first (i.e.,
    sorted using the natural order).

    If the argument ``params2`` is ``None``, the second model is assumed to
    rank the items by their index: item ``0`` has rank 1, item ``1`` has rank
    2, etc.

    If some values are equal within a parameter vector, all items are given a
    distinct rank, corresponding to the order in which the values occur.

    Parameters
    ----------
    params1 : array_like
        Parameters of the first model.
    params2 : array_like, optional
        Parameters of the second model.

    Returns
    -------
    dist : float
        Kendall tau distance.