Skip to content

fix: return the limiting density at x = 0 in stats/base/dists/log-logistic/pdf - #15608

Open
Abhist17 wants to merge 1 commit into
stdlib-js:developfrom
Abhist17:fix/log-logistic-pdf-zero
Open

Abhist17 wants to merge 1 commit into
stdlib-js:developfrom
Abhist17:fix/log-logistic-pdf-zero

Conversation

@Abhist17

Copy link
Copy Markdown
Contributor

Description

What is the purpose of this pull request?

This pull request:

  • makes stats/base/dists/log-logistic/pdf (JS, factory, and C) return the limiting density at x = 0 rather than 0.
var pdf = require( '@stdlib/stats/base/dists/log-logistic/pdf' );

// The standard log-logistic has density 1/(1+x)^2, which is 1 at x = 0:
pdf( 0.0, 1.0, 1.0 );   // 0 (and the README/JSDoc example says `returns 0.0`)

// For beta < 1 the density is unbounded near 0:
pdf( 1.0e-10, 1.0, 0.5 ); // ~5e4
pdf( 0.0, 1.0, 0.5 );     // 0

The density is (beta/alpha) (x/alpha)^(beta-1) / (1 + (x/alpha)^beta)^2. At x = 0 its limit is +Infinity for beta < 1, 1/alpha for beta = 1, and 0 for beta > 1. SciPy's fisk.pdf( 0, c ) returns those values (inf, 1, 0 for c = 0.5, 1, 2 with unit scale).

Changes:

  • lib/main.js, lib/factory.js, src/main.c: x < 0 still returns 0, and x = 0 now returns +Infinity, 1/alpha or 0. manifest.json gains @stdlib/constants/float64/pinf.
  • The documented example pdf( 0.0, 1.0, 1.0 ) now says 1.0, in lib/main.js, lib/native.js, docs/types/index.d.ts and docs/repl.txt.
  • Tests: the "x <= 0 returns 0" tests asserted pdf( 0.0, 1.0, 1.0 ) === 0. That point is removed and they now say x < 0. There is a new x = 0 test with beta below, at and above one in test.pdf.js, test.factory.js and test.native.js.

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?

No.

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

…logistic/pdf`

`x <= 0` returned `0`, but the density
`(beta/alpha) (x/alpha)^(beta-1) / (1+(x/alpha)^beta)^2` tends to
`+Infinity`, `1/alpha`, or `0` at `x = 0` for `beta` less than, equal to,
or greater than one. The documented example `pdf( 0.0, 1.0, 1.0 )` is the
standard log-logistic, whose density `1/(1+x)^2` is `1` at `0`.
@Abhist17
Abhist17 requested a review from a team September 27, 2026 23:09
@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. 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/log-logistic/pdf $\\color{green}324/324$
$\\color{green}+100.00\\%$
$\\color{green}37/37$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}324/324$
$\\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 one?

@kgryte
kgryte requested a review from Planeshifter September 28, 2026 01:52

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