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

Pair values with metadata? #101

Closed
cscherrer opened this issue Sep 14, 2019 · 4 comments
Closed

Pair values with metadata? #101

cscherrer opened this issue Sep 14, 2019 · 4 comments

Comments

@cscherrer
Copy link
Contributor

For Soss.jl I'm moving toward all MCMC results being in the form of iterators. Currently, sample returns a pair (samples, stats), which is a bit awkward to work with.

It seems like this is a general problem: we have a value we're interested in (here a single sample) that has some metadata associated with it. We don't always want to throw away the metadata, but we don't want it to get in the way.

This seems like the exact problem addressed by MacroTools.jl's @forward macro.

For example, there could be a (maybe general-purpose) Meta struct with

struct Meta{T,S}
    value :: T
    meta  :: S
end

with methods for common functions @forwarded to the .value field. A new method for sample could then return an iterator of Metas. This could be really convenient - the metadata is there is you need it, but stays out of the way for computations.

What do you think?

@cpfiffer
Copy link
Member

This is actually a big part of what we did over in Turing recently, but hasn't made it over to AdvancedHMC. The plan is to basically return a struct for each step that contains the values and any additional metadata that is a subtype of AbstractTransition. I think Kai and I were talking about doing this a week ago.

@xukai92
Copy link
Member

xukai92 commented Sep 15, 2019

Definitely agree that an iterator approach is preferred!

We have something like Meta already in AHMC already: https://github.com/TuringLang/AdvancedHMC.jl/blob/master/src/trajectory.jl#L14. This was mainly introduced to work with Turing's new interface.

It's a bit hard to use ATM because the value in our case is a PhasePoint contains both the sample and the corresponding momentum. Now sure if we want to export an iterator of PhasePoint to the user or not? Or we make a new one which is similar to Meta to export to the user?

@xukai92
Copy link
Member

xukai92 commented Jul 20, 2020

The plan to solve this issue is by wrapping over AbstractMCMC,
which would provide us an iterator and a transducer.

@yebai
Copy link
Member

yebai commented Dec 16, 2021

We now support the AbstractMCMC interface. #259

@yebai yebai closed this as completed Dec 16, 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

No branches or pull requests

4 participants