nodes: 0, module; 1, function_definition; 2, function_name:mode_half_sample; 3, parameters; 4, block; 5, identifier:a; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, if_statement; 12, identifier:is_sorted; 13, False; 14, string:'''
      Estimate the mode using the Half Sample mode.
  
      A method to estimate the mode, as described in
      D. R. Bickel and R. Frühwirth (contributed equally),
      "On a fast, robust estimator of the mode: Comparisons to other
      robust estimators with applications,"
      Computational Statistics and Data Analysis 50, 3500-3530 (2006).
  
  
      Example
      =======
  
      >> import numpy as np
      >> np.random.seed(1392838)
      >> a = np.random.normal(1000, 200, size=1000)
      >> a[:100] = np.random.normal(2000, 300, size=100)
      >> b = np.sort(a)
      >> mode_half_sample(b, is_sorted=True)
      1041.9327885039545
  
      '''; 15, assignment; 16, not_operator; 17, block; 18, else_clause; 19, assignment; 20, comparison_operator:n == 1; 21, block; 22, elif_clause; 23, elif_clause; 24, else_clause; 25, identifier:a; 26, call; 27, identifier:is_sorted; 28, expression_statement; 29, block; 30, identifier:n; 31, call; 32, identifier:n; 33, integer:1; 34, return_statement; 35, comparison_operator:n == 2; 36, block; 37, comparison_operator:n == 3; 38, block; 39, block; 40, attribute; 41, argument_list; 42, assignment; 43, expression_statement; 44, identifier:len; 45, argument_list; 46, subscript; 47, identifier:n; 48, integer:2; 49, return_statement; 50, identifier:n; 51, integer:3; 52, expression_statement; 53, if_statement; 54, expression_statement; 55, expression_statement; 56, expression_statement; 57, return_statement; 58, identifier:np; 59, identifier:asanyarray; 60, identifier:a; 61, identifier:sdata; 62, call; 63, assignment; 64, identifier:sdata; 65, identifier:sdata; 66, integer:0; 67, binary_operator:0.5 * (sdata[0] + sdata[1]); 68, assignment; 69, comparison_operator:ind < 0; 70, block; 71, elif_clause; 72, else_clause; 73, assignment; 74, assignment; 75, assignment; 76, call; 77, attribute; 78, argument_list; 79, identifier:sdata; 80, identifier:a; 81, float:0.5; 82, parenthesized_expression; 83, identifier:ind; 84, binary_operator:-sdata[0] + 2 * sdata[1] - sdata[2]; 85, identifier:ind; 86, integer:0; 87, return_statement; 88, comparison_operator:ind > 0; 89, block; 90, block; 91, identifier:N; 92, call; 93, identifier:w; 94, binary_operator:sdata[(N-1):] - sdata[:(n-N+1)]; 95, identifier:ar; 96, call; 97, identifier:mode_half_sample; 98, argument_list; 99, identifier:np; 100, identifier:sort; 101, identifier:a; 102, binary_operator:sdata[0] + sdata[1]; 103, binary_operator:-sdata[0] + 2 * sdata[1]; 104, subscript; 105, binary_operator:0.5 * (sdata[0] + sdata[1]); 106, identifier:ind; 107, integer:0; 108, return_statement; 109, return_statement; 110, identifier:int; 111, argument_list; 112, subscript; 113, subscript; 114, attribute; 115, argument_list; 116, subscript; 117, keyword_argument; 118, subscript; 119, subscript; 120, unary_operator; 121, binary_operator:2 * sdata[1]; 122, identifier:sdata; 123, integer:2; 124, float:0.5; 125, parenthesized_expression; 126, binary_operator:0.5 * (sdata[1] + sdata[2]); 127, subscript; 128, call; 129, identifier:sdata; 130, slice; 131, identifier:sdata; 132, slice; 133, identifier:w; 134, identifier:argmin; 135, identifier:sdata; 136, slice; 137, identifier:is_sorted; 138, True; 139, identifier:sdata; 140, integer:0; 141, identifier:sdata; 142, integer:1; 143, subscript; 144, integer:2; 145, subscript; 146, binary_operator:sdata[0] + sdata[1]; 147, float:0.5; 148, parenthesized_expression; 149, identifier:sdata; 150, integer:1; 151, attribute; 152, argument_list; 153, parenthesized_expression; 154, parenthesized_expression; 155, identifier:ar; 156, binary_operator:ar+N; 157, identifier:sdata; 158, integer:0; 159, identifier:sdata; 160, integer:1; 161, subscript; 162, subscript; 163, binary_operator:sdata[1] + sdata[2]; 164, identifier:math; 165, identifier:ceil; 166, binary_operator:n / 2.0; 167, binary_operator:N-1; 168, binary_operator:n-N+1; 169, identifier:ar; 170, identifier:N; 171, identifier:sdata; 172, integer:0; 173, identifier:sdata; 174, integer:1; 175, subscript; 176, subscript; 177, identifier:n; 178, float:2.0; 179, identifier:N; 180, integer:1; 181, binary_operator:n-N; 182, integer:1; 183, identifier:sdata; 184, integer:1; 185, identifier:sdata; 186, integer:2; 187, identifier:n; 188, identifier:N
code: def mode_half_sample(a, is_sorted=False):
      '''
      Estimate the mode using the Half Sample mode.
  
      A method to estimate the mode, as described in
      D. R. Bickel and R. Frühwirth (contributed equally),
      "On a fast, robust estimator of the mode: Comparisons to other
      robust estimators with applications,"
      Computational Statistics and Data Analysis 50, 3500-3530 (2006).
  
  
      Example
      =======
  
      >> import numpy as np
      >> np.random.seed(1392838)
      >> a = np.random.normal(1000, 200, size=1000)
      >> a[:100] = np.random.normal(2000, 300, size=100)
      >> b = np.sort(a)
      >> mode_half_sample(b, is_sorted=True)
      1041.9327885039545
  
      '''
  
      a = np.asanyarray(a)
  
      if not is_sorted:
          sdata = np.sort(a)
      else:
          sdata = a
  
      n = len(sdata)
      if n == 1:
          return sdata[0]
      elif n == 2:
          return 0.5 * (sdata[0] + sdata[1])
      elif n == 3:
          ind = -sdata[0] + 2 * sdata[1] - sdata[2]
          if ind < 0:
              return 0.5 * (sdata[0] + sdata[1])
          elif ind > 0:
              return 0.5 * (sdata[1] + sdata[2])
          else:
              return sdata[1]
      else:
          N = int(math.ceil(n / 2.0))
          w = sdata[(N-1):] - sdata[:(n-N+1)]
          ar = w.argmin()
          return mode_half_sample(sdata[ar:ar+N], is_sorted=True)