-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Establish new test framework for the "random" behavior of Distributions #4554
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
Comments
+1 to this, we should set up using https://hypothesis.readthedocs.io/en/latest/ See for example https://github.com/tensorflow/probability/blob/master/tensorflow_probability/python/internal/hypothesis_testlib.py |
If it's still free, I would be keen to work on this |
It is still free. Do you have any ideas on how to tackle this? |
My understanding is that given that
Still not sure how to do this |
I am still having a hard time understanding where exactly in Despite that, I would expect the two samples below to converge, given a large enough n.
So, possibly the Kolmogorov–Smirnov and the Chi-Square currently ran respectively by However, given that
This approach may be overkill, I still haven't considered how to test the right parameterization. I have the feeling that one way or another it will still be necessary to rely on the distribution generated... Let me know what you think |
This is the default |
The exponential is not working right now (#4576) that's why you see those failing tests (if you try 1/10 in one or the other they should match). Trying with another distribution like normal that can be given in terms of tau and sigma should give you a better idea of what is needed. |
This should be straightforward; for example, if the underlying Here's an illustration based on your example: import numpy as np
import aesara
from pymc3.distributions.continuous import Exponential
test_lambda = 10.
rng_at = aesara.shared(np.random.RandomState(23092))
exp_pymc = Exponential.dist(lam=test_lambda, rng=rng_at)
# We only need to confirm that the parameterization from `Exponential` to
# `ExponentialRV` is correct. We can do this directly, exactly, and without
# resorting to costly statistical tests.
#
# `ExponentialRV` uses the `scale` argument to `np.random.exponential`,
# so we only need to check that the `scale` parameter is equal to one over
# the `lam` value we gave to `Exponential.`
#
# All the `Apply` node inputs after the third one are distribution parameters,
# so we get and compare those.
rv_scale, = exp_pymc.owner.inputs[3:]
assert rv_scale.eval() == 1/test_lambda Otherwise, are the NumPy results and the np.random.seed(23092)
exp_vals_np = np.array([np.random.exponential(scale=10) for _ in range(10_000)])
exp_vals_pymc = np.array([exp_pymc.eval() for _ in range(10_000)]) >>> exp_vals_np.mean() - exp_vals_pymc.mean()
0.0 They are. |
@brandonwillard I think you are missing the fact that the exponential In [4]: np.random.exponential(scale=10, size=1000).mean()
Out[4]: 10.024648140707738 # pymc3 master
In [7]: pm.Exponential.dist(lam=10).random(size=1000).mean()
Out[7]: 0.10322241829781785 |
No, we're talking about how to make tests for bugs like this, and not that there are bugs like this. FYI: |
Thanks to both, in particular for the detailed illustration and pointing out that I created a WIP PR with a first possible approach to test the parameterization. I still need to add more distributions and also check whether there are other tests which is worth removing.
Fundamentally I simply needed to spend more time on the docs. At that point, I only really read the aesara code, but I got lost into the |
In general,
|
The distributions refactoring moves the random variable sampling to aesara. This relies on numpy and scipy random variables implementation. So, now the only thing we care about testing is that the parametrization on the PyMC side is sendible given the one on the Aesara side (effectively the numpy/scipy one) More details can be found on issue pymc-devs#4554 pymc-devs#4554
Most of the random variable logic has been moved to aesara, as well as most of the relative tests. More details can be found on issue pymc-devs#4554
The distributions refactoring moves the random variable sampling to aesara. This relies on numpy and scipy random variables implementation. So, now the only thing we care about testing is that the parametrization on the PyMC side is sendible given the one on the Aesara side (effectively the numpy/scipy one) More details can be found on issue pymc-devs#4554 pymc-devs#4554
More details can be found on issue pymc-devs#4554 pymc-devs#4554
More details can be found on issue pymc-devs#4554 pymc-devs#4554
Most of the random variable logic has been moved to aesara, as well as most of the relative tests. More details can be found on issue pymc-devs#4554
The distributions refactoring moves the random variable sampling to aesara. This relies on numpy and scipy random variables implementation. So, now the only thing we care about testing is that the parametrization on the PyMC side is sendible given the one on the Aesara side (effectively the numpy/scipy one) More details can be found on issue pymc-devs#4554 pymc-devs#4554
More details can be found on issue pymc-devs#4554 pymc-devs#4554
More details can be found on issue pymc-devs#4554 pymc-devs#4554
Most of the random variable logic has been moved to aesara, as well as most of the relative tests. More details can be found on issue pymc-devs#4554
* Update tests following distributions refactoring The distributions refactoring moves the random variable sampling to aesara. This relies on numpy and scipy random variables implementation. So, now the only thing we care about testing is that the parametrization on the PyMC side is sendible given the one on the Aesara side (effectively the numpy/scipy one) More details can be found on issue #4554 #4554 * Change tests for more refactored distributions. More details can be found on issue #4554 #4554 * Change tests for refactored distributions More details can be found on issue #4554 #4554 * Remove tests for random variable samples shape and size Most of the random variable logic has been moved to aesara, as well as most of the relative tests. More details can be found on issue #4554 * Fix test for half cauchy, renmae mv normal tests and add test for Bernoulli * Add test checking PyMC samples match the aesara ones Also mark test_categorical as expected to fail due to bug on aesara side. The bug is going to be fixed with 2.0.5 release, so we need to bump the version for categorical and the test to pass. * Move Aesara to 2.0.5 to include Gumbel distribution * Enamble exponential and gamma tests following bug-fix * Enable categorical test following aesara version bump to 2.0.5 and relative bug-fix * Few small cosmetic changes: - replace list of tuples with dict - rename 1 method - move pymc_dist as first argument in function call - replace list(params) with params.copy() * Remove redundant tests * Further refactoring The refactoring should make it possible testing both the distribution parametrization and sampled values according to need, as well as any other future test. More details on PR #4608 * Add size tests to new rv testing framework * Add tests for multivariate and for univariate multi-parameters * remove test already covered in aesara * fix few names * Remove "distribution" from test class names * Add discrete Weibull, improve Beta and some minor refactoring * Fix typos in checks naming and add sanity check Co-authored-by: Ricardo <[email protected]>
Closed via #4608 |
* Update tests following distributions refactoring The distributions refactoring moves the random variable sampling to aesara. This relies on numpy and scipy random variables implementation. So, now the only thing we care about testing is that the parametrization on the PyMC side is sendible given the one on the Aesara side (effectively the numpy/scipy one) More details can be found on issue #4554 #4554 * Change tests for more refactored distributions. More details can be found on issue #4554 #4554 * Change tests for refactored distributions More details can be found on issue #4554 #4554 * Remove tests for random variable samples shape and size Most of the random variable logic has been moved to aesara, as well as most of the relative tests. More details can be found on issue #4554 * Fix test for half cauchy, renmae mv normal tests and add test for Bernoulli * Add test checking PyMC samples match the aesara ones Also mark test_categorical as expected to fail due to bug on aesara side. The bug is going to be fixed with 2.0.5 release, so we need to bump the version for categorical and the test to pass. * Move Aesara to 2.0.5 to include Gumbel distribution * Enamble exponential and gamma tests following bug-fix * Enable categorical test following aesara version bump to 2.0.5 and relative bug-fix * Few small cosmetic changes: - replace list of tuples with dict - rename 1 method - move pymc_dist as first argument in function call - replace list(params) with params.copy() * Remove redundant tests * Further refactoring The refactoring should make it possible testing both the distribution parametrization and sampled values according to need, as well as any other future test. More details on PR #4608 * Add size tests to new rv testing framework * Add tests for multivariate and for univariate multi-parameters * remove test already covered in aesara * fix few names * Remove "distribution" from test class names * Add discrete Weibull, improve Beta and some minor refactoring * Fix typos in checks naming and add sanity check Co-authored-by: Ricardo <[email protected]>
#4508 and #4548 started the refactoring of Distributions whose random Ops were already defined in Aesara, and we should be able to start converting the remaining ones anytime now.
It seems that the logp/ logcdf tests in
test_distributions.py
should stay more or less unchanged, but we might want to change or remove most of the tests intest_distributions_random.py
.Right now, in
test_distribtions_random.py
, we are generating a couple hundred samples via pymc3 and scipy and checking they match by doing a Kolmogorov-Smirnov test.@brandonwillard said that since we are basically just calling numpy / scipy random routines under the hood, it should be enough to check we are converting properly between our parametrizations and the scipy ones.
For the shapes, we can assume that if things are working on Aesara side, they should be working here?
This is the minimalist example of what we need to check:
Anything I am missing?
The text was updated successfully, but these errors were encountered: