docstr: Test algorithm against posterior (R) convergence functions.
  
  posterior: https://github.com/stan-dev/posterior
  R code:
  ```
  library("posterior")
  data2 <- read.csv("blocker.2.csv", comment.char = "#")
  data1 <- read.csv("blocker.1.csv", comment.char = "#")
  output <- matrix(ncol=17, nrow=length(names(data1))-4)
  j = 0
  for (i in 1:length(names(data1))) {
      name = names(data1)[i]
      ary = matrix(c(data1[,name], data2[,name]), 1000, 2)
      if (!endsWith(name, "__"))
          j <- j + 1
          output[j,] <- c(
              posterior::rhat(ary),
              posterior::rhat_basic(ary, FALSE),
              posterior::ess_bulk(ary),
              posterior::ess_tail(ary),
              posterior::ess_mean(ary),
              posterior::ess_sd(ary),
              posterior::ess_median(ary),
              posterior::ess_basic(ary, FALSE),
              posterior::ess_quantile(ary, 0.01),
              posterior::ess_quantile(ary, 0.1),
              posterior::ess_quantile(ary, 0.3),
              posterior::mcse_mean(ary),
              posterior::mcse_sd(ary),
              posterior::mcse_median(ary),
              posterior::mcse_quantile(ary, prob=0.01),
              posterior::mcse_quantile(ary, prob=0.1),
              posterior::mcse_quantile(ary, prob=0.3))
  }
  df = data.frame(output, row.names = names(data1)[5:ncol(data1)])
  colnames(df) <- c("rhat_rank",
                    "rhat_raw",
                    "ess_bulk",
                    "ess_tail",
                    "ess_mean",
                    "ess_sd",
                    "ess_median",
                    "ess_raw",
                    "ess_quantile01",
                    "ess_quantile10",
                    "ess_quantile30",
                    "mcse_mean",
                    "mcse_sd",
                    "mcse_median",
                    "mcse_quantile01",
                    "mcse_quantile10",
                    "mcse_quantile30")
  write.csv(df, "reference_posterior.csv")
  ```
  Reference file:
  
  Created: 2020-08-31
  System: Ubuntu 18.04.5 LTS
  R version 4.0.2 (2020-06-22)
  posterior 0.1.2
