nodes: 0, module; 1, function_definition; 2, function_name:assortativity_indicators; 3, parameters; 4, block; 5, identifier:user; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, comment:# Use all indicator except reporting variables and attributes; 11, expression_statement; 12, expression_statement; 13, for_statement; 14, expression_statement; 15, for_statement; 16, return_statement; 17, comment:"""
      Computes the assortativity of indicators.
  
      This indicator measures the similarity of the current user with his
      correspondants, for all bandicoot indicators. For each one, it calculates
      the variance of the current user's value with the values for all his
      correspondants:
  
      .. math::
  
          \\text{assortativity}(J) = \\frac{1}{n} \\sum_i^n (J_{\\text{user}} - J_{\\text{i}})^2
  
      for the indicator :math:`J`, and all the :math:`n` correspondents.
      """; 18, assignment; 19, assignment; 20, assignment; 21, assignment; 22, assignment; 23, pattern_list; 24, call; 25, block; 26, assignment; 27, identifier:i; 28, identifier:count_indicator; 29, block; 30, identifier:assortativity; 31, identifier:matrix; 32, call; 33, identifier:count_indicator; 34, call; 35, identifier:total_indicator; 36, call; 37, identifier:ego_indics; 38, call; 39, identifier:ego_indics; 40, dictionary_comprehension; 41, identifier:i; 42, identifier:u_name; 43, identifier:enumerate; 44, argument_list; 45, expression_statement; 46, comment:# Non reciprocated edge; 47, if_statement; 48, expression_statement; 49, for_statement; 50, identifier:assortativity; 51, dictionary; 52, expression_statement; 53, identifier:matrix_undirected_unweighted; 54, argument_list; 55, identifier:defaultdict; 56, argument_list; 57, identifier:defaultdict; 58, argument_list; 59, identifier:all; 60, argument_list; 61, pair; 62, for_in_clause; 63, if_clause; 64, call; 65, assignment; 66, boolean_operator; 67, block; 68, assignment; 69, identifier:a; 70, identifier:ego_indics; 71, block; 72, assignment; 73, identifier:user; 74, identifier:int; 75, identifier:int; 76, identifier:user; 77, keyword_argument; 78, identifier:a; 79, identifier:value; 80, pattern_list; 81, call; 82, boolean_operator; 83, identifier:matrix_index; 84, argument_list; 85, identifier:correspondent; 86, call; 87, boolean_operator; 88, comparison_operator:matrix[0][i] == 0; 89, continue_statement; 90, identifier:neighbor_indics; 91, call; 92, if_statement; 93, subscript; 94, binary_operator:count_indicator[i] / total_indicator[i]; 95, identifier:flatten; 96, True; 97, identifier:a; 98, identifier:value; 99, attribute; 100, argument_list; 101, boolean_operator; 102, comparison_operator:a[:10] != "attributes"; 103, identifier:user; 104, attribute; 105, argument_list; 106, comparison_operator:correspondent is None; 107, comparison_operator:u_name == user.name; 108, subscript; 109, integer:0; 110, identifier:all; 111, argument_list; 112, boolean_operator; 113, block; 114, identifier:assortativity; 115, identifier:i; 116, subscript; 117, subscript; 118, identifier:ego_indics; 119, identifier:items; 120, comparison_operator:a != "name"; 121, comparison_operator:a[:11] != "reporting__"; 122, subscript; 123, string:"attributes"; 124, attribute; 125, identifier:get; 126, identifier:u_name; 127, None; 128, identifier:correspondent; 129, None; 130, identifier:u_name; 131, attribute; 132, subscript; 133, identifier:i; 134, identifier:correspondent; 135, keyword_argument; 136, comparison_operator:ego_indics[a] is not None; 137, comparison_operator:neighbor_indics[a] is not None; 138, expression_statement; 139, expression_statement; 140, identifier:count_indicator; 141, identifier:i; 142, identifier:total_indicator; 143, identifier:i; 144, identifier:a; 145, string:"name"; 146, subscript; 147, string:"reporting__"; 148, identifier:a; 149, slice; 150, identifier:user; 151, identifier:network; 152, identifier:user; 153, identifier:name; 154, identifier:matrix; 155, integer:0; 156, identifier:flatten; 157, True; 158, subscript; 159, None; 160, subscript; 161, None; 162, augmented_assignment; 163, augmented_assignment; 164, identifier:a; 165, slice; 166, integer:10; 167, identifier:ego_indics; 168, identifier:a; 169, identifier:neighbor_indics; 170, identifier:a; 171, subscript; 172, integer:1; 173, subscript; 174, binary_operator:(ego_indics[a] - neighbor_indics[a]) ** 2; 175, integer:11; 176, identifier:total_indicator; 177, identifier:a; 178, identifier:count_indicator; 179, identifier:a; 180, parenthesized_expression; 181, integer:2; 182, binary_operator:ego_indics[a] - neighbor_indics[a]; 183, subscript; 184, subscript; 185, identifier:ego_indics; 186, identifier:a; 187, identifier:neighbor_indics; 188, identifier:a
code: def assortativity_indicators(user):
      """
      Computes the assortativity of indicators.
  
      This indicator measures the similarity of the current user with his
      correspondants, for all bandicoot indicators. For each one, it calculates
      the variance of the current user's value with the values for all his
      correspondants:
  
      .. math::
  
          \\text{assortativity}(J) = \\frac{1}{n} \\sum_i^n (J_{\\text{user}} - J_{\\text{i}})^2
  
      for the indicator :math:`J`, and all the :math:`n` correspondents.
      """
  
      matrix = matrix_undirected_unweighted(user)
  
      count_indicator = defaultdict(int)
      total_indicator = defaultdict(int)
  
      # Use all indicator except reporting variables and attributes
      ego_indics = all(user, flatten=True)
      ego_indics = {a: value for a, value in ego_indics.items()
                    if a != "name" and a[:11] != "reporting__" and
                    a[:10] != "attributes"}
  
      for i, u_name in enumerate(matrix_index(user)):
          correspondent = user.network.get(u_name, None)
  
          # Non reciprocated edge
          if correspondent is None or u_name == user.name or matrix[0][i] == 0:
              continue
  
          neighbor_indics = all(correspondent, flatten=True)
          for a in ego_indics:
              if ego_indics[a] is not None and neighbor_indics[a] is not None:
                  total_indicator[a] += 1
                  count_indicator[a] += (ego_indics[a] - neighbor_indics[a]) ** 2
  
      assortativity = {}
      for i in count_indicator:
          assortativity[i] = count_indicator[i] / total_indicator[i]
  
      return assortativity