-
Notifications
You must be signed in to change notification settings - Fork 16
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
Made a new branch called logLmax with the updated anesthetic.examples… #348
Conversation
….perfect_ns.correlated_gaussian.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #348 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 34 34
Lines 2984 2978 -6
=========================================
- Hits 2984 2978 -6 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks for this proposal @DilyOng.
At the moment the tests are failing because your changes are not flake8 PEP compliant. You can see this by clicking 'Details' next to the failed test, and see it locally by running python -m flake8 anesthetic tests
. You also need to increment the version number as the Checklist at the top of the PR suggests.
Could you add a test to tests.test_examples.test_perfect_ns_correlated_gaussian
which checks that the logLmax functionality is working. The best thing to do would be to make a run with logLmax equal to some number (e.g. 10), and check that samples.logL.mean()
is close to logLmax-d/2
, where d is the number of parameters.
One other thing we should consider is putting in a logLmax into the gaussian
function as well. This would also need a test.
…, which checks that the logLmax functionality is working
… of the other tests. I am using numpy.testing.assert_allclose() but not sure what to put for rtol and atol. I have also updated the .gitignore file to exclude the .DS_Store file. In the __init__.py, I added a temporary line in line 12 to check if the correct anesthetic is being imported locally. This line will need to be removed later.
…te tolerance to the assert_allclose function in test_logLmax. The test is passed. I previously accidentally deleted tests/test.ipynb so I added it back. Deleted the line, print test logLmax in anesthetic/__init__.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks @DilyOng.
- Could you remove the tests/tests.ipynb file
- Could you move test_perfect_ns_correlated_gaussian.py int othe file tests/test_examples.py
- Could you add the logLmax variable to
gaussian
- The version number should be 2.5.0 as we have added functionality
- Could you modify & simplify the planck_gaussian function so that it uses your new functionality!
…st_perfect_ns_correlated_gaussian.py to tests/test_examples.py, then removed test_perfect_ns_correlated_gaussian.py. Added logLmax variable to gaussian() in anesthetic/examples/perfect_ns.py. Changed version number to 2.5.0 becuase we have added functionality. Modified the planck_gaussian() function in examples/perfect_ns.py, added logLmax when calling the correlated_gaussian() function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @DilyOng,
I have pushed a minor but structural change, which implements the functionality that in gaussian
, wedding_cake
and correlated_gaussian
the 'rest of the arguments' *args, **kwargs
are passed on to the NestedSamples
constructor.
The main reason for doing this is that it allows us to pass columns
and params
to correlated_gaussian
in the planck_gaussian
function.
One further minor change is that with logL_max
being set means that the logL_mean
comes with an additional nested sampling error, so the tests associated with
logL_mean` had to be adjusted.
If you're happy with these changes, you should add yourself to the author list in pyproject.toml
, and then I'll approve these changes to be merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks @DilyOng. Please press 'squash and merge'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @DilyOng, just one request from me. Could we add a docstring entries for logLmax
, please?
def gaussian(nlive, ndims, sigma=0.1, R=1, logLmin=-1e-2, logLmax=0, | ||
*args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logLmax
is lacking a docstring entry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comment. But logLmax needs to be a number. I'm not sure what you mean I am sorry...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring underneath the function definition is the text that describes what the function does such that a new user can quickly inform themselves on the correct usage. Such a function docstring should include a list of (at least) all the explicit function arguments. By numpy convention (which is the one that we are using), all these function arguments get listed underneath a "Parameters" heading. In jupyter notebooks this docstring is easily accessible by pressing shift+tab
inside a function.
Here, the docstring currently is:
"""Perfect nested sampling run for a spherical Gaussian & prior.
Up to normalisation this is identical to the example in John Skilling's
original paper https://doi.org/10.1214/06-BA127 . Both spherical Gaussian
width sigma and spherical uniform prior width R are centered on zero
Parameters
----------
nlive : int
number of live points#
ndims : int
dimensionality of gaussian
sigma : float
width of gaussian likelihood
R : float
radius of gaussian prior
logLmin : float
loglikelihood at which to terminate
The remaining arguments are passed to the
:class:`anesthetic.samples.NestedSamples` constructor.
Returns
-------
samples : :class:`anesthetic.samples.NestedSamples`
Nested sampling run
"""
So this currently lists nlive
, ndims
, sigma
, R
, and logLmin
, but it lacks a description of logLmax
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for explaining! I've implemented your suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I was hoping for a bit more description...
Then again, the docstring for the other arguments is also very minimalistic... and possibly a bit misleading... Is this really a nested sampling run of a spherical Gaussian and prior? Or would it be more accurate to call it a nested sampling run of a spherical Gaussian likelihood from a spherical top-hat prior? In which case the docstring for R
should be rather the radius of the spherical top-hat prior...
Anyhow, it's not right to ask you to clean all that up (unless you want to), but it would be nice if you could make the logLmax
docstring a bit more descriptive. Something along the lines that, yes, this defines the maximum of the Gaussian likelihood, but in effect this only shifts the log-likelihood up and down by a constant. Is there a reason anyone should choose a value different from the default logLmax=0
? What prompted you to introduce this argument the first place? If that is a gotcha that would be good for other people to be aware of, then this is a good place to warn about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @lukashergt I am terribly sorry for my late reply, I somehow missed your newest comment.
The reason why we need to add LogLmax is because we’ve found an issue with the definition of combined Gaussian likelihood. We are recently adding a new function (in the branch called tension) to anesthetic for calculating tension statistics between datasets. The initial test involves creating 2 mock datasets A and B with d-dimensional Gaussian likelihood and a combined dataset AB (combining A and B on the likelihood level). We discovered that the quantity of logLmax is actually needed explicitly in the calculation of combined likelihoods. Besides, we have noticed that the correlated_gaussian() function does not produce a normalised correlated gaussian likelihood and the evidence isn’t unity. Therefore, we need to update the function description. Please refer to equations 14-21 in the paper Quantifying tensions in cosmological parameters: Interpreting the DES evidence ratio [1902.04029]. Thank you very much!
def correlated_gaussian(nlive, mean, cov, bounds=None, logLmax=0, | ||
*args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docstring entry for logLmax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Please implement changes requested by @!ukashergt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I did not mean to halt this completely, just thought it best to document things thoroughly while the reason for changes/additions are fresh in our minds, but not at the cost of causing a standstill, so I'd rather approve this now.
….perfect_ns.correlated_gaussian.
Description
A bug was found in the function anesthetic.examples.perfect_ns.correlated_gaussian(). The generated Gaussian likelihood is not normalised and the evidence is not unity. Three changes have been made.
Fixes # (issue)
Checklist:
flake8 anesthetic tests
)pydocstyle --convention=numpy anesthetic
)python -m pytest
)