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

A chain to vector of NamedTuples utility? #456

Closed
SamuelBrand1 opened this issue May 22, 2024 · 8 comments
Closed

A chain to vector of NamedTuples utility? #456

SamuelBrand1 opened this issue May 22, 2024 · 8 comments

Comments

@SamuelBrand1
Copy link

Hi everyone!

Functions like condition and generated_quantities take NamedTuples as arguments (and Dicts). Sometimes this is really convenient, for example, in counter-factual modelling. Or in extending samples one model into a related model, e.g. for Bayesian forecasting.

However, I can't find a utility that maps between a chain object and an iterable object of NamedTuples. If it doesn't exist I think this would be a useful addition!

@SamuelBrand1
Copy link
Author

SamuelBrand1 commented May 22, 2024

PS in comparison to get_params, which is col wise with respect to the chain object, this would be row-wise. It would also recollection vars into vectors if possible e.g. x[1], x[2] etc would be repacked into (x = some_vector,...)

@cpfiffer
Copy link
Member

cpfiffer commented May 22, 2024 via email

@SamuelBrand1
Copy link
Author

I added my pass CDCgov/Rt-without-renewal#235 to my project before I saw this.

@cpfiffer
Copy link
Member

Cool, love it. Good to close?

@SamuelBrand1
Copy link
Author

Would you want me to PR this utility to MCMCChains?

@cpfiffer
Copy link
Member

It depends on whether it's materially different from using the Tables.jl interface. If it is, then great, but if it provides roughly the same effect I'm not sure this is the home for it. Could you check the existing tables interface to see if it makes sense?

@SamuelBrand1
Copy link
Author

using Tables
rowtable(chain)

Does indeed give an iterable with NamedTuples for samples. Very nice. Definitely using this pattern in the future.

@cpfiffer
Copy link
Member

Thanks so much! Appreciate your time.

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

No branches or pull requests

2 participants