code: def test_contbox_hotstart():
      rng_samples = np.random.RandomState(43)
      N = 100000
      samples = rng_samples.normal(0.1, 1e-6, size=(N, 2))
      samples[:, 1] = rng_samples.uniform(size=N)
      weights = (np.ones(N) / N).reshape((-1, 1))
      logl = weights * 0
  
      steps = [0.1, 0.01]
      ulos, uhis = compute_quantile_intervals(steps, samples, weights)
      print("quantiles:", ulos)
      print("quantiles:", uhis)
      ulos2, uhis2, uinterpspace = compute_quantile_intervals_refined(
          steps, samples, weights
      )
      print("refined quantiles:", ulos2)
      print("refined quantiles:", uhis2)
      print("interpolation steps:", uinterpspace)
      assert np.diff(ulos, axis=0).shape == (2, 2), ulos
      assert (np.diff(uinterpspace) > 0).all(), uinterpspace
      assert (np.diff(ulos, axis=0) < 0).all(), (ulos, uhis)
      assert (np.diff(uhis, axis=0) > 0).all(), (ulos, uhis)
      assert (np.diff(ulos2, axis=0) < 0).all(), (ulos2, uhis2)
      assert (np.diff(uhis2, axis=0) > 0).all(), (ulos2, uhis2)
      assert ulos.shape == (2 + 1, len(steps)), (uhis.shape, ulos.shape)
      assert uhis.shape == ulos.shape, (uhis.shape, ulos.shape)
      assert len(uinterpspace) == len(uhis2)
      assert len(uinterpspace) == len(uhis2)
      tol = dict(atol=1e-3, rtol=0.01)
      for i in 1, 0:
          for j, q in enumerate(steps):
              expectation = np.quantile(samples[:, i], q)
              actual = ulos[j, i]
              print(i, j, q, expectation, actual)
              assert np.isclose(expectation, actual, **tol), (
                  i,
                  j,
                  q,
                  expectation,
                  actual,
              )
              expectation = np.quantile(samples[:, i], 1 - q)
              actual = uhis[j, i]
              print(i, j, 1 - q, expectation, actual)
              assert np.isclose(expectation, actual, **tol), (
                  i,
                  j,
                  1 - q,
                  expectation,
                  actual,
              )
  
      (
          aux_param_names,
          aux_loglike,
          aux_transform,
          vectorized,
      ) = get_auxiliary_contbox_parameterization(
          parameters,
          loglike=log_likelihood,
          transform=prior_transform,
          vectorized=False,
          upoints=samples,
          uweights=weights,
      )
      assert aux_param_names == parameters + ["aux_logweight"], (
          aux_param_names,
          parameters,
      )
      p = aux_transform(np.random.uniform(size=3))
      assert p.shape == (len(aux_param_names),)
      L = float(aux_loglike(p))
      print(L)
      del aux_param_names, aux_loglike, aux_transform
  
      (
          aux_param_names,
          aux_vloglike,
          aux_vtransform,
          vectorized,
      ) = get_auxiliary_contbox_parameterization(
          parameters,
          loglike=vectorize(log_likelihood),
          transform=vectorize(prior_transform),
          vectorized=True,
          upoints=samples,
          uweights=weights,
      )
      print(aux_param_names, parameters)
      assert aux_param_names == parameters + ["aux_logweight"], (
          aux_param_names,
          parameters,
      )
      p = aux_vtransform(np.random.uniform(size=(11, 3)))
      assert p.shape == (11, len(aux_param_names)), p.shape
      L = aux_vloglike(p)
      assert L.shape == (11,), L.shape
      print(L)
      del aux_param_names, aux_vloglike, aux_vtransform
  
      with tempfile.TemporaryDirectory() as tmpdirname:
          tmpfilename = os.path.join(
              tmpdirname, "weighted_posterior_samples.txt"
          )
          print(tmpfilename)
          np.savetxt(
              tmpfilename,
              np.hstack((weights, logl, samples)),
              header="weight logl mean scatter",
              fmt="%f",
          )
          (
              aux_param_names,
              aux_loglike,
              aux_transform,
              vectorized,
          ) = warmstart_from_similar_file(
              tmpfilename,
              parameters,
              extended_log_likelihood,
              extended_prior_transform,
              vectorized=False,
          )
          assert aux_param_names == parameters + ["aux_logweight"], (
              aux_param_names,
              parameters,
          )
          p = aux_transform(np.random.uniform(size=3))
          assert p.shape == (len(aux_param_names) + 1,)
          L = float(aux_loglike(p))
          print(L)
          (
              aux_param_names,
              aux_vloglike,
              aux_vtransform,
              vectorized,
          ) = warmstart_from_similar_file(
              tmpfilename,
              parameters,
              vectorize(extended_log_likelihood),
              vectorize(extended_prior_transform),
              vectorized=True,
          )
          assert aux_param_names == parameters + ["aux_logweight"], (
              aux_param_names,
              parameters,
          )
          p = aux_vtransform(np.random.uniform(size=(11, 3)))
          assert p.shape == (11, len(aux_param_names) + 1)
          L = aux_vloglike(p)
          assert L.shape == (11,)
          print(L)
  
file_path: ultranest/tests/test_hotstart.py
imports: from __future__ import print_function, division
  import numpy
  import scipy.stats
  from numpy import log10
  from ultranest import ReactiveNestedSampler
  from ultranest.utils import vectorize
  from ultranest.integrator import warmstart_from_similar_file
  from ultranest.hotstart import reuse_samples, get_extended_auxiliary_problem
  from ultranest.hotstart import compute_quantile_intervals, get_auxiliary_contbox_parameterization, compute_quantile_intervals_refined
  import os
  import tempfile
label_desc: Use image node_id 5 for calling a global function with example usage: test_contbox_hotstart() without return types