code: def _save_samples(
      self,
      samples,
      loglikes,
      weights=None,
      derived_samples=None,
      min_weight=1e-30,
      outfile="chain",
  ):
      if weights is None:
          weights = np.ones_like(loglikes)
      if len(samples.shape) == 2:
          # Single chain
          with open(
              os.path.join(self.logs["chains"], outfile + ".txt"), "w"
          ) as f:
              if self.param_names is not None:
                  f.write("#weight minusloglike ")
                  f.write(" ".join(self.param_names))
                  f.write("\n")
              for i in range(samples.shape[0]):
                  f.write("%.5E " % max(weights[i], min_weight))
                  f.write("%.5E " % -loglikes[i])
                  f.write(" ".join(["%.5E" % v for v in samples[i, :]]))
                  if derived_samples is not None:
                      f.write(" ")
                      f.write(
                          " ".join(
                              [
                                  "%.5E" % v
                                  for v in derived_samples[i, :]
                              ]
                          )
                      )
                  f.write("\n")
      elif len(samples.shape) == 3:
          # Multiple chains
          for ib in range(samples.shape[0]):
              with open(
                  os.path.join(
                      self.logs["chains"],
                      outfile + "_%s.txt" % (ib + 1),
                  ),
                  "w",
              ) as f:
                  if self.param_names is not None:
                      f.write("#weight minusloglike ")
                      f.write(" ".join(self.param_names))
                      f.write("\n")
                  for i in range(samples.shape[1]):
                      f.write("%.5E " % max(weights[ib, i], min_weight))
                      f.write("%.5E " % -loglikes[ib, i])
                      f.write(
                          " ".join(
                              ["%.5E" % v for v in samples[ib, i, :]]
                          )
                      )
                      if derived_samples is not None:
                          f.write(" ")
                          f.write(
                              " ".join(
                                  [
                                      "%.5E" % v
                                      for v in derived_samples[ib, i, :]
                                  ]
                              )
                          )
                      f.write("\n")
  
imports: from __future__ import print_function
  from __future__ import division
  import os
  import json
  import logging
  import time
  import torch
  import numpy
  from tqdm import tqdm
  import matplotlib.pyplot
  from nnest.trainer import Trainer
  from nnest.utils.evaluation import acceptance_rate, effective_sample_size, mean_jump_distance, gelman_rubin_diagnostic
  from nnest.utils.logger import create_logger, get_or_create_run_dir
label_desc: Use image node_id 6 for calling the Sampler obj's underlying member method code with example usage: obj._save_samples(samples, loglikes, weights, derived_samples, min_weight, outfile) without return types