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

Dynesty warnings added #1324

Merged
merged 10 commits into from
Mar 15, 2024
Merged

Dynesty warnings added #1324

merged 10 commits into from
Mar 15, 2024

Conversation

arrjon
Copy link
Contributor

@arrjon arrjon commented Mar 11, 2024

The wrapper for the dynesty sampler differs significantly to the other samplers in pyPESTO. Usually the samplers expect the objective to be the posterior and x_priors to be defined, from which they compute the likelihood if needed. I added the argument objective_type to the sampler to switch between posterior and likelihood with default set to posterior. I also added checks in the initialize function to very if x_priors is defined in the problem or not.

Furthermore, I added a warning that by default, a uniform prior with bounds specified in the problem is assumed. This warning was missing, but already mentioned in the prior_transform function.

@arrjon arrjon added bug Something isn't working sampling Related to sampling labels Mar 11, 2024
Copy link
Member

@dilpath dilpath left a comment

Choose a reason for hiding this comment

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

Thanks!

pypesto/sample/dynesty.py Outdated Show resolved Hide resolved
pypesto/sample/dynesty.py Outdated Show resolved Hide resolved
pypesto/sample/dynesty.py Show resolved Hide resolved
pypesto/sample/dynesty.py Outdated Show resolved Hide resolved
pypesto/sample/dynesty.py Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Mar 11, 2024

Codecov Report

Attention: Patch coverage is 21.42857% with 11 lines in your changes are missing coverage. Please review.

Project coverage is 53.47%. Comparing base (b1298ea) to head (75bc446).

Files Patch % Lines
pypesto/sample/dynesty.py 8.33% 11 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #1324       +/-   ##
============================================
- Coverage    81.32%   53.47%   -27.86%     
============================================
  Files          153      153               
  Lines        12515    12529       +14     
============================================
- Hits         10178     6700     -3478     
- Misses        2337     5829     +3492     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vwiela
Copy link
Contributor

vwiela commented Mar 12, 2024

Do we want to add this flag only in the dynesty sampler? I think it would be better to add it on the objective level.

Copy link
Member

@dilpath dilpath left a comment

Choose a reason for hiding this comment

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

Feel free to merge with just the warning and leave the objective_type things to a new PR where objective attributes are added.

Copy link
Contributor

@vwiela vwiela left a comment

Choose a reason for hiding this comment

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

Fine then as a temporary fix for the dynesty sampler and to have some warnings.

Copy link
Contributor

@Doresic Doresic 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. Good temporary solution for dynesty.

I have a general question, possibly stupid.
As much as I understand, the OBJECTIVE_NEGLOGLIKE and NEGLOGPOST constants are only passed to the dynesty sampler upon construction such that it knows whether it needs to remove the priors from the objective function when calculating the likelihood.

My question is whether the constants are necessary? Why not define the loglikelihood of dynesty to always remove the prior in cases a prior exists? The only case when it should not remove the prior from the objective is when it does not exist, right? I might be missing something.

@arrjon
Copy link
Contributor Author

arrjon commented Mar 15, 2024

My question is whether the constants are necessary? Why not define the loglikelihood of dynesty to always remove the prior in cases a prior exists? The only case when it should not remove the prior from the objective is when it does not exist, right? I might be missing something.

If you load a petab problem, that should work fine. But if you define your objective yourself (which could be the nllh) and you define x_priors as well, you would compute something wrong without giving any warnings. That is not only a problem in dynesty, but also with the other samplers, see #1325.

# Conflicts:
#	test/sample/test_sample.py
@arrjon arrjon merged commit 2558763 into develop Mar 15, 2024
18 checks passed
@arrjon arrjon deleted the dynesty_update branch March 15, 2024 10:41
@PaulJonasJost PaulJonasJost mentioned this pull request Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sampling Related to sampling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants