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

Refactoring the ChiSquared distribution #4695

Merged
merged 13 commits into from
Jun 7, 2021
Merged

Refactoring the ChiSquared distribution #4695

merged 13 commits into from
Jun 7, 2021

Conversation

larryshamalama
Copy link
Member

This PR further addresses the ongoing issue 4686

I don't fully understand the process of creating tests, but I try to follow the previously mentioned template. If my edits are good (please let me know if I need to correct anything), my questions are:

  • How can I know when to use seeded_numpy_distribution_builder or seeded_scipy_distribution_builder vs. creating my own function?
  • What tests should be run in the list tests_to_run?

If there are other PRs or documentation that addresses my questions, I am happy to be pointed to them.

Thanks!

@twiecki twiecki requested a review from ricardoV94 May 14, 2021 06:27
@twiecki
Copy link
Member

twiecki commented May 14, 2021

Thanks for taking this on @larryshamalama!

@twiecki twiecki mentioned this pull request May 14, 2021
26 tasks
@ricardoV94
Copy link
Member

ricardoV94 commented May 14, 2021

@larryshamalama Thanks for taking on this one.

Unfortunately it seems the chisquare RandomVariable should go on our aesara library , as it is offered by numpy. Would you like to open a PR there? It would look similar to this one: https://github.com/pymc-devs/aesara/pull/363/files, but including just the ChiSquareRV that you created here.

Then we can come back to this PR and import the op from aesara. We might still need other changes related to the fact we are inheriting from the Gamma, but we can discuss that after.

@larryshamalama
Copy link
Member Author

Thanks so much for the suggestions @ricardoV94, I can do just that and then edit this PR accordingly.

@larryshamalama
Copy link
Member Author

larryshamalama commented May 20, 2021

Using aesara's op now. Still unsure if I am properly inheriting from Gamma

Edit: jobs seem to be failing...

@larryshamalama larryshamalama marked this pull request as draft May 20, 2021 22:59
pymc3/distributions/continuous.py Show resolved Hide resolved
pymc3/distributions/continuous.py Outdated Show resolved Hide resolved
@ricardoV94
Copy link
Member

ricardoV94 commented May 21, 2021

Even after fixing the errors, the tests will still fail until a new version of Aesara is released. You should test that it passes locally for the time being

@ricardoV94
Copy link
Member

The latest Aesara version was released, you should be able to install it (version 2.0.9) and make use of the chisquare function now.

@ricardoV94
Copy link
Member

Hi @larryshamalama, any progress on this PR?

@larryshamalama
Copy link
Member Author

Hi @ricardoV94, so sorry for the delay, this PR sat on my back burner due to organizing an upcoming conference. Let me revisit this today.

@ricardoV94
Copy link
Member

ricardoV94 commented May 30, 2021

There is no rush, just wanted to know what was the status :)

@larryshamalama
Copy link
Member Author

Even after fixing the errors, the tests will still fail until a new version of Aesara is released. You should test that it passes locally for the time being

Embarrassing question... do you mind explaining how to check this? I'm new to testing in general and was not able to successfully run some test functions by copy pasting into a notebook (see here). Do you have any suggestions or tips?

@ricardoV94
Copy link
Member

Embarrassing question... do you mind explaining how to check this? I'm new to testing in general and was not able to successfully run some test functions by copy pasting into a notebook

There is nothing embarrassing about it. First of all, the tests should now work here as we have already updated the aesara version we are using.

In any case it's very important to get comfortable running tests locally. Ideally you would run your tests from the terminal by calling pytest path/to/test file.py -k testfunction/testclass You should read the documentation here or search for some tutorials.

Alternatively you can use some IDEs like pycharm that allow you to run tests from the interface.

Copying tests to a separate notebook should only be a last resort thing (if ever advisable) because it's much more difficult to setup, and not easy to use debugging tools that you'll need when you can't easily figure out why a test is failing.

@ricardoV94
Copy link
Member

ricardoV94 commented May 31, 2021

You should also install pre-commit locally if you haven't yet. One of the failing tests is just the code style check because you didn't include a space between the division operator.

You can read our wiki to learn how to install and run it: https://github.com/pymc-devs/pymc3/wiki/PyMC3-Python-Code-Style

This way it will catch this sort of errors automatically (and fix them if it can) when you try to make a commit, saving you some time.

@larryshamalama
Copy link
Member Author

larryshamalama commented Jun 2, 2021

so I spent some time looking into testing and the library... My newly created tests are failing but I have no idea how to fix them. Checking TestChiSquare using pytest test_distributions_random.py -k TestChiSquare gives me to following error:

============================================================================== short test summary info ============================================================================== FAILED test_distributions_random.py::TestChiSquare::test_distribution - TypeError: object.__init__() takes exactly one argument (the instance to initialize)

I checked my ChiSquare class in continuous.py, but I feel a bit stuck. Do you have any thoughts or pointers that you want to share?

pymc3/distributions/continuous.py Outdated Show resolved Hide resolved
pymc3/distributions/continuous.py Outdated Show resolved Hide resolved
@larryshamalama larryshamalama marked this pull request as ready for review June 7, 2021 14:50
Copy link
Member

@ricardoV94 ricardoV94 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. Let's see if the tests pass :)

@twiecki twiecki merged commit b4a67d3 into pymc-devs:v4 Jun 7, 2021
@twiecki
Copy link
Member

twiecki commented Jun 7, 2021

Thanks @larryshamalama!

@ricardoV94
Copy link
Member

ricardoV94 commented Jun 7, 2021

Was this merged into v4?

@twiecki
Copy link
Member

twiecki commented Jun 7, 2021

Damn, my bad. @ricardoV94 can you fix that?

@ricardoV94
Copy link
Member

I don't think I would have realized it in time either. How can it be fixed, other than opening a new PR with the same content?

@larryshamalama
Copy link
Member Author

Oh no, was this supposed to be merged into another branch?

ricardoV94 pushed a commit to ricardoV94/pymc that referenced this pull request Jun 7, 2021
* Refactoring ChiSquared distribution

* Refactoring ChiSquared (minor edit)

* Refactoring Chisquared (another one-line change)

* Trying to rebase/merge my branch with updated upstream v4

* Using aesara chisquare op (r.f. PR pymc-devs#414) and renamed ChiSquared to ChiSquare

* Added logpdf & logcdf to the ChiSquare class

* Corrected function name

* Updating branch

* Refactoring ChiSquared: bug fixed, tests work locally

* Minor fix: removed float32 specification

* ☀️ underflow to -inf seems normal in float32

* Minor fix in documentation
twiecki pushed a commit that referenced this pull request Jun 9, 2021
* Refactoring ChiSquared distribution

* Refactoring ChiSquared (minor edit)

* Refactoring Chisquared (another one-line change)

* Trying to rebase/merge my branch with updated upstream v4

* Using aesara chisquare op (r.f. PR #414) and renamed ChiSquared to ChiSquare

* Added logpdf & logcdf to the ChiSquare class

* Corrected function name

* Updating branch

* Refactoring ChiSquared: bug fixed, tests work locally

* Minor fix: removed float32 specification

* ☀️ underflow to -inf seems normal in float32

* Minor fix in documentation
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.

3 participants