code: def max_posterior(lnps_per_walker, dim):
      
      if len(lnps_per_walker.shape) != 2:
          raise ValueError("lnps_per_walker must have shape "
                           "nwalkers x niterations")
      # find the value to compare against
      max_p = lnps_per_walker.max()
      criteria = max_p - dim/2.
      nwalkers, _ = lnps_per_walker.shape
      burn_in_idx = numpy.empty(nwalkers, dtype=int)
      is_burned_in = numpy.empty(nwalkers, dtype=bool)
      # find the first iteration in each chain where the logpost has exceeded
      # max_p - dim/2
      for ii in range(nwalkers):
          chain = lnps_per_walker[ii, :]
          passedidx = numpy.where(chain >= criteria)[0]
          is_burned_in[ii] = passedidx.size > 0
          if is_burned_in[ii]:
              burn_in_idx[ii] = passedidx[0]
          else:
              burn_in_idx[ii] = NOT_BURNED_IN_ITER
      return burn_in_idx, is_burned_in
docs: Burn in based on samples being within dim/2 of maximum posterior.
  
      Parameters
      ----------
      lnps_per_walker : 2D array
          Array of values that are proportional to the log posterior values. Must
          have shape ``nwalkers x niterations``.
      dim : int
          The dimension of the parameter space.
  
      Returns
      -------
      burn_in_idx : array of int
          The burn in indices of each walker. If a walker is not burned in, its
          index will be be equal to the length of the chain.
      is_burned_in : array of bool
          Whether or not a walker is burned in.