statrs-dev / statrs

Statistical computation library for Rust

Home Page:https://docs.rs/statrs/latest/statrs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is statrs::distribution::Laplace correct?

vi opened this issue · comments

Assuming it is this Laplace distribution, generated samples look strangely distributed:

q

Wikipedia shows symmetric density function, but all values generated by statrs::distribution::Laplace are positibe (assuming zero location parameter).

Formula used in the code reuses uniform float value both as sign and as exponential distribution generator, but actually has no way to ever generate negative values.

Looks like there's a bug here

Should be

self.location - self.scale * x.signum() * (1.0 - 2.0 * x.abs()).ln()

@boxtown Are you going to submit a pull request for this?