-
Notifications
You must be signed in to change notification settings - Fork 432
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
Revise pert #1452
Revise pert #1452
Conversation
The division requiring a special case factors out, and code factors down neatly. See also mc2d R package.
Clippy says:
I don't think |
@newpavlov thoughts on Clippy error (see last comment)? |
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.
Looks good, I think the Clippy warning can be allowed in this case. One tiny suggestion: this is a micro-optimization but we could use shape: Option<F>
in PertBuilder
so that we have lazy evaluation of the default value via self.shape.unwrap_or_else(|| F::from(4.).unwrap());
. But it is not immediately clear to me where that call should happen - the shape is needed in both with_mean
and with_mode
, and unwrapping the value twice is a bit unclean. So it might be more trouble than its worth. I'll leave it up to you!
Personally, I agree with the lint. I expect for |
That expression should optimise down to a constant.
I sincerely hope not. The builder is supposed to make The alternatives are renaming
|
I am not familiar with the most commonly used way to construct |
No; |
Good point, didn't even consider that. |
Then we need at least two methods |
We need precisely the four methods I listed above. We can just use those instead of a builder pattern if preferred. |
Opting to exceptionally allow this builder-constructor (approved by @MichaelOwenDyer). Renaming to |
CHANGELOG.md
entry#1311 show-cases an issue with our PERT implementation. The simplest fix I found was to also use the special-case of
v
when2*mode - min - max == 0
. A better fix can be found in the R package mc2d, duplicated here.Calculations are straightforward:
As the R source shows, we can easily calculate
mode
frommean
. Since our argument order (min, max, mode
) is already unusual, I replaced the constructor with a builder pattern.