nodes: 0, module; 1, function_definition; 2, function_name:calc_min_interval; 3, parameters; 4, block; 5, identifier:x; 6, identifier:alpha; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, if_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, return_statement; 18, comment:"""Internal method to determine the minimum interval of
      a given width
  
      Assumes that x is sorted numpy array.
      """; 19, assignment; 20, assignment; 21, assignment; 22, assignment; 23, assignment; 24, comparison_operator:len(interval_width) == 0; 25, block; 26, assignment; 27, assignment; 28, assignment; 29, list; 30, identifier:n; 31, call; 32, identifier:cred_mass; 33, binary_operator:1.0 - alpha; 34, identifier:interval_idx_inc; 35, call; 36, identifier:n_intervals; 37, binary_operator:n - interval_idx_inc; 38, identifier:interval_width; 39, binary_operator:x[interval_idx_inc:] - x[:n_intervals]; 40, call; 41, integer:0; 42, expression_statement; 43, return_statement; 44, identifier:min_idx; 45, call; 46, identifier:hdi_min; 47, subscript; 48, identifier:hdi_max; 49, subscript; 50, identifier:hdi_min; 51, identifier:hdi_max; 52, identifier:len; 53, argument_list; 54, float:1.0; 55, identifier:alpha; 56, identifier:int; 57, argument_list; 58, identifier:n; 59, identifier:interval_idx_inc; 60, subscript; 61, subscript; 62, identifier:len; 63, argument_list; 64, call; 65, list; 66, attribute; 67, argument_list; 68, identifier:x; 69, identifier:min_idx; 70, identifier:x; 71, binary_operator:min_idx + interval_idx_inc; 72, identifier:x; 73, call; 74, identifier:x; 75, slice; 76, identifier:x; 77, slice; 78, identifier:interval_width; 79, identifier:print_; 80, argument_list; 81, None; 82, None; 83, identifier:np; 84, identifier:argmin; 85, identifier:interval_width; 86, identifier:min_idx; 87, identifier:interval_idx_inc; 88, attribute; 89, argument_list; 90, identifier:interval_idx_inc; 91, identifier:n_intervals; 92, string; 93, identifier:np; 94, identifier:floor; 95, binary_operator:cred_mass * n; 96, string_content:Too few elements for interval calculation; 97, identifier:cred_mass; 98, identifier:n
code: def calc_min_interval(x, alpha):
      """Internal method to determine the minimum interval of
      a given width
  
      Assumes that x is sorted numpy array.
      """
  
      n = len(x)
      cred_mass = 1.0 - alpha
  
      interval_idx_inc = int(np.floor(cred_mass * n))
      n_intervals = n - interval_idx_inc
      interval_width = x[interval_idx_inc:] - x[:n_intervals]
  
      if len(interval_width) == 0:
          print_('Too few elements for interval calculation')
          return [None, None]
  
      min_idx = np.argmin(interval_width)
      hdi_min = x[min_idx]
      hdi_max = x[min_idx + interval_idx_inc]
      return [hdi_min, hdi_max]