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

Conditional autoregression distribution #4504

Merged
merged 12 commits into from
Mar 9, 2021

Conversation

ckrapu
Copy link
Contributor

@ckrapu ckrapu commented Mar 5, 2021

After many months of dragging my feet, I finally spent some time cleaning up the CAR implementation that @junpenglao showed in an example notebook (Issue #3689). I have modified that code to allow for multiple observations of a CAR-distributed vector conditional on a single fixed value for the adjacency matrix W.

This is definitely a work in progress and I am humbly asking for some assistance in devising a testing strategy for this distribution. Right now, all I can think of is to do pointwise tests on the logp for fixed values of the inputs.

@ckrapu ckrapu changed the title Car distribution Conditional autoregression distribution Mar 5, 2021
@twiecki
Copy link
Member

twiecki commented Mar 5, 2021

This looks like a great start!

@twiecki
Copy link
Member

twiecki commented Mar 5, 2021

Regarding tests, yeah, pointwise is probably good enough here if we don't have a reference implementation.

@ckrapu
Copy link
Contributor Author

ckrapu commented Mar 7, 2021

The test that I wrote for this distribution doesn't fit neatly into the framework already set up for testing against Scipy because while the CAR logp is defined to be that of a multivariate normal with a specific covariance structure, the implementation here isn't exactly equal - it differs from the MVN logp by an additive constant.

pymc3/distributions/multivariate.py Outdated Show resolved Hide resolved
pymc3/distributions/multivariate.py Show resolved Hide resolved
@ckrapu
Copy link
Contributor Author

ckrapu commented Mar 7, 2021

I think all of the suggested changes have been addressed. Is the preferred workflow to individually mark each conversation as 'resolved' once the changes have been made, or should that be done by the reviewer?

@twiecki
Copy link
Member

twiecki commented Mar 7, 2021

Best to let @ricardoV94 resolve them.

Added reference for CAR distribution

Running precommit checks

Adding CAR test and updating CAR logp

Extending CAR test to try multiple shapes

Docstring change for CAR logp

Adding bounds to logp for CAR distribution
Copy link
Member

@ricardoV94 ricardoV94 left a comment

Choose a reason for hiding this comment

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

I think it's looking great.

I left another comment. I'll resolve the old ones now.

pymc3/distributions/multivariate.py Show resolved Hide resolved
Copy link
Member

@ricardoV94 ricardoV94 left a comment

Choose a reason for hiding this comment

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

LGTM

)

def random(self, point=None, size=None):
raise NotImplementedError("Sampling from a CAR distribution is not supported.")
Copy link
Member

Choose a reason for hiding this comment

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

Should we turn this into a feature request?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I've got a few leads on efficient methods for doing this. We can track that discussion at #4518.

@ricardoV94 ricardoV94 merged commit 53b642e into pymc-devs:master Mar 9, 2021
@ckrapu ckrapu deleted the car-distribution branch March 9, 2021 15:32
@ckrapu
Copy link
Contributor Author

ckrapu commented Mar 10, 2021

Thanks for the reviews, @ricardoV94 and @twiecki!

ricardoV94 pushed a commit to ricardoV94/pymc that referenced this pull request Mar 10, 2021
* Add conditional autoregression distribution (CAR)
@ckrapu ckrapu restored the car-distribution branch March 23, 2021 16:11
aerubanov pushed a commit to aerubanov/pymc3 that referenced this pull request Mar 26, 2021
* Add conditional autoregression distribution (CAR)
@aerubanov aerubanov mentioned this pull request Apr 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants