Skip to content
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

Fix max_treedepth warning #2808

Merged
merged 2 commits into from
Jan 24, 2018
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
8 changes: 7 additions & 1 deletion pymc3/backends/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,17 @@ def _run_convergence_checks(self, trace):
warn = SamplerWarning(
WarningType.CONVERGENCE, msg, 'error', None, None, effective_n)
warnings.append(warn)
elif eff_min / n_samples < 0.1:
msg = ("The number of effective samples is smaller than "
"10% for some parameters.")
warn = SamplerWarning(
WarningType.CONVERGENCE, msg, 'warn', None, None, effective_n)
warnings.append(warn)
elif eff_min / n_samples < 0.25:
msg = ("The number of effective samples is smaller than "
"25% for some parameters.")
warn = SamplerWarning(
WarningType.CONVERGENCE, msg, 'warn', None, None, effective_n)
WarningType.CONVERGENCE, msg, 'info', None, None, effective_n)
warnings.append(warn)

self._add_warnings(warnings)
Expand Down
5 changes: 3 additions & 2 deletions pymc3/step_methods/hmc/base_hmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ def warnings(self, strace):
WarningType.DIVERGENCES, msg, 'error', None, None, None)
warnings.append(warning)
elif n_divs > 0:
message = ('Divergences after tuning. Increase `target_accept` or '
'reparameterize.')
message = ('There were %s divergences after tuning. Increase '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for putting this back!

'`target_accept` or reparameterize.'
% n_divs)
warning = SamplerWarning(
WarningType.DIVERGENCES, message, 'error', None, None, None)
warnings.append(warning)
Expand Down
7 changes: 5 additions & 2 deletions pymc3/step_methods/hmc/nuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ def _hamiltonian_step(self, start, p0, step_size):
if divergence_info or turning:
break
else:
self._reached_max_treedepth += 1
if not self.tune:
self._reached_max_treedepth += 1

stats = tree.stats()
accept_stat = stats['mean_tree_accept']
Expand All @@ -185,8 +186,10 @@ def competence(var, has_grad):

def warnings(self, strace):
warnings = super(NUTS, self).warnings(strace)
n_samples = self._samples_after_tune
n_treedepth = self._reached_max_treedepth

if np.mean(self._reached_max_treedepth) > 0.05:
if n_samples > 0 and n_treedepth / float(n_samples) > 0.05:
msg = ('The chain reached the maximum tree depth. Increase '
'max_treedepth, increase target_accept or reparameterize.')
warn = SamplerWarning(WarningType.TREEDEPTH, msg, 'warn',
Expand Down