code: def combine_results(
      saved_logl, saved_nodeids, pointpile, main_iterator, mpi_comm=None
  ):
      """Combine a sequence of likelihoods and nodes into a summary dictionary.
  
      Parameters
      ----------
      saved_logl: list of floats
          loglikelihoods of dead points
      saved_nodeids: list of ints
          indices of dead points
      pointpile: :py:class:`PointPile`
          Point pile.
      main_iterator: :py:class:`BreadthFirstIterator`
          iterator used
      mpi_comm:
          MPI communicator object, or None if MPI is not used.
  
      Returns
      --------
      results: dict
          All information of the run. Important keys:
          Number of nested sampling iterations (niter),
          Evidence estimate (logz),
          Effective Sample Size (ess),
          H (information gain),
          weighted samples (weighted_samples),
          equally weighted samples (samples),
          best-fit point information (maximum_likelihood),
          posterior summaries (posterior).
          The rank order test score (insertion_order_MWW_test) is
          included if the iterator has it.
      """
      assert np.shape(main_iterator.logweights) == (
          len(saved_logl),
          len(main_iterator.all_logZ),
      ), (
          np.shape(main_iterator.logweights),
          np.shape(saved_logl),
          np.shape(main_iterator.all_logZ),
      )
  
      saved_logl = np.array(saved_logl)
      saved_u = pointpile.getu(saved_nodeids)
      saved_v = pointpile.getp(saved_nodeids)
      saved_logwt = np.array(main_iterator.logweights)
      saved_logwt0 = saved_logwt[:, 0]
      saved_logwt_bs = saved_logwt[:, 1:]
      logZ_bs = main_iterator.all_logZ[1:]
      assert len(saved_logwt_bs) == len(saved_nodeids), (
          saved_logwt_bs.shape,
          len(saved_nodeids),
      )
  
      if mpi_comm is not None:
          # spread logZ_bs, saved_logwt_bs
          recv_saved_logwt_bs = mpi_comm.gather(saved_logwt_bs, root=0)
          recv_saved_logwt_bs = mpi_comm.bcast(
              recv_saved_logwt_bs, root=0
          )
          saved_logwt_bs = np.concatenate(recv_saved_logwt_bs, axis=1)
  
          recv_logZ_bs = mpi_comm.gather(logZ_bs, root=0)
          recv_logZ_bs = mpi_comm.bcast(recv_logZ_bs, root=0)
          logZ_bs = np.concatenate(recv_logZ_bs)
  
      saved_wt_bs = exp(
          saved_logwt_bs + saved_logl.reshape((-1, 1)) - logZ_bs
      )
      saved_wt0 = exp(
          saved_logwt0 + saved_logl - main_iterator.all_logZ[0]
      )
  
      # compute fraction in tail
      w = saved_wt0 / saved_wt0.sum()
      assert np.isclose(w.sum() - 1, 0), w.sum()
      ess = len(w) / (1.0 + ((len(w) * w - 1) ** 2).sum() / len(w))
      tail_fraction = w[np.asarray(main_iterator.istail)].sum()
      if tail_fraction != 0:
          logzerr_tail = (
              logaddexp(
                  log(tail_fraction) + main_iterator.logZ,
                  main_iterator.logZ,
              )
              - main_iterator.logZ
          )
      else:
          logzerr_tail = 0
  
      logzerr_bs = (logZ_bs - main_iterator.logZ).max()
      logzerr_total = (logzerr_tail**2 + logzerr_bs**2) ** 0.5
      samples = resample_equal(saved_v, w)
  
      ndim = saved_u.shape[1]
      information_gain_bits = []
      for i in range(ndim):
          H, _ = np.histogram(
              saved_u[:, i],
              weights=saved_wt0,
              density=True,
              bins=np.linspace(0, 1, 40),
          )
          information_gain_bits.append(
              float((np.log2(1 / ((H + 0.001) * 40)) / 40).sum())
          )
  
      j = saved_logl.argmax()
  
      results = dict(
          niter=len(saved_logl),
          logz=main_iterator.logZ,
          logzerr=logzerr_total,
          logz_bs=logZ_bs.mean(),
          logz_single=main_iterator.logZ,
          logzerr_tail=logzerr_tail,
          logzerr_bs=logzerr_bs,
          ess=ess,
          H=main_iterator.all_H[0],
          Herr=main_iterator.all_H.std(),
          posterior=dict(
              mean=samples.mean(axis=0).tolist(),
              stdev=samples.std(axis=0).tolist(),
              median=np.percentile(samples, 50, axis=0).tolist(),
              errlo=np.percentile(samples, 15.8655, axis=0).tolist(),
              errup=np.percentile(samples, 84.1345, axis=0).tolist(),
              information_gain_bits=information_gain_bits,
          ),
          weighted_samples=dict(
              upoints=saved_u,
              points=saved_v,
              weights=saved_wt0,
              logw=saved_logwt0,
              bootstrapped_weights=saved_wt_bs,
              logl=saved_logl,
          ),
          samples=samples,
          maximum_likelihood=dict(
              logl=saved_logl[j],
              point=saved_v[j, :].tolist(),
              point_untransformed=saved_u[j, :].tolist(),
          ),
      )
  
      if getattr(main_iterator, "check_insertion_order", False):
          results["insertion_order_MWW_test"] = dict(
              independent_iterations=main_iterator.insertion_order_runlength,
              converged=main_iterator.insertion_order_converged,
          )
  
      return results
  
imports: import numpy
  from numpy import log, log1p, exp, logaddexp
  import math
  import sys
  from .utils import resample_equal
  from .ordertest import UniformOrderAccumulator
label_desc: Use image node_id 7 for calling a global function with example usage: combine_results(saved_logl, saved_nodeids, pointpile, main_iterator, mpi_comm) and returns: results