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

ESS produces the wrong result certain models #1633

Merged
merged 16 commits into from
Jun 10, 2021
Merged

ESS produces the wrong result certain models #1633

merged 16 commits into from
Jun 10, 2021

Conversation

torfjelde
Copy link
Member

@torfjelde torfjelde commented Jun 8, 2021

Ref: #1633

@torfjelde
Copy link
Member Author

torfjelde commented Jun 8, 2021

Tests are failing because of the issue fixed in TuringLang/Bijectors.jl#184

@torfjelde torfjelde requested a review from devmotion June 8, 2021 12:20
Comment on lines +115 to +117
for vn in Iterators.flatten(values(vns))
set_flag!(varinfo, vn, "del")
end
Copy link
Member

Choose a reason for hiding this comment

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

We should add a context that does this 😛 At least it would be more convenient than dealing with DynamicPPL internals here. I remember that I was very confused and uncertain if I did it correctly when I implemented this. It seemed to work 😬

Copy link
Member Author

Choose a reason for hiding this comment

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

It works sometimes because in assume we only check if the flag is set for vns[1], but that is only for "sub-symbols". This is the line I'm referring to: https://github.com/TuringLang/DynamicPPL.jl/blob/9083299db3f623136895cae80ef5f10d7fcf8d2c/src/context_implementations.jl#L268. But this won't work if we have more than one key in vi.metadata or if tilde_assume and others are called with a varname subsumed e.g. m[2].

And this won't be an issue once we have a clear separation between sampling and evaluation. These sorts of bugs show up soooo often (and I agree, it's super-confusing), so looking forward to not having those:)

Comment on lines +160 to +161
function DynamicPPL.dot_tilde(ctx::DefaultContext, sampler::Sampler{<:ESS}, right, left, vi)
return DynamicPPL.dot_tilde(ctx, SampleFromPrior(), right, left, vi)
Copy link
Member

Choose a reason for hiding this comment

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

Was this a bug or is needed because of recent changes in DynamicPPL?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was a bug. This is never actually hit and given the arguments I'm assuming it was intended to be a dot_tilde_observe rather than a dot_tilde_assume (which is the case when rng is passed, but because the signature doesn't match the rest of the dot_tilde_assume, it was never hit). The result was that ESS didn't work for dotted observations.

@@ -34,14 +34,15 @@ function Bijectors.bijector(
end

bs = Bijectors.bijector.(tuple(dists...))
rs = tuple(ranges...)
Copy link
Member

Choose a reason for hiding this comment

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

I guess this is not related to ESS?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct; this is just to ensure that we have the same behavior as we had before the most recent release of Bijectors.jl. I just noticed it when trying to figure out why the tests weren't passing.

test/test_utils/models.jl Outdated Show resolved Hide resolved
test/test_utils/models.jl Outdated Show resolved Hide resolved
Comment on lines 70 to 72
# Log this so that if something goes wrong, we can identify the
# algorithm and model.
@info "Testing $(alg) on $(m.name)"
Copy link
Member

Choose a reason for hiding this comment

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

Just put it into a testset

@testset "Testing $(alg) on $(m.name)" for m in mean_of_mean_models
...
end

?

Copy link
Member Author

Choose a reason for hiding this comment

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

Wait wat?! That works?!

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Sick! Did not know that:)

Comment on lines +55 to +56
# A collection of models for which the mean-of-means for the posterior should
# be same.
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, what exactly do you mean with mean-of-means? And is the value the same as the prior? Or between the models? And only with the default arguments or in general?

Copy link
Member Author

Choose a reason for hiding this comment

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

I want to have a collection of models which tries out all the combinations of *_tilde_*, but this means that we'll sometimes have univariate latent variables rather than multivariate (e.g. gdemo5 below). Therefore I compare the mean of the mean of the latent variables rather than the variables directly.

Buuuuut now that we're comparing to the true mean rather than pitting the different models against each other, I guess we don't need to do that 😅

Project.toml Outdated Show resolved Hide resolved
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
@coveralls
Copy link

coveralls commented Jun 10, 2021

