Skip to content

Conversation

@cpfiffer
Copy link
Member

@cpfiffer cpfiffer commented Sep 28, 2019

This PR includes

  1. Some convenience functions for developers, some of which were discussed in API design for non-Turing samplers #886.
  2. A guide on how to use the interface methods on both Turing and non-Turing methods by implementing MH.
  3. Miscellaneous changes to internals, such as
  • allowing a default Sampler constructor
  • storing VarName instead of a string in Transition structs (for later access)
  • a default observe statement for all samplers which just uses SampleFromPrior()
  • a default assume statement which just returns the current value and it's density

There are some things in here I think we should discuss before merging, because I've made a couple design choices that I hope might enable more people to work with immutable Transition structs instead of relying so heavily on mutable states. The guide is an attempt to showcase partial immutable sampling to mirror the non-Turing implementation, and the functions I added in to Turing's code base might make this a little easier.

New functions

Here are the new tools I've added in for developers. I'd like some feedback on these specifically to see how we feel about them.

  • A new Transition constructor, which has the signature Transition(model::Model, spl::Sampler, θ::T, nt::NamedTuple=NamedTuple()). You can pass in the model and the sampler, it'll run the model, grab the density, and bundle everything up for you into a Transition.
  • parameters! is a function with the signature parameters!(spl::Sampler, t::Transition), which accepts a Transition and updates the VarInfo to contain the parameters in the Transition. It returns a vector of the parameters if you would prefer to work with vectors instead of a NamedTuple.
  • parameters is a function which simply returns a NamedTuple of the vi.
  • variables(spl::Sampler) is a function that returns a vector containing the VarNames of a sampler, so you can retrieve or set information about them in a VarInfo. I would like this to be an iterator or something slightly quicker than what it is now, but I like the idea of giving developers quick access to some iterable of VarName.
  • Distributions.logpdf(model::Model, spl::T, θ::P) accepts a model, a sampler, and a vector, and returns the log density. It's a little clumsy but it should get us closer to models that people can just evaluate.

There's some bugs in here I still have to fix, but this is the core of the PR.

@cpfiffer cpfiffer changed the title [WIP] Early API functions and the interface guide. Early API functions and the interface guide. Oct 6, 2019
@cpfiffer
Copy link
Member Author

cpfiffer commented Oct 6, 2019

Alright, I've fixed the bugs on this one. We're ready for a review.

@cpfiffer
Copy link
Member Author

Looks like the tests are good. Does anyone have any further comments on this?

@yebai
Copy link
Member

yebai commented Nov 22, 2019

Ready to merge from my side after the merge conflict is fixed.

@cpfiffer
Copy link
Member Author

cpfiffer commented Dec 2, 2019

I'm going to close this for now and split the guide into parts. I will add the guide on just the interface methods in another PR, #1007.

@cpfiffer cpfiffer closed this Dec 2, 2019
@cpfiffer cpfiffer deleted the csp/interface-guide branch December 17, 2019 18:03
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.

4 participants