question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trying to sample from the LKJCovariancePrior

See original GitHub issue

Trying to declare and LKJ prior and sample from it however it doesn’t like the event_shape of the sd_prior:

import torch
from gpytorch.priors import LKJCovariancePrior, GammaPrior

sd_prior = GammaPrior(torch.tensor([1.0]),torch.tensor([1.0]), validate_args=True)
cov_prior = LKJCovariancePrior(n=10, eta=1, sd_prior=sd_prior)
Traceback (most recent call last):

  File "<ipython-input-40-1ca20a6657f1>", line 5, in <module>
    cov_prior = LKJCovariancePrior(n=10, eta=1, sd_prior=sd_prior)

  File "/home/vr308/anaconda3/lib/python3.8/site-packages/gpytorch/priors/lkj_prior.py", line 111, in __init__
    raise ValueError("sd_prior must have event_shape 1 or n")

ValueError: sd_prior must have event_shape 1 or n

event_shape is not a settable attribute and by default it is empty torch.Size([]) for a prior over scalar - is this a bug?

Thanks.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
wjmaddoxcommented, Jul 22, 2021

I can try to setup a PR soon, finally managed to track down some code for sampling from the LKJ priors:

1reaction
wjmaddoxcommented, Jul 9, 2021

Hi, I was dealing with this the other day, and don’t think it’s actually a bug in gpytorch but rather a bug in torch.distributions.ExponentialFamily (or some strange feature), as there’s no way to set event shape in those distributions.

This works though because you can set _event_shape:

sd_prior = GammaPrior(torch.tensor([1.0]),torch.tensor([1.0]), validate_args=True)
sd_prior._event_shape = torch.Size((1,))
cov_prior = LKJCovariancePrior(n=10, eta=torch.ones(1), sd_prior=sd_prior)
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use LKJ prior? - greta forum
I am trying to include an LKJ prior in a network model with random sender and receiver effects. However, naively applying the decomposition...
Read more >
LKJ Cholesky Covariance Priors for Multivariate Normal Models
To illustrate modelling covariance with the LKJ distribution, we first generate a two-dimensional normally-distributed sample data set. [1]:.
Read more >
Hierarchical model hyperparameter for sampling the ...
Hi all I am trying to set up a hierarchical model. My model needs to sample the site-specific mean and covariance between two...
Read more >
Hierarchical model hyperparameter ... - Pyro Discussion Forum
I am trying to set up a hierarchical model. My model needs to sample the site-specific mean and covariance between two variables at...
Read more >
Hierarchical modeling with the LKJ prior in PyMC
I describe how to use the LKJCholeskyCov and LKJCorr distributions to include correlated priors in Bayesian hierarchical modeling using PyMC.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found