Skip to content

Implement icdf for Univariate distribution #6528

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

Merged
merged 11 commits into from
Mar 19, 2023

Conversation

michaelraczycki
Copy link
Contributor

@michaelraczycki michaelraczycki commented Feb 17, 2023

What is this PR about?
Adding icdf functions for existing distributions
Creation of tests for added idcf functions

Major / Breaking Changes

  • ...

New features

  • icdf function for Uniform distritubtion

Bugfixes

  • ...

Documentation

  • ...

Maintenance

  • extended test_continuous.py with corresponding tests

@michaelraczycki
Copy link
Contributor Author

@ricardoV94 if that's what you had in mind I can continue adding them for other distributions, I wanted to create a PR before writing a lot to make sure we're on the same page

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 like a good start! Some issues mentioned in the comments below

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, left some comments below and don't miss the test :)

@codecov
Copy link

codecov bot commented Feb 20, 2023

Codecov Report

Merging #6528 (63641a7) into main (67925df) will increase coverage by 0.00%.
The diff coverage is 93.33%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #6528   +/-   ##
=======================================
  Coverage   92.01%   92.01%           
=======================================
  Files          93       93           
  Lines       15737    15742    +5     
=======================================
+ Hits        14480    14485    +5     
  Misses       1257     1257           
Impacted Files Coverage Δ
pymc/testing.py 91.79% <90.90%> (+0.01%) ⬆️
pymc/distributions/continuous.py 97.70% <100.00%> (+<0.01%) ⬆️

@michaelraczycki
Copy link
Contributor Author

@ricardoV94 I've included tests in previous commits, following the lead from test_normal_icdf. Please take a look at it, as I might have missed something

@ricardoV94
Copy link
Member

@ricardoV94 I've included tests in previous commits, following the lead from test_normal_icdf. Please take a look at it, as I might have missed something

Oh sorry I must have missed it, I was looking only at the last commit

@michaelraczycki
Copy link
Contributor Author

I assume that I still need to add params like lower and upper for distribution tests that require them. I'm just not quite sure if it's possible to include conditional arguments in @pytest.mark.parametrize, or I should create another set of test parameters (try to group them up, so they can share the same test datasets)

@ricardoV94
Copy link
Member

I assume that I still need to add params like lower and upper for distribution tests that require them. I'm just not quite sure if it's possible to include conditional arguments in @pytest.mark.parametrize, or I should create another set of test parameters (try to group them up, so they can share the same test datasets)

Each row in the parametrize should include one set of parameters that are jointly valid to test the icdf. Adding 2 or 3 rows should be enough.

@michaelraczycki
Copy link
Contributor Author

I have a problem, Uniform distribution test requires some data transformation (uniform.icdf takes in value, lower and upper as parameters, and stats.uniform.ppf expects value, loc, scale= upper - lower) and I can't seem to figure it out. So far I have tried to extract the values given to uniform distribution and compute the needed values for uniform.ppf:
Zrzut ekranu 2023-02-21 o 19 22 24
I must understand something wrong, because the test fails with this message:
Zrzut ekranu 2023-02-21 o 19 23 18

@michaelraczycki
Copy link
Contributor Author

michaelraczycki commented Feb 21, 2023

I also tried to play with the idea of adding a new if-else to numpy_res assignment, in which I could maybe alter what goes to it:
Zrzut ekranu 2023-02-21 o 19 47 03
problem in this approach would be that I can't come up with an idea to check if the passed variable is a reference to specific function. @ricardoV94 any suggestions on how to handle this?

@ricardoV94
Copy link
Member

For the compatibility between PyMC and Scipy parametrizations you can wrap scipy icdf in a lambda function that does the parameter conversion (untested code and parametrization expression):

test_fn=lambda value, lower, upper: stats.uniform.icdf(value, lower, upper-lower)

@michaelraczycki
Copy link
Contributor Author

@ricardoV94 , I've adjusted the uniform icdf to use the new value and parameter checks for icdf, I think we should merge it now so It can be used as a template for contributors with further icdf implementations

@ricardoV94
Copy link
Member

ricardoV94 commented Mar 18, 2023

@michaelraczycki the code still includes the untested icdf for the truncated normal, and it's using the old testing routine, not the new check_icdf introduced in 9ef9a14

@ricardoV94 ricardoV94 changed the title adding icdf functions for distributions Implement icdf for Univariate distribution Mar 18, 2023
….py check_icdf with skip_paradomain_outside_edge_test param
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. Should be squashed merged

@ricardoV94 ricardoV94 merged commit 473c952 into pymc-devs:main Mar 19, 2023
daniel-saunders-phil added a commit to daniel-saunders-phil/pymc that referenced this pull request Apr 6, 2023
daniel-saunders-phil added a commit to daniel-saunders-phil/pymc that referenced this pull request Apr 6, 2023
…#6528)""

This reverts commit 86f36031759620a124ba5b46faf9305d2b160b71.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants