-
Notifications
You must be signed in to change notification settings - Fork 246
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
gh-1806: Implementation of Doubly Truncated Power Law and Lower Truncated Power Law #1807
Conversation
@fehiepsi Power Law is not in SciPy. Can you guide me for the Unit Tests? |
Hi @Qazalbash, you could add if/else statements to skip some tests (like some other distributions). Do you have reference for this distribution? I couldn't find it on wikipedia. |
@fehiepsi unfortunately I couldn't find much on internet too. I have seen many papers in astrophysics using these distributions. Therefore, I did the derivations. If you like to see, I can share them. This way we can cross check it too. |
I think we would need to let users know how to use the distribution. Could you add references / formulas in the docstring? I can double-check the formulas - though I hope that the tests will cover them. |
…DoublyTruncatedPowerLaw
|
I think you need double where. See this note |
Your suggestion worked and the gradient is some float now! But values are still diverging. I have rechecked my derivations and implementation a couple of times. You can double-check it! |
…ixing the discontinuity point for alpha equals minus one and correct tangents for lower and upper bounds.
…minus one and also changed equation to keep equational uniformity UpperTruncatedPowerLaw to and improved stability of the calculation by integrating formula parts inside log to prevent NaN values due to negative values of some parts that could balance out in the end.
@Qazalbash Please see my pull request in your repository. Probably this can solve the problems. |
@InfinityMod, I will look into it. |
@InfinityMod The only problem left is the failing of test cases, can you look into it? |
Hi, please see #1860 to solve the long testing times and the problems significantly when increasing the numerical accuracy to 64-bit. @Qazalbash, @fehiepsi, looking forward to the review and the validation. |
@Qazalbash, could you merge #1860 into this pull request? |
Can you change the base of your PR to |
I'm not sure if it can still be merged into the master branch if I change the base right now. |
We should wait till #1860 gets merged to |
i just merged the other PR. Thanks both! |
@fehiepsi I have merged the |
Ah, testing went through now. No stopping anymore. |
for some reasons, float64 is enabled for other distributions, not just power law ones. I will think a bit more on why it is the case. |
@fehiepsi @InfinityMod Finally all test cases are passing. I fixed them by disabling the higher precession at the start of every test because previously we were enabling it and not disabling it after the test, which let other tests and distributions be tested on x64 precession. My thought process!I tried to fix them in the following fashion, Switch between enable and disable (f1da2d5)if jax_dist in [dist.LowerTruncatedPowerLaw, dist.DoublyTruncatedPowerLaw]:
numpyro.enable_x64()
else:
numpyro.enable_x64(False) Disable before x64 in tests for power laws (42ed59d)numpyro.enable_x64(False)
if jax_dist in [dist.LowerTruncatedPowerLaw, dist.DoublyTruncatedPowerLaw]:
numpyro.enable_x64() Why no sandwich?The next obvious thing was to sandwich tests between enable and disable, like, if jax_dist in [dist.LowerTruncatedPowerLaw, dist.DoublyTruncatedPowerLaw]:
numpyro.enable_x64()
# tests
if jax_dist in [dist.LowerTruncatedPowerLaw, dist.DoublyTruncatedPowerLaw]:
numpyro.enable_x64(False) This is okay if every test comes to the last line. Many tests were using Disable every time (2671edb)The best way I could figure out was to disable it at the start of every test and it worked! |
Glad to merge this awesome work! Thanks for adding |
Awesome, glad it finally worked out! |
This PR contains the implementation of Power Law distributions, that fixes #1806. There are two different types of power law implementations based on their truncation.
DoublyTruncatedPowerLaw
LowerTruncatedPowerLaw
They are named in such way to avoid confusion with
TwoSidedTruncated*
andLeftTruncated*
distributions.