-
-
Notifications
You must be signed in to change notification settings - Fork 436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Pareto distribution #495
Conversation
Okay, but I'm starting to wonder if we shouldn't discuss #290 before continuing to add more distributions. Is there some specific motivation for this one? |
src/distributions/pareto.rs
Outdated
/// | ||
/// # Panics | ||
/// | ||
/// `scale` and `shape` have to be non-zero and positive. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be worth mentioning common variable names such as k
, x_m
and α
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree and added those to the docs.
As I understand it was primarily about adding new distributions. And no, we don't currently have any framework for choosing whether to add new distributions, this is just an arbitrary point to bring it up (also since you opened #290 originally). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks good to me. Testing is minimal; perhaps a bit more could be done. With a couple of tweaks suggested I think we should merge, in spite of #290.
src/distributions/pareto.rs
Outdated
impl Distribution<f64> for Pareto { | ||
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> f64 { | ||
let u: f64 = rng.sample(OpenClosed01); | ||
self.scale * u.powf(-1.0 / self.shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be equivalent to store -1 / shape
as a field which should speed up sampling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Done.
src/distributions/pareto.rs
Outdated
let d = Pareto::new(1.0, 2.0); | ||
let mut rng = ::test::rng(1); | ||
for _ in 0..1000 { | ||
d.sample(&mut rng); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory the sample must never be less than the shape parameter, so you should either test this or give some small allowance for rounding (but hopefully this isn't necessary).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you meant the scale parameter? Done.
It is as extensive as the testing of |
Looks good. Still missing a benchmark but not required. Any further comments before merging? If not I'll probably merge tomorrow. |
No description provided.