Skip to content

Conversation

marcoct
Copy link
Collaborator

@marcoct marcoct commented Jul 20, 2020

This PR makes several changes related to Gen's support for involution MCMC and SMC:

  • What was previously called the "involution DSL" has now been generalized to become a "Trace Transform DSL", for transforming between arbitrary spaces of traces or pairs of traces. Whereas the involution DSL was previously restricted to the setting when the previous model and the new model were the same generative function, this DSL also can be used to define transformations when the previous model and the new model are different generative functions.

  • There are many syntax improvements to the Trace Transform DSL, which is now documented here.

  • The Trace Transform DSL can now read and write to multivariate (vector-valued) continuous random choices, and compute Jacobians appropriately.

  • There is a new abstraction called "Trace Translators", that unifies patterns of computation that occur within involutive MCMC with patterns of computation occuring within SMC algorithms. This PR includes documentation for several types of Trace Translators, including General Trace Translators (the most general type, which can be used in constructing SMC samplers that use arbitrary sequences of models), Symmetric Trace Translators (used in involutive MCMC), Deterministic Trace Translators (primarily for pedagogical purposes), and Simple Extending Trace Translators (corresponding to a variant of SMC where the model is extended with new random choices at each step, that are sampled from a proposal distribution).

Some of these item were part of this issue: #230

@marcoct marcoct requested a review from alex-lew July 20, 2020 23:29
@marcoct marcoct changed the title 20200416 marcoct translatordsl Trace Translators and new Trace Transform DSL Jul 20, 2020
@marcoct marcoct requested a review from ztangent July 22, 2020 18:03
@georgematheos
Copy link
Contributor

One thing I just ran into while using this DSL was that I was getting a cryptic error about how the "Jacobian is 0x1 and is not square". I eventually realized this is because I was looking up a continuous return value of a subtrace in my model in the involution I had written. It was something along the lines of:

# `:vals => i` points to a subtrace which samples `:val ~ ...` then returns this value
@read(model_tr[:vals => 1], :cont)

Would it be easy to throw a custom error if a user tries to read a continuous value from a subtrace return like this, so it's clear to the user how to fix this?

Copy link
Member

@ztangent ztangent left a comment

Choose a reason for hiding this comment

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

Love this new abstraction, as well as the new syntax! I can totally see how this helps provide a unifying formalism for various operations used in both SMC and MCMC, like we discussed previously.

One limitation of the Trace Transform DSL though, as compared to the Involution DSL, is it that it seems like TraceTransformDSLPrograms no longer have access to the model and proposal arguments, whereas InvolutionDSLPrograms did? If I'm right about that, then it seems harder to write trace transforms parameterized by various model arguments, which might be useful sometimes (e.g. in the example I gave for the use of ExtendingTraceTranslators in SMC), because the trace address you want to read / write from could depend on model arguments, and not just previously sampled values. Would be curious to hear more of your thoughts about this @marcoct!

@marcoct
Copy link
Collaborator Author

marcoct commented Jul 27, 2020

One limitation of the Trace Transform DSL though, as compared to the Involution DSL, is it that it seems like TraceTransformDSLPrograms no longer have access to the model and proposal arguments, whereas InvolutionDSLPrograms did? If I'm right about that, then it seems harder to write trace transforms parameterized by various model arguments, which might be useful sometimes (e.g. in the example I gave for the use of ExtendingTraceTranslators in SMC), because the trace address you want to read / write from could depend on model arguments, and not just previously sampled values.

@ztangent That is still supported, but with a different syntax that better matches the idea that model_in and aux_in are traces, e.g. get_args(model_in) and get_args(aux_in).

@ztangent
Copy link
Member

That is still supported, but with a different syntax that better matches the idea that model_in and aux_in are traces, e.g. get_args(model_in) and get_args(aux_in).

Nice, that's right! Perhaps all that's needed then is an example within the docs / tutorials of that -- or maybe there already is, and I just missed it.

@georgematheos
Copy link
Contributor

georgematheos commented Aug 14, 2020

As another suggestion for an improvement, I think the documentation for the @copy and @tcall could both be improved. In particular, for @copy, we should make it clear that

  1. It is possible to copy a whole submap of addresses
  2. If we copy a whole submap of addresses, it will overwrite any values currently at those addresses

I'm not 100% sure 2 is true--it is true in my fork where I redid the set_submap! function in my choicemap rewrite, but not sure about the main branch. If 2 is true, we could also consider if this is the behavior we want. I suspect it isn't. Eg. It is sometimes nice to have an involution looking like

@transform .....
  @write(new_tr[:top => :value => 1], some_value, :disc)
  # say the proposal proposes some addresses in `:top => :space1` and `:top => :space2`, but not in `:top => :value`
  @copy(proposal_tr[:top], new_tr[:top])
end

Ie. we may want to write to some addresses in namespace :top, then copy in all the proposed addresses in namespaces :top without overwriting the values we wrote explicitly.

To prevent this type of overwriting should be pretty easy, we just need to change a call to set_submap! to merge!.

@marcoct marcoct marked this pull request as draft September 14, 2020 04:18
@marcoct marcoct marked this pull request as ready for review September 21, 2020 21:06
@marcoct marcoct merged commit d948cf3 into master Sep 21, 2020
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