Skip to content

added icdf for asymmetric laplace distribution #7141

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

Closed
wants to merge 9 commits into from
Closed

added icdf for asymmetric laplace distribution #7141

wants to merge 9 commits into from

Conversation

ParamThakkar123
Copy link

@ParamThakkar123 ParamThakkar123 commented Feb 6, 2024

Description

Added icdf function for Asymmetric Laplace distribution

Related Issue

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

📚 Documentation preview 📚: https://pymc--7141.org.readthedocs.build/en/7141/

@ParamThakkar123
Copy link
Author

@larryshamalama please take a look at my pull request

@ParamThakkar123
Copy link
Author

Are there any changes needed to be done ?

Copy link

codecov bot commented Feb 6, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (7bb2ccd) 92.21% compared to head (17338f6) 71.34%.
Report is 31 commits behind head on main.

❗ Current head 17338f6 differs from pull request most recent head bb312a8. Consider uploading reports for the commit bb312a8 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #7141       +/-   ##
===========================================
- Coverage   92.21%   71.34%   -20.87%     
===========================================
  Files         101      101               
  Lines       16912    16967       +55     
===========================================
- Hits        15595    12105     -3490     
- Misses       1317     4862     +3545     
Files Coverage Δ
pymc/distributions/continuous.py 64.36% <50.00%> (-33.43%) ⬇️

... and 82 files with indirect coverage changes

Copy link
Member

@larryshamalama larryshamalama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ParamThakkar123, thanks for the PR. Two main comments:

@@ -1642,6 +1642,15 @@ def logp(value, b, kappa, mu):
msg="b > 0, kappa > 0",
)

def icdf(p, mu, b, kappa):
if b <= 0:
raise ValueError("Scale Parameter sigma must be positive")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's sigma?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry. Actually the resource from where I was referring the icdf equation, there they used sigma instead of b. I wrote it out of mistake. I will correct that one and change it to b

@@ -1642,6 +1642,15 @@ def logp(value, b, kappa, mu):
msg="b > 0, kappa > 0",
)

def icdf(p, mu, b, kappa):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def icdf(p, mu, b, kappa):
def icdf(value, b, kappa, mu):

To keep consistent with the signatures of other icdf methods and the signatures of methods under this class

@ParamThakkar123
Copy link
Author

@larryshamalama I made the changes.

@larryshamalama
Copy link
Member

Have you checked if the test passes locally? That would be an indication, good or bad, if you are on the right track

raise ValueError("Scale Parameter b must be positive")
if value <= 0.5:
res = mu - (b / kappa) * pt.log(2 * value)
if value > 0.5:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, comparisons need to be done using PyTensor operations

Again, there may be other edits that need to be incorporated, but a robust way to go about this is to check via a unit test, hence the emphasis for testing

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@larryshamalama I changed the comparisons to Pytensor Operations

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.

Can't use Python if statements with TensorVariables

@ParamThakkar123
Copy link
Author

@ricardoV94 I changed the if else conditions in python to pytensor condition

Copy link
Member

@larryshamalama larryshamalama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you investigated if any of this works?

pt.le(value, 0.5),
lambda: mu - (b / kappa) * pt.log(2 * value),
lambda: mu + (b / kappa) * pt.log(2 * (1 - value))
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why lambda functions here...?

pm.AsymmetricLaplace,
{"b": Rplus, "kappa": Rplus, "mu": R},
lambda q, kappa, mu, b: st.laplace_asymmetric.ppf(q, kappa, mu, b)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked if this test pass?

@ricardoV94 ricardoV94 closed this Mar 22, 2024
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