Beispiel #1
0
 def _load__txt(self, skip=0):
     self.log.debug("Skipping %d rows", skip)
     self._data = load_DataFrame(self.file_name,
                                 skip=skip,
                                 root_file_name=self.root_file_name)
     self.log.info("Loaded %d sample points from '%s'", len(self._data),
                   self.file_name)
Beispiel #2
0
def plot_progress(progress,
                  ax=None,
                  index=None,
                  figure_kwargs=empty_dict,
                  legend_kwargs=empty_dict):
    """
    Plots progress of one or more MCMC runs: evolution of R-1
    (for means and c.l. intervals) and acceptance rate.

    Takes a ``progress`` instance (actually a ``pandas.DataFrame``,
    returned as part of the sampler ``products``),
    a chain ``output`` prefix, or a list of any of those
    for plotting progress of several chains at once.

    You can use ``figure_kwargs`` and ``legend_kwargs`` to pass arguments to
    ``matplotlib.pyplot.figure`` and ``matplotlib.pyplot.legend`` respectively.

    Return a subplots axes array. Display with ``matplotlib.pyplot.show()``.

    """
    if ax is None:
        import matplotlib.pyplot as plt
        # noinspection PyTypeChecker
        fig, ax = plt.subplots(nrows=2, sharex=True, **figure_kwargs)
    if isinstance(progress, DataFrame):
        pass  # go on to plotting
    elif isinstance(progress, str):
        try:
            if not progress.endswith(Extension.progress):
                progress += Extension.progress
            progress = load_DataFrame(progress)
            # 1-based
            progress.index = np.arange(1, len(progress) + 1)
        except:
            raise ValueError("Cannot load progress file %r" % progress)
    elif hasattr(type(progress), "__iter__"):
        # Assume is a list of progress'es
        for i, p in enumerate(progress):
            plot_progress(p, ax=ax, index=i + 1)
        return ax
    else:
        raise ValueError("Cannot understand progress argument: %r" % progress)
    # Plot!
    tag_pre = "" if index is None else "%d : " % index
    p = ax[0].semilogy(progress.N,
                       progress.Rminus1,
                       "o-",
                       label=tag_pre + "means")
    ax[0].semilogy(progress.N,
                   progress.Rminus1_cl,
                   "x:",
                   c=p[0].get_color(),
                   label=tag_pre + "bounds")
    ax[0].set_ylabel(r"$R-1$")
    ax[0].legend(**legend_kwargs)
    ax[1].plot(progress.N, progress.acceptance_rate, "o-")
    ax[1].set_ylabel(r"acc. rate")
    return ax
Beispiel #3
0
 def _load__txt(self, skip=0, thin=1):
     self.log.debug("Skipping %d rows and thinning with factor %d.", skip, thin)
     self._data = load_DataFrame(self.file_name, skip=skip, thin=thin)
     self.log.info("Loaded %d samples from '%s'", len(self._data), self.file_name)