# What does the "maximum tree depth" warning mean?

**URL:** <https://discourse.pymc.io/t/what-does-the-maximum-tree-depth-warning-mean/4173>\
**Category:** Questions\
**Created:** [December 3, 2019, 10:44pm UTC](https://discourse.pymc.io/t/what-does-the-maximum-tree-depth-warning-mean/4173 "2019-12-03T22:44:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexAndorra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/alexandorra/32/9142_2.png) [@AlexAndorra](https://discourse.pymc.io/u/AlexAndorra)\
**Post date:** [December 3, 2019, 10:44pm UTC](https://discourse.pymc.io/t/what-does-the-maximum-tree-depth-warning-mean/4173/1 "2019-12-03T22:44:40Z")

</div>

Hi dear community!  
I’m wondering about the warning about maximum tree depth: `The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.`

- I know what increasing `target_accept` and reparametrizing do, but I never encountered max tree depth – _what does it hint at, and how do you handle it usually_?

- In particular, if you have no divergences and no r\_hat warnings, but just effective sample size warnings, what does it say about your trace’s quality?

I can share the model I’m working on, but I’m more interested in general heuristics here – and I still need to test some things on my model to be officially stuck 😜  
Thanks a bunch in advance for your helpful comments 🖖

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [December 4, 2019, 6:02am UTC](https://discourse.pymc.io/t/what-does-the-maximum-tree-depth-warning-mean/4173/2 "2019-12-04T06:02:50Z")

</div>

NUTS using a binary tree doubling guide how many leapfrogs it should do. It is a recursive algorithm only stop when it hits a U-turn in the trajectory (and also when there is divergence). Of course, in practice we wont run the recursive forever, so there is a upper limit of how many trees we double (default to 10 usually). When you reach the maximum tree depth and still have not got a U-turn, you will get a warning.  
It does not effect the correctness of the sampler, but since it effectively stop early your sampler is not as efficient. Usually, this is an indication that NUTS is taking too small steps. You can also try increase the tuning so that the mass matrix is adapted a bit better.

---

<div class="post-metadata">

**Author:** ![AlexAndorra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/alexandorra/32/9142_2.png) [@AlexAndorra](https://discourse.pymc.io/u/AlexAndorra)\
**Post date:** [December 4, 2019, 11:36am UTC](https://discourse.pymc.io/t/what-does-the-maximum-tree-depth-warning-mean/4173/3 "2019-12-04T11:36:08Z")

</div>

Ow ok, thanks Junpeng, that’s very clear!  
From what you said here:

> [@junpenglao](#):
>
> Usually, this is an indication that NUTS is taking too small steps

Can I conclude that one way to _not_ reach max tree depth would actually be to _reduce_ `target_accept`, since NUTS would then take bigger steps?

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [December 4, 2019, 1:35pm UTC](https://discourse.pymc.io/t/what-does-the-maximum-tree-depth-warning-mean/4173/4 "2019-12-04T13:35:11Z")

</div>

Yes and no, in theory that should be the case, but in practice the reason you are getting small step size initially is because your posterior density space has region of high curvature which you do need small step size to sample those.

---

<div class="post-metadata">

**Author:** ![AlexAndorra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/alexandorra/32/9142_2.png) [@AlexAndorra](https://discourse.pymc.io/u/AlexAndorra)\
**Post date:** [December 4, 2019, 2:37pm UTC](https://discourse.pymc.io/t/what-does-the-maximum-tree-depth-warning-mean/4173/5 "2019-12-04T14:37:20Z")

</div>

Mmmh ok 🤔  
And I know sometimes switching to a non-centered parametrization actually hurts sampling (e.g it seems to be the case in my model). So if I followed you correctly, that means that the non-centered parametrization has an even higher curvature than the centered one – in these cases, your only choice is to increase `target_accept` and just sample from the centered model for a (very) long time?

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [December 4, 2019, 3:32pm UTC](https://discourse.pymc.io/t/what-does-the-maximum-tree-depth-warning-mean/4173/6 "2019-12-04T15:32:01Z")

</div>

> [@AlexAndorra](#):
>
> So if I followed you correctly, that means that the non-centered parametrization has an even higher curvature than the centered one

I would say most likely, but in reality there are more nuance to that. You could have a centered parameterization that contains pretty nasty geometric, but adaptation just ignore that and estimated the covariance around the mode. The result is that although you have a nicer geometry using a non-centered parameterized posterior (overall smoother and less curvature), it contains higher curvature around the mode and thus result in small step size after adaptation.

In general, so many things could happen it is hard to say what is the situation of your model. You could deep dive using e.g. the pair plot of the posterior sample for more insight.

---

<div class="post-metadata">

**Author:** ![AlexAndorra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/alexandorra/32/9142_2.png) [@AlexAndorra](https://discourse.pymc.io/u/AlexAndorra)\
**Post date:** [December 4, 2019, 5:29pm UTC](https://discourse.pymc.io/t/what-does-the-maximum-tree-depth-warning-mean/4173/7 "2019-12-04T17:29:58Z")

</div>

Thanks Junpeng, this thread was really helpful! I’ll mark it as solved, as I just wanted a conceptual and high-level understanding of the max tree depth warning, that I and the community could refer to when getting this warning 😉
