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

Reenable PriorContext for Optimization #2165

Merged
merged 2 commits into from
Jun 5, 2024
Merged

Conversation

alyst
Copy link
Contributor

@alyst alyst commented Feb 3, 2024

This PR reenables the support for PriorContext in optimization, which was disabled by #2022.
While it is not directly supported by the current optim_problem() interface (only MLE/MAP are supported, although adding MaxPrior is possible), I think it is useful to support PriorContext for Turing.OptimLogDensity().
In my code I use it for multi-objective Pareto optimization (prior + llh).

@devmotion
Copy link
Member

This PR reenables the support for PriorContext in optimization, which was disabled by #2022.

AFAICT support for PriorContext has never existed and has never been tested. The check in the PR was only introduced to communicate this more clearly and provide a better error message.

@alyst
Copy link
Contributor Author

alyst commented Feb 4, 2024

AFAICT support for PriorContext has never existed and has never been tested.

I see. It was working before though. Do you think it makes sense to support it for some of the user use cases?

@torfjelde
Copy link
Member

IMO if we 're allowing both DefaultContext and LikelihoodContext, I feel like allowing PriorContext also seems reasonable (i.e. all the leaf-contexts).

Copy link
Collaborator

@mhauru mhauru left a comment

Choose a reason for hiding this comment

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

I had one minor style change to suggest.

I also got some extra peace of mind by, in the test, checking that

            true_prior_logpdf = -Distributions.logpdf(Uniform(0, 2), a[1])
            @test Turing.OptimLogDensity(m1, prictx)(a) ≈ true_prior_logpdf

Could incorporate a more explicit check like that.

Both of these are optional, I'd be okay with the code as is. I'll leave approving for @torfjelde since there might be context (pun unintended) to this that I lack.

src/optimisation/Optimisation.jl Outdated Show resolved Hide resolved
@alyst
Copy link
Contributor Author

alyst commented May 30, 2024

@mhauru I have incorporated your suggestions, thank you!

@torfjelde
Copy link
Member

Would be happy to include this:) But we need to fix the merge conflicts 😕

Co-authored-by: Markus Hauru <markus@mhauru.org>
@coveralls
Copy link

coveralls commented Jun 5, 2024

Pull Request Test Coverage Report for Build 9384233247

Details

  • 0 of 5 (0.0%) changed or added relevant lines in 1 file are covered.
  • 89 unchanged lines in 1 file lost coverage.
  • Overall coverage remained the same at 0.0%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/optimisation/Optimisation.jl 0 5 0.0%
Files with Coverage Reduction New Missed Lines %
src/optimisation/Optimisation.jl 89 0.0%
Totals Coverage Status
Change from base Build 9374257750: 0.0%
Covered Lines: 0
Relevant Lines: 1503

💛 - Coveralls

Copy link
Collaborator

@mhauru mhauru 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 to me

@mhauru mhauru merged commit f135821 into TuringLang:master Jun 5, 2024
56 checks passed
@mhauru
Copy link
Collaborator

mhauru commented Jun 5, 2024

Thanks @alyst!

@alyst alyst deleted the prior_optctxt branch June 5, 2024 22:21
@torfjelde
Copy link
Member

Lovely work @alyst :)

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

5 participants