Updated the stopping criteria in igammac_cf_impl.

Previously, when computing the derivative, it used a relative error threshold. Now it uses an absolute error threshold. The behavior for computing the value is unchanged. This makes more sense since we do not expect the derivative to often be close to zero. This change makes the derivatives about 30% faster across the board. The error for the igamma_der_a is almost unchanged, while for gamma_sample_der_alpha it is a bit worse for float32 and unchanged for float64.
This commit is contained in:
Michael Figurnov 2018-06-07 12:03:58 +01:00
parent 4bd158fa37
commit 5172a32849

View File

@ -605,8 +605,7 @@ struct igammac_cf_impl {
break;
}
} else {
if (numext::abs(dans_da - dans_da_prev) <=
machep * numext::abs(dans_da)) {
if (numext::abs(dans_da - dans_da_prev) <= machep) {
break;
}
}
@ -955,8 +954,8 @@ struct igamma_der_a_impl : igamma_generic_impl<Scalar, DERIVATIVE> {
* Accuracy estimation. For each a in [10^-2, 10^-1...10^3] we sample
* 50 Gamma random variables x ~ Gamma(x | a, 1), a total of 300 points.
* The ground truth is computed by mpmath. Mean absolute error:
* float: 6.27648e-07
* double: 4.60455e-12
* float: 6.17992e-07
* double: 4.60453e-12
*
* Reference:
* R. Moore. "Algorithm AS 187: Derivatives of the incomplete gamma
@ -1000,8 +999,8 @@ struct gamma_sample_der_alpha_impl
* Accuracy estimation. For each alpha in [10^-2, 10^-1...10^3] we sample
* 50 Gamma random variables sample ~ Gamma(sample | alpha, 1), a total of 300
* points. The ground truth is computed by mpmath. Mean absolute error:
* float: 1.0993e-06
* double: 1.47631e-12
* float: 2.1686e-06
* double: 1.4774e-12
*
* Reference:
* M. Figurnov, S. Mohamed, A. Mnih "Implicit Reparameterization Gradients".