Skip to content

Weibull returns NaN from pdf/cdf/sf/ln_pdf for finite shape and scale #465

Description

@DRMacIver
use statrs::distribution::{Continuous, ContinuousCDF, Weibull};

fn main() {
    for (shape, scale) in [(2000.0, 0.5), (1e6, 0.99), (1500.0, 0.9)] {
        let w = Weibull::new(shape, scale).unwrap();
        println!("Weibull({shape}, {scale}): pdf = {}, cdf = {}, sf = {}, ln_pdf = {}",
            w.pdf(0.4), w.cdf(0.4), w.sf(0.4), w.ln_pdf(0.4));
    }
}

Output:

Weibull(2000, 0.5): pdf = NaN, cdf = NaN, sf = NaN, ln_pdf = NaN
Weibull(1000000, 0.99): pdf = NaN, cdf = NaN, sf = NaN, ln_pdf = NaN
Weibull(1500, 0.9): pdf = 0, cdf = 0, sf = 1, ln_pdf = -1208.1658132055286

new accepts all three. A density is never NaN, and Weibull(1500, 0.9) shows the neighbouring case coming back finite.

Possibly a duplicate of #310, which describes the same NaN in the same expression. Filing separately because #310 is scoped to infinite parameters throughout — its repro passes f64::INFINITY and the discussion turns on rejecting those at construction, which would leave this case, where every parameter and the argument are finite. Happy for it to be folded into #310.

Tested on statrs 0.19.1 and current main (50fcf4d).

(This was another bug found using hegel.)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions