-
Notifications
You must be signed in to change notification settings - Fork 85
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
Fix inverse_cdf for Gamma #227
Conversation
src/distribution/gamma.rs
Outdated
@@ -146,6 +147,51 @@ impl ContinuousCDF<f64, f64> for Gamma { | |||
gamma::gamma_ur(self.shape, x * self.rate) | |||
} | |||
} | |||
|
|||
fn inverse_cdf(&self, p: f64) -> f64 { | |||
const MAX_ITERS: (u16, u16) = (8, 4); |
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.
Is there a special reason for defining the number of iterations like this? It's probably more natural to just
for _ in 0..8 {
since the complexity is pretty low
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 thought,
8 and 4 sound like nice numbers, what does that give me. 8 bisection is 2 digits in
$p$ and NR is quadratic convergence, so 4 gives 16 digits, lucky me. Hmm, it's helpful to name things, soconst
it is.
Then I thought,
I don't want to name two close but separate things, tuple it is.
I.e. I would be fine changing it to literal.
However, since my attention is on it, I think I might instead do the initial bracketing a little differently and try some math to back up the number of iterations I select.
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 see. It's not a problem either way, I just wanted to know why you used that const tuple there.
9041a98
to
f4a85d1
Compare
…nverse_cdf uses bisection prior to NR search
f4a85d1
to
cc96883
Compare
Since it works and I've not already reviewed how to make it "better" I don't think I will for now. If we get a handle on provided or emitting precisions then I think property testing shrinking could use some of that precision information to help find larger parameter space with correct behavior. |
Don't think there's a closed form expression for inverting the CDF, so this improves on the bisection approach with a few iterations of Newton-Raphson since we have
pdf
also adds tests