Skip to content

[BUG] reject non-positive sigma/scale in Normal and Laplace#960

Open
Ayushigitgithub wants to merge 2 commits intosktime:mainfrom
Ayushigitgithub:bugfix-nonpositive-scale-959
Open

[BUG] reject non-positive sigma/scale in Normal and Laplace#960
Ayushigitgithub wants to merge 2 commits intosktime:mainfrom
Ayushigitgithub:bugfix-nonpositive-scale-959

Conversation

@Ayushigitgithub
Copy link
Copy Markdown

Reference Issues/PRs

Closes #959

What does this implement/fix? Explain your changes.

Adds constructor-level validation for non-positive scale parameters in Normal and Laplace.

Changes:

  • Normal now raises ValueError when sigma <= 0
  • Laplace now raises ValueError when scale <= 0
  • adds tests for:
    • Normal(mu=0, sigma=-1)
    • Normal(mu=0, sigma=0)
    • Laplace(mu=0, scale=-1)
    • Laplace(mu=0, scale=0)

Why is this needed?
Normal(mu=0, sigma=-1).pdf(0) previously returned -0.3989422804014327
Laplace(mu=0, scale=-1).pdf(0) previously returned -0.5

A pdf should never be negative, so these invalid parameters should be rejected early instead of silently producing mathematically invalid outputs.

Does your contribution introduce a new dependency? If yes, which one?

No

What should a reviewer concentrate their feedback on?

Constructor-level validation for non-positive sigma / scale in Normal and Laplace, and whether the added regression tests in test_proba_basic.py are the right place and scope for this fix.

Did you add any tests for the change?

Yes.

Added tests for:

Normal(mu=0, sigma=-1)
Normal(mu=0, sigma=0)
Laplace(mu=0, scale=-1)
Laplace(mu=0, scale=0)

These verify that non-positive scale parameters are rejected with ValueError.

Any other comments?

Closes #959

PR checklist

For all contributions
  • I've added myself to the list of contributors with any new badges I've earned :-)
  • The PR title starts with either [ENH], [MNT], [DOC], or [BUG].

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.

[BUG]Normal and Laplace accept non-positive sigma/scale and return invalid pdf values

1 participant