Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

pymc-devs / pymc3 / 8412

28 Nov 2018 - 15:42 coverage decreased (-0.7%) to 88.7%
8412

Pull #3275

travis-ci

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
Fix link to be relative
Pull Request #3275: Documentation rewrite

17630 of 19876 relevant lines covered (88.7%)

4.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/pymc3/plots/energyplot.py
1
import warnings
10×
2

3
import numpy as np
10×
4
try:
10×
5
    import matplotlib.pyplot as plt
10×
6
except ImportError:  # mpl is optional
!
7
    pass
!
8
from .kdeplot import kdeplot
10×
9

10

11
def energyplot(trace, kind='kde', figsize=None, ax=None, legend=True, shade=0.35, bw=4.5,
10×
12
               frame=True, kwargs_shade=None, **kwargs):
13
    """Plot energy transition distribution and marginal energy distribution in
14
    order to diagnose poor exploration by HMC algorithms.
15

16
    Parameters
17
    ----------
18

19
    trace : result of MCMC run
20
    kind : str
21
        Type of plot to display (kde or histogram)
22
    figsize : figure size tuple
23
        If None, size is (8 x 6)
24
    ax : axes
25
        Matplotlib axes.
26
    legend : bool
27
        Flag for plotting legend (defaults to True)
28
    shade : float
29
        Alpha blending value for the shaded area under the curve, between 0
30
        (no shade) and 1 (opaque). Defaults to 0.35
31
    bw : float
32
        Bandwidth scaling factor for the KDE. Should be larger than 0. The higher this number the
33
        smoother the KDE will be. Defaults to 4.5 which is essentially the same as the Scott's rule
34
        of thumb (the default rule used by SciPy). Only works if `kind='kde'`.
35
    frame : bool
36
        Flag for plotting frame around figure.
37
    kwargs_shade : dicts, optional
38
        Additional keywords passed to `fill_between` (to control the shade)
39
    Returns
40
    -------
41

42
    ax : matplotlib axes
43
    """
44

UNCOV
45
    if ax is None:
3×
UNCOV
46
        _, ax = plt.subplots(figsize=figsize)
3×
47

UNCOV
48
    try:
3×
UNCOV
49
        energy = trace['energy']
3×
UNCOV
50
    except KeyError:
3×
UNCOV
51
        warnings.warn('There is no energy information in the passed trace.')
3×
UNCOV
52
        return ax
3×
53

UNCOV
54
    series = [('Marginal energy distribution', energy - energy.mean()),
3×
55
              ('Energy transition distribution', np.diff(energy))]
56

UNCOV
57
    if figsize is None:
3×
UNCOV
58
        figsize = (8, 6)
3×
59

UNCOV
60
    if kwargs_shade is None:
3×
UNCOV
61
        kwargs_shade = {}
3×
62

UNCOV
63
    if kind == 'kde':
3×
UNCOV
64
        for label, value in series:
3×
UNCOV
65
            kdeplot(value, label=label, shade=shade, bw=bw, ax=ax, kwargs_shade=kwargs_shade,
3×
66
                    **kwargs)
67

UNCOV
68
    elif kind == 'hist':
3×
UNCOV
69
        for label, value in series:
3×
UNCOV
70
            ax.hist(value, alpha=shade, label=label, **kwargs)
3×
71

72
    else:
73
        raise ValueError('Plot type {} not recognized.'.format(kind))
!
74

UNCOV
75
    ax.set_xticks([])
3×
UNCOV
76
    ax.set_yticks([])
3×
77

UNCOV
78
    if not frame:
3×
79
        for spine in ax.spines.values():
!
80
            spine.set_visible(False)
!
81

UNCOV
82
    if legend:
3×
UNCOV
83
        ax.legend()
3×
84

UNCOV
85
    return ax
3×
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2021 Coveralls, Inc