# LKJCholeskyCov maximum dimension

**URL:** <https://discourse.pymc.io/t/lkjcholeskycov-maximum-dimension/3169>\
**Category:** Questions\
**Created:** [April 29, 2019, 2:58pm UTC](https://discourse.pymc.io/t/lkjcholeskycov-maximum-dimension/3169 "2019-04-29T14:58:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pannefr](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@pannefr](https://discourse.pymc.io/u/pannefr)\
**Post date:** [April 29, 2019, 2:58pm UTC](https://discourse.pymc.io/t/lkjcholeskycov-maximum-dimension/3169/1 "2019-04-29T14:58:48Z")

</div>

What is the maximum size of covariance matrix that LKJCholeskyCov can handle ?  
I only see examples with small dimensions (2 or 3). Can it be used efficiently for 10 dim or 30 dim ? larger ?

I am new to this package…

Thanks

---

<div class="post-metadata">

**Author:** ![lucianopaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/lucianopaz/32/2186_2.png) [@lucianopaz](https://discourse.pymc.io/u/lucianopaz)\
**Post date:** [April 29, 2019, 6:20pm UTC](https://discourse.pymc.io/t/lkjcholeskycov-maximum-dimension/3169/2 "2019-04-29T18:20:54Z")

</div>

It stores the lower triangular part of the matrix so its memory usage scales like (n+1)n/2, where n is the number of dimensions. That is o(n^2), which isn’t so much, but can add up to a lot when n~1000. 30 should be fine though.

---

<div class="post-metadata">

**Author:** ![pannefr](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@pannefr](https://discourse.pymc.io/u/pannefr)\
**Post date:** [April 29, 2019, 6:58pm UTC](https://discourse.pymc.io/t/lkjcholeskycov-maximum-dimension/3169/3 "2019-04-29T18:58:32Z")

</div>

What is the highest dimension you modeled ? Was it efficient ? Also, what is the relationship between the sample size and the dimension ?

Obviously, the more data you have, the better it is. How do you know if you have enough data for the dimension of the problem at hand ?

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![lucianopaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/lucianopaz/32/2186_2.png) [@lucianopaz](https://discourse.pymc.io/u/lucianopaz)\
**Post date:** [April 30, 2019, 2:12pm UTC](https://discourse.pymc.io/t/lkjcholeskycov-maximum-dimension/3169/4 "2019-04-30T14:12:55Z")

</div>

These are all great questions.

> [@pannefr](#):
>
> What is the highest dimension you modeled ?

I have not used `LKJCholeskyCov` at work yet. I have used it with some toy examples which did not go beyond 10 dimensions.

> [@pannefr](#):
>
> Was it efficient ?

As I said, I did not use it for work purposes. However, there are some post [talking about speed gains of using the Cholesky decomposition](https://discourse.pymc.io/t/advice-for-speeding-up-large-multivariate-models/180) instead of the regular covariance matrix. I recall @twiecki looked at this in detail in [the past](https://twitter.com/twiecki/status/845732000229142530).

> [@pannefr](#):
>
> Also, what is the relationship between the sample size and the dimension ?

By that, do you mean effective sample size? Regrettably, ESS depends on the rest of the model and whatever you were observing. For multivariate normals, using `LKJCholeskyCov` there should be little penalty in increasing the dimensionality thanks to the HMC steps, because these scale better in high dimensions. There’s [a paper](https://projecteuclid.org/euclid.bj/1383661192) that proves that you need of the order of O(D^{1/4}) samples to get a good converged chain with HMC for well behaved problems.

> [@pannefr](#):
>
> Obviously, the more data you have, the better it is. How do you know if you have enough data for the dimension of the problem at hand ?

I’m not sure about this point. The parameter state space is affected by the amount of data, but mostly by how the data changes the curvature of the model’s parameter space. If your assumed generative process is badly specified, no amount of data will help you converge better. I don’t know of an optimal bound, but I think that the O(D^{1/4}) should roughly hold also for the amount of data inasmuch as the model is well behaved.

---

<div class="post-metadata">

**Author:** ![sammosummo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/sammosummo/32/96_2.png) [@sammosummo](https://discourse.pymc.io/u/sammosummo)\
**Post date:** [April 30, 2019, 3:25pm UTC](https://discourse.pymc.io/t/lkjcholeskycov-maximum-dimension/3169/5 "2019-04-30T15:25:38Z")

</div>

> [@lucianopaz](#):
>
> As I said, I did not use it for work purposes. However, there are some post [talking about speed gains of using the Cholesky decomposition](https://discourse.pymc.io/t/advice-for-speeding-up-large-multivariate-models/180) instead of the regular covariance matrix. I recall @twiecki looked at this in detail in [the past](https://twitter.com/twiecki/status/845732000229142530).

The example you linked to (my old question) is a special case where I was fitting a multivariate normal with a special covariance matrix. To my knowledge, the trick that occurs in that model is possible only when the covariance matrix is the weighted sum of two known covariance matrices which never change. I’m not sure its relevant to your question.
