nodes: 0, module; 1, function_definition; 2, function_name:kendalltau_dist; 3, parameters; 4, block; 5, identifier:params1; 6, default_parameter; 7, expression_statement; 8, assert_statement; 9, expression_statement; 10, if_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, return_statement; 15, identifier:params2; 16, None; 17, comment: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.
      """; 18, boolean_operator; 19, assignment; 20, comparison_operator:params2 is None; 21, block; 22, else_clause; 23, assignment; 24, assignment; 25, assignment; 26, call; 27, comparison_operator:params2 is None; 28, comparison_operator:len(params1) == len(params2); 29, identifier:ranks1; 30, call; 31, identifier:params2; 32, None; 33, expression_statement; 34, block; 35, pattern_list; 36, call; 37, identifier:n_items; 38, call; 39, identifier:n_pairs; 40, binary_operator:n_items * (n_items - 1) / 2; 41, identifier:round; 42, argument_list; 43, identifier:params2; 44, None; 45, call; 46, call; 47, identifier:rankdata; 48, argument_list; 49, assignment; 50, expression_statement; 51, identifier:tau; 52, identifier:_; 53, identifier:kendalltau; 54, argument_list; 55, identifier:len; 56, argument_list; 57, binary_operator:n_items * (n_items - 1); 58, integer:2; 59, binary_operator:(n_pairs - n_pairs * tau) / 2; 60, identifier:len; 61, argument_list; 62, identifier:len; 63, argument_list; 64, identifier:params1; 65, keyword_argument; 66, identifier:ranks2; 67, call; 68, assignment; 69, identifier:ranks1; 70, identifier:ranks2; 71, identifier:params1; 72, identifier:n_items; 73, parenthesized_expression; 74, parenthesized_expression; 75, integer:2; 76, identifier:params1; 77, identifier:params2; 78, identifier:method; 79, string:"ordinal"; 80, attribute; 81, argument_list; 82, identifier:ranks2; 83, call; 84, binary_operator:n_items - 1; 85, binary_operator:n_pairs - n_pairs * tau; 86, identifier:np; 87, identifier:arange; 88, integer:1; 89, binary_operator:len(params1) + 1; 90, keyword_argument; 91, identifier:rankdata; 92, argument_list; 93, identifier:n_items; 94, integer:1; 95, identifier:n_pairs; 96, binary_operator:n_pairs * tau; 97, call; 98, integer:1; 99, identifier:dtype; 100, identifier:float; 101, identifier:params2; 102, keyword_argument; 103, identifier:n_pairs; 104, identifier:tau; 105, identifier:len; 106, argument_list; 107, identifier:method; 108, string:"ordinal"; 109, identifier:params1
code: def kendalltau_dist(params1, params2=None):
      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.
      """
      assert params2 is None or len(params1) == len(params2)
      ranks1 = rankdata(params1, method="ordinal")
      if params2 is None:
          ranks2 = np.arange(1, len(params1) + 1, dtype=float)
      else:
          ranks2 = rankdata(params2, method="ordinal")
      tau, _ = kendalltau(ranks1, ranks2)
      n_items = len(params1)
      n_pairs = n_items * (n_items - 1) / 2
      return round((n_pairs - n_pairs * tau) / 2)