Pull Request Test Coverage Report for Build 924779474

  • 3 of 5 (60.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+1.02%) to 79.325%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/variational/advi.jl 0 2 0.0%
Totals Coverage Status
Change from base Build 899504966: 1.02%
Covered Lines: 1128
Relevant Lines: 1422

💛 - Coveralls

@codecov
Copy link

codecov bot commented Jun 10, 2021

Codecov Report

Merging #1633 (64a816a) into master (c79dce0) will increase coverage by 1.02%.
The diff coverage is 60.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1633      +/-   ##
==========================================
+ Coverage   78.30%   79.32%   +1.02%     
==========================================
  Files          23       23              
  Lines        1424     1422       -2     
==========================================
+ Hits         1115     1128      +13     
+ Misses        309      294      -15     
Impacted Files Coverage Δ
src/variational/advi.jl 61.11% <0.00%> (-1.16%) ⬇️
src/inference/ess.jl 98.00% <100.00%> (+4.12%) ⬆️
src/stdlib/distributions.jl 56.98% <0.00%> (+1.07%) ⬆️
src/modes/ModeEstimation.jl 80.76% <0.00%> (+9.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c79dce0...64a816a. Read the comment docs.

@torfjelde
Copy link
Member Author

@devmotion You ready to give it 👍 ?

Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

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

Looks good 👍 Maybe test/Project.toml doesn't have to be modified?

test/Project.toml Outdated Show resolved Hide resolved
test/Project.toml Outdated Show resolved Hide resolved
@yebai yebai merged commit 9f52d75 into master Jun 10, 2021
@delete-merged-branch delete-merged-branch bot deleted the tor/fix-1633 branch June 10, 2021 11:53
@yebai
Copy link
Member

yebai commented Jun 10, 2021

thanks, @torfjelde.

torfjelde added a commit that referenced this pull request Jun 10, 2021
* removed unnecessary exports

* updated OptimizationContext

* updated ESS smapler

* fixed #1633

* fixed bug where ESS didnt support dot_observe

* added some additional models to test against

* added test for ESS on the mean-of-mean models

* patch version bump

* added tests on mean_of_mean_models for optimization methods too

* fixed bug in bijector after recent update to Bijectors.jl

* use exact value in check_mean_of_mean_models

* fixed bug in OptimizationContext

* just use MvNormal instead of TuringDiagMvNormal in test models

* renamed the mean_of_mean models used tests

* renamed the mean_of_mean_models in tests to gdemo_models

* removed redundant testset block

* upper-bound compat entries for Libtask while we wait for bugfix

* compat entries with hyphens arent supported on Julia v1.3

* compat entries with hyphens not supported on Julia 1.3

* also test models with literal observe

* Update Project.toml

Co-authored-by: David Widmann <devmotion@users.noreply.github.com>

* forgot to bump DPPL version

* Apply suggestions from code review

* bump DPPL patch version to fix AdvancedPS samplers

* bump patch version

Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
yebai pushed a commit that referenced this pull request Aug 14, 2021
* removed unnecessary exports

* updated OptimizationContext

* updated ESS smapler

* fixed #1633

* fixed bug where ESS didnt support dot_observe

* added some additional models to test against

* added test for ESS on the mean-of-mean models

* patch version bump

* added tests on mean_of_mean_models for optimization methods too

* fixed bug in bijector after recent update to Bijectors.jl

* use exact value in check_mean_of_mean_models

* fixed bug in OptimizationContext

* just use MvNormal instead of TuringDiagMvNormal in test models

* renamed the mean_of_mean models used tests

* renamed the mean_of_mean_models in tests to gdemo_models

* removed redundant testset block

* upper-bound compat entries for Libtask while we wait for bugfix

* compat entries with hyphens arent supported on Julia v1.3

* compat entries with hyphens not supported on Julia 1.3

* also test models with literal observe

* Update Project.toml

Co-authored-by: David Widmann <devmotion@users.noreply.github.com>

* forgot to bump DPPL version

* Apply suggestions from code review

* bump DPPL patch version to fix AdvancedPS samplers

* bump patch version

* updated OptimizationContext to work with the new version of DPPL

Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
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.

None yet

4 participants