Skip to content

Plot posterior reliable mode calculation for continuous variables and ignore kde_plot=True for discretes ones #2294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pymc3/plots/artists.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ def display_point_estimate():
if point_estimate == 'mean':
point_value = trace_values.mean()
elif point_estimate == 'mode':
point_value = mode(trace_values.round(round_to))[0][0]
if isinstance(trace_values[0], float):
density, l, u = fast_kde(trace_values)
x = np.linspace(l, u, len(density))
point_value = x[np.argmax(density)]
else:
point_value = mode(trace_values.round(round_to))[0][0]
elif point_estimate == 'median':
point_value = np.median(trace_values)
point_text = '{point_estimate}={point_value:.{round_to}f}'.format(point_estimate=point_estimate,
Expand Down Expand Up @@ -121,7 +126,7 @@ def set_key_if_doesnt_exist(d, key, value):
if key not in d:
d[key] = value

if kde_plot:
if kde_plot and isinstance(trace_values[0], float):
kdeplot(trace_values, alpha=kwargs.pop('alpha', 0.35), ax=ax, **kwargs)

else:
Expand Down
3 changes: 2 additions & 1 deletion pymc3/plots/posteriorplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def plot_posterior(trace, varnames=None, transform=identity_transform, figsize=N
ref_val: bool
display the percentage below and above ref_val
kde_plot: bool
if True plot a KDE instead of a histogram
if True plot a KDE instead of a histogram. For discrete variables this
argument is ignored.
plot_transformed : bool
Flag for plotting automatically transformed variables in addition to
original variables (defaults to False).
Expand Down