You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ENH: tools numerical derivatives for only part of parameters #8421
We could add a helper function that computes first and second derivatives for only one element of a partition of the parameter space.
We have several applications where we can compute analytical derivatives for part of the parameters, but need numerical derivatives with respect to parameters where we do not have analytical derivatives.
Currently, we either use only numerical derivatives, or hand code it for the special case (example ?).
Main applications
models with extra params, e.g. negative binomial, generalized poisson, more to come
score or conditional moment tests, GMM: derivative of extra moment conditions, or cross-derivative in stacked moment conditions as in treatment effect GMM. (??? *1)
In those cases we have partition params = [known, unknown]
First derivative is easy, we just need to write a wrapper function to keep some parameters fixed.
Second derivatives: more difficult because we also need cross-derivatives, off-diagonal block of Hessian.
In the score_test/cmt/GMM application, we have first derivative of moment conditions instead of second derivative. This requires more vectorization because return of target function may be 2-dim. But in most cases we only need the derivative of the sum or mean of moment conditions for that (like in Hessian case).
*1: This might be different.
We need cross derivatives of extra moment conditions w.r.t. original parameters and derivative of extra moment condition w.r.t. new parameters. We also have a partition of the moment conditions and not just of params.
mask : array or None, optional
If `x` is an array and `mask` is not None, compute the Jacobi matrix only for the
part of the array selected by the mask.
much easier special case, block triangular form with extra moment condition h(a, beta) = a - g(beta)
momcond
h_1(beta) # hessian of model with params beta
h_a(a, beta) = a - g(beta) # extra moment condition that defines a desired (average) effect
d h_1(beta) / d a = 0
d h_a(a, beta) / d a = 1
d h_a(a, beta) / d beta = d g(beta) / d beta
So, we only need the derivative of the effect w.r.t. params, which is the same as what we need for delta method.
Same, if a is a vector of parameter where effects g_k (beta) do not depend on each others parameter,
momconds: h_a_k(a_k, beta) = a_k - g_k(beta) for all k
Activity
josef-pkt commentedon Apr 12, 2023
much easier special case, block triangular form with extra moment condition h(a, beta) = a - g(beta)
momcond
h_1(beta) # hessian of model with params beta
h_a(a, beta) = a - g(beta) # extra moment condition that defines a desired (average) effect
d h_1(beta) / d a = 0
d h_a(a, beta) / d a = 1
d h_a(a, beta) / d beta = d g(beta) / d beta
So, we only need the derivative of the effect w.r.t. params, which is the same as what we need for delta method.
Same, if a is a vector of parameter where effects g_k (beta) do not depend on each others parameter,
momconds: h_a_k(a_k, beta) = a_k - g_k(beta) for all k