code: def test_deterministic(self):
      """
      Test algorithm against posterior (R) convergence functions.
  
      posterior: https://github.com/stan-dev/posterior
      R code:
      ```
      library("posterior")
      data2 <- read.csv("blocker.2.csv", comment.char = "#")
      data1 <- read.csv("blocker.1.csv", comment.char = "#")
      output <- matrix(ncol=17, nrow=length(names(data1))-4)
      j = 0
      for (i in 1:length(names(data1))) {
          name = names(data1)[i]
          ary = matrix(c(data1[,name], data2[,name]), 1000, 2)
          if (!endsWith(name, "__"))
              j <- j + 1
              output[j,] <- c(
                  posterior::rhat(ary),
                  posterior::rhat_basic(ary, FALSE),
                  posterior::ess_bulk(ary),
                  posterior::ess_tail(ary),
                  posterior::ess_mean(ary),
                  posterior::ess_sd(ary),
                  posterior::ess_median(ary),
                  posterior::ess_basic(ary, FALSE),
                  posterior::ess_quantile(ary, 0.01),
                  posterior::ess_quantile(ary, 0.1),
                  posterior::ess_quantile(ary, 0.3),
                  posterior::mcse_mean(ary),
                  posterior::mcse_sd(ary),
                  posterior::mcse_median(ary),
                  posterior::mcse_quantile(ary, prob=0.01),
                  posterior::mcse_quantile(ary, prob=0.1),
                  posterior::mcse_quantile(ary, prob=0.3))
      }
      df = data.frame(output, row.names = names(data1)[5:ncol(data1)])
      colnames(df) <- c("rhat_rank",
                        "rhat_raw",
                        "ess_bulk",
                        "ess_tail",
                        "ess_mean",
                        "ess_sd",
                        "ess_median",
                        "ess_raw",
                        "ess_quantile01",
                        "ess_quantile10",
                        "ess_quantile30",
                        "mcse_mean",
                        "mcse_sd",
                        "mcse_median",
                        "mcse_quantile01",
                        "mcse_quantile10",
                        "mcse_quantile30")
      write.csv(df, "reference_posterior.csv")
      ```
      Reference file:
  
      Created: 2020-08-31
      System: Ubuntu 18.04.5 LTS
      R version 4.0.2 (2020-06-22)
      posterior 0.1.2
      """
      # download input files
      here = os.path.dirname(os.path.abspath(__file__))
      data_directory = os.path.join(here, "..", "saved_models")
      path = os.path.join(
          data_directory, "stan_diagnostics", "blocker.[0-9].csv"
      )
      posterior = from_cmdstan(path)
      reference_path = os.path.join(
          data_directory, "stan_diagnostics", "reference_posterior.csv"
      )
      reference = (
          pd.read_csv(
              reference_path, index_col=0, float_precision="high"
          )
          .sort_index(axis=1)
          .sort_index(axis=0)
      )
      # test arviz functions
      funcs = {
          "rhat_rank": lambda x: rhat(x, method="rank"),
          "rhat_raw": lambda x: rhat(x, method="identity"),
          "ess_bulk": lambda x: ess(x, method="bulk"),
          "ess_tail": lambda x: ess(x, method="tail"),
          "ess_mean": lambda x: ess(x, method="mean"),
          "ess_sd": lambda x: ess(x, method="sd"),
          "ess_median": lambda x: ess(x, method="median"),
          "ess_raw": lambda x: ess(x, method="identity"),
          "ess_quantile01": lambda x: ess(
              x, method="quantile", prob=0.01
          ),
          "ess_quantile10": lambda x: ess(
              x, method="quantile", prob=0.1
          ),
          "ess_quantile30": lambda x: ess(
              x, method="quantile", prob=0.3
          ),
          "mcse_mean": lambda x: mcse(x, method="mean"),
          "mcse_sd": lambda x: mcse(x, method="sd"),
          "mcse_median": lambda x: mcse(x, method="median"),
          "mcse_quantile01": lambda x: mcse(
              x, method="quantile", prob=0.01
          ),
          "mcse_quantile10": lambda x: mcse(
              x, method="quantile", prob=0.1
          ),
          "mcse_quantile30": lambda x: mcse(
              x, method="quantile", prob=0.3
          ),
      }
      results = {}
      for key, coord_dict, _, vals in xarray_var_iter(
          posterior.posterior, combined=True
      ):
          if coord_dict:
              key = f"{key}.{list(coord_dict.values())[0] + 1}"
          results[key] = {
              func_name: func(vals) for func_name, func in funcs.items()
          }
      arviz_data = (
          pd.DataFrame.from_dict(results)
          .T.sort_index(axis=1)
          .sort_index(axis=0)
      )
  
      # check column names
      assert set(arviz_data.columns) == set(reference.columns)
  
      # check parameter names
      assert set(arviz_data.index) == set(reference.index)
  
      # show print with pytests '-s' tag
      np.set_printoptions(16)
      print(abs(reference - arviz_data).max())
  
      # test absolute accuracy
      assert (abs(reference - arviz_data).values < 1e-8).all(None)
  
imports: import os
  import numpy
  import packaging
  import pandas
  import pytest
  import scipy
  from numpy.testing import assert_almost_equal
  from ...data import from_cmdstan, load_arviz_data
  from ...rcparams import rcParams
  from ...sel_utils import xarray_var_iter
  from ...stats import bfmi, ess, mcse, rhat
  from ...stats.diagnostics import _ess, _ess_quantile, _mc_error, _mcse_quantile, _multichain_statistics, _rhat, _rhat_rank, _split_chains, _z_scale, ks_summary
label_desc: Use image node_id 5 for calling the TestDiagnostics obj's underlying member method code with example usage: obj.test_deterministic() without return types