Skip to content

fix: return the limiting density at x = 0 and x = 1 in stats/base/dists/kumaraswamy/pdf and logpdf - #15606

Open
Abhist17 wants to merge 1 commit into
stdlib-js:developfrom
Abhist17:fix/kumaraswamy-pdf-bounds
Open

Abhist17 wants to merge 1 commit into
stdlib-js:developfrom
Abhist17:fix/kumaraswamy-pdf-bounds

Conversation

@Abhist17

Copy link
Copy Markdown
Contributor

Description

What is the purpose of this pull request?

This pull request:

  • makes stats/base/dists/kumaraswamy/pdf and logpdf return the limiting density at the two ends of the support. Both currently return 0 (-Infinity) at x = 0 and x = 1 for all shape parameters.
var kumaraswamy = require( '@stdlib/stats/base/dists/kumaraswamy/pdf' );
var beta = require( '@stdlib/stats/base/dists/beta/pdf' );
var uniform = require( '@stdlib/stats/base/dists/uniform/pdf' );

// Kumaraswamy(1, 1), Beta(1, 1) and Uniform(0, 1) are the same distribution:
uniform( 0.0, 0.0, 1.0 );     // 1
beta( 0.0, 1.0, 1.0 );        // 1
kumaraswamy( 0.0, 1.0, 1.0 ); // 0

// Kumaraswamy(1, b) is Beta(1, b):
beta( 0.0, 1.0, 2.0 );        // 2
kumaraswamy( 0.0, 1.0, 2.0 ); // 0

// Near the boundary the density grows without bound for a < 1:
kumaraswamy( 1.0e-300, 0.5, 2.0 ); // ~1e150
kumaraswamy( 0.0, 0.5, 2.0 );      // 0

The density is a b x^(a-1) (1-x^a)^(b-1). At x = 0 its limit is +Infinity, b or 0 for a less than, equal to or greater than 1. At x = 1 it is +Infinity, a or 0 for b less than, equal to or greater than 1. This PR returns those values, and their logarithms in logpdf, using the same structure as beta/pdf and beta/logpdf. Their READMEs describe the support as (0,1) too, but the code already handles the boundaries this way. Julia's pdf( Kumaraswamy( a, b ), x ) returns the same values (Inf, 2.0, 0.0 at x = 0 for a = 0.5, 1, 2 with b = 2).

Changes:

  • pdf/lib/main.js, pdf/lib/factory.js, logpdf/lib/main.js, logpdf/lib/factory.js, logpdf/src/main.c: add boundary branches, and x < 0 || x > 1 stays 0 / -Infinity. logpdf/manifest.json gains @stdlib/constants/float64/pinf.
  • Tests: the "outside the support" tests asserted pdf( 1.0, 0.5, 1.0 ) === 0 and pdf( 0.0, 0.5, 1.0 ) === 0, but those densities are 0.5 and +Infinity. I moved those two points out of the support tests. There are new tests for both boundaries with each shape parameter below, at and above one, in all five test files.

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

Questions

Any questions for reviewers of this pull request?

The README equations define the density as 0 outside the open interval (0,1), the same as beta/pdf's README. I've left them alone, to match beta. If you'd rather the boundary convention were written down explicitly, I can add a note to both.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

This PR was written primarily by Claude Code. The bug was found by comparing every stats/base/dists function against SciPy on random parameters.


@stdlib-js/reviewers

…e/dists/kumaraswamy/pdf` and `logpdf`

Both returned `0` (`-Infinity`) at either end of the support, whatever
the shape parameters. Return `+Infinity`, `b` (`a` at `x = 1`) or `0`
when the corresponding shape parameter is below, equal to or above one,
matching `stats/base/dists/beta/pdf` and `logpdf`. `Kumaraswamy(1, b)`
is `Beta(1, b)`, and `Kumaraswamy(1, 1)` is `Uniform(0, 1)`, whose `pdf`
returns `1` at `0`.
@Abhist17
Abhist17 requested a review from a team September 27, 2026 23:05
@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. and removed Needs Review A pull request which needs code review. labels Sep 27, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/kumaraswamy/logpdf $\\color{green}385/385$
$\\color{green}+100.00\\%$
$\\color{green}47/47$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}385/385$
$\\color{green}+100.00\\%$
stats/base/dists/kumaraswamy/pdf $\\color{green}283/283$
$\\color{green}+100.00\\%$
$\\color{green}45/45$
$\\color{green}+100.00\\%$
$\\color{green}3/3$
$\\color{green}+100.00\\%$
$\\color{green}283/283$
$\\color{green}+100.00\\%$

The above coverage report was generated for the changes in this PR.

@kgryte

kgryte commented Sep 28, 2026

Copy link
Copy Markdown
Member

@Planeshifter Mind taking a look at this PR?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review A pull request which needs code review. Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants