-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add a function that constructs samplers #45
Add a function that constructs samplers #45
Conversation
4b90969
to
ea2456b
Compare
ea2456b
to
b2a0a16
Compare
0ea5140
to
c8fe1cb
Compare
Codecov Report
@@ Coverage Diff @@
## main #45 +/- ##
==========================================
- Coverage 99.74% 97.20% -2.55%
==========================================
Files 7 9 +2
Lines 391 572 +181
Branches 31 62 +31
==========================================
+ Hits 390 556 +166
- Misses 0 5 +5
- Partials 1 11 +10
Continue to review full report at Codecov.
|
7b1a633
to
f335ab3
Compare
d57903a
to
f25d53e
Compare
We now have a complete working example in the test |
9c12ab6
to
f2a41f0
Compare
f2a41f0
to
32fd2b1
Compare
I've finished refactoring the sampler steps and filled out the docstings, so this should be ready to merge when/if it passes. |
65c7a37
to
58882f0
Compare
58882f0
to
39ac1a5
Compare
This PR provides an initial implementation of #3—and the related interface function mentioned in #26. It provides a general sampler-constructor,
aemcmc.basic.construct_sampler
, that returns adict
mappingRandomVariable
s to their sample steps.The current approach uses a
Feature
calledSamplerTracker
to track adict
fromRandomVariable
s to all their discovered sample steps—even when there's more than one potential sampler for the sameRandomVariable
. Sample steps are discovered by walking the graph with standard local rewriters that write their results to thedict
inSamplerTracker
. This allows us to maintain the original observation variable graphs in relation to every other un-observed variable (i.e. so we can see when a variable is in a particular hierarchical relationship with another variable, etc.)In order to get around some
DimShuffle
annoyances during unification/pattern-matching, aSubsumingElemwise
Op
was added and is used to replaceElemwise(DimShuffle(x), ...)
graphs withSubsumingElemwise(x, ...)
graphs (i.e. ones that subsume theDimShuffle
s). SinceSubsumingElemwise
inherits fromOpFromGraph
, those nodes can be expanded later on to reproduce the originalElemwise
+DimShuffle
sub-graphs.This loop needs to iterate over all the unobserved
RandomVariable
s and construct samplers for them. While doing so, it needs to use references to the previously constructed samplers' outputs.RandomVariable
rewritingThe issue here is that
RandomVariable
s that are canonicalized are no longer the sameRandomVariable
s that the user created, so we need a means of keeping a map between the two. LiftingOp
s throughRandomVariable
s is one of the main ways this issue shows up. N.B.: This is also one situation in which we could use complete relations (i.e. two-way rewrites).DimShuffle
sSubsumingElemwise
will subsume (i.e. limit to only ones that add the appropriate broadcast dimensions).In cases where the original graph was a
Elemwise(DimShuffle1(DimShuffle2(x)), ...)
and the twoDimShuffle*
are merged, we will need to un-merge/expand them in order to useSubsumingElemwise
.RandomVariable
s).aemcmc.gibbs
(e.g. remove combination samplers in favor ofconstruct_sampler
, create morelocal_optimizer
s, generalizelocal_optimizer
construction, etc.)