Skip to content

[ENH] exact _log_pdf for Uniform distribution#784

Merged
fkiraly merged 1 commit into
sktime:mainfrom
Ashish-Kumar-Dash:log_pdf_implementation
Mar 6, 2026
Merged

[ENH] exact _log_pdf for Uniform distribution#784
fkiraly merged 1 commit into
sktime:mainfrom
Ashish-Kumar-Dash:log_pdf_implementation

Conversation

@Ashish-Kumar-Dash
Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Fixes #782

What does this implement/fix? Explain your changes.

Adds the missing _log_pdf method to the Uniform distribution. The class already declared "log_pdf" in its capabilities:exact tag but never implemented the method, causing the base class fallback (np.log(self.pdf(x))) to be used at runtime. This fallback is numerically unstable for out-of-bounds points (log(0) triggers numpy warnings) and contradicts the exact tag.

The new implementation directly computes:

  • -np.log(upper - lower) for in-bounds points
  • -np.inf for out-of-bounds points

using np.where, which is both exact and numerically clean.

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

No.

What should a reviewer concentrate their feedback on?

The _log_pdf implementation in uniform.py — single method addition following the same pattern as Laplace._log_pdf and Normal._log_pdf.

Did you add any tests for the change?

No new tests were added. The existing test_log_pdf_and_pdf test in test_all_distrs.py already validates consistency between pdf and log_pdf for all distributions, including Uniform. All 97 existing Uniform tests pass.

Any other comments?

This is a small, low-risk change — one method addition (~18 lines including docstring) with no changes to existing logic.

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]. [ENH] - adding or improving code.

@Ashish-Kumar-Dash
Copy link
Copy Markdown
Contributor Author

Ashish-Kumar-Dash commented Mar 4, 2026

Hey @fkiraly @felipeangelimvieira
I had raised the PR for #782 previously than the other contributor who worked on same issue(with AI overuse), yet my PR didn't get reviewed earlier than him and his PR was approved earlier than mine. Can you let me know why? It's a bit disappointing to see, even after my previous contributions...
Thanks

@arnavk23
Copy link
Copy Markdown
Contributor

arnavk23 commented Mar 5, 2026

Hi @Ashish-Kumar-Dash, I recommend working on further issues than waiting for this. Also the reason I found was that the change was better explained and written in a way that follows skpro more closely than yours. Rather than keeping this pr active and increasing review load on reviewer, I would close this pr and look for issues under good first issues or enhancement. Good luck for your future prs.

@Ashish-Kumar-Dash
Copy link
Copy Markdown
Contributor Author

Hey @arnavk23 ,
My comment was due to the concerns I had towards the behaviour of some contributors which are against the spirit of open source.
Nevertheless, looking forward to contributing and gaining more such experience. Thanks for replying!

@fkiraly fkiraly changed the title [ENH] add _log_pdf implementation to Uniform distribution [ENH] exact _log_pdf for Uniform distribution Mar 5, 2026
@fkiraly fkiraly added enhancement module:probability&simulation probability distributions and simulators labels Mar 5, 2026
@fkiraly
Copy link
Copy Markdown
Collaborator

fkiraly commented Mar 5, 2026

I accidentally reviewed #787 which is a copy of this. Instead, this PR should be merged.

@fkiraly fkiraly reopened this Mar 5, 2026
@fkiraly
Copy link
Copy Markdown
Collaborator

fkiraly commented Mar 5, 2026

FYI, @arnavk23 is not a maintainer. Please ignore what he said.

Copy link
Copy Markdown
Collaborator

@fkiraly fkiraly left a comment

Choose a reason for hiding this comment

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

Sorry for the mixup. Thanks for the contribution, and welcome to sktime / skpro!

@Ashish-Kumar-Dash
Copy link
Copy Markdown
Contributor Author

thanks for the acknowledgement and prompt response!

@arnavk23
Copy link
Copy Markdown
Contributor

arnavk23 commented Mar 6, 2026

I also apologise for the mixup on this issue and pr. I think I was a bit premature in my understanding of the changes made in the two prs.

@fkiraly fkiraly merged commit 5bd64c0 into sktime:main Mar 6, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement module:probability&simulation probability distributions and simulators

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENH] add _log_pdf implementation to Uniform distribution

3 participants