statrs-dev / statrs

Statistical computation library for Rust
https://docs.rs/statrs/latest/statrs/
MIT License
582 stars 83 forks source link

Is statrs::distribution::Laplace correct? #150

Closed vi closed 3 years ago

vi commented 3 years ago

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.

boxtown commented 3 years ago

Looks like there's a bug here

Should be

self.location - self.scale * x.signum() * (1.0 - 2.0 * x.abs()).ln()
vi commented 3 years ago

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