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
REF/Design: numdiff, clarify and clean up behavior with 2- or multi-dimensional parameters #7680
related to vectorized scalar param #1783 which will be added in #7287 as separate functions.
Behavior of numdiff approx_fprime and of approx_fprime_cs in case of 2-d params are not well defined, but don't raise in all cases.
Trying to make changes to this in #7287 causes test error with approx_fprime_cs in MarkovSwitching unit tests.
approx_fprime breaks and raises a broadcast error for that type of test case (2-d single row params)
approx_fprime creates diagonal matrix in vectorized scalar param case, so it works. #7287 will remove those cases from link functions.
This should be clarified, and maybe raise an exception for cases that we don't want to handle.
related:
Even when cases work with the implemented numdiff function, it does not necessarily use the correct options.
e.g. My initial change to handle vectorized scalar params, dropped the usage of epsilon scaled by individual params, using a single epsilon instead.
My guess would be that approx_fprime_cs does something similar in some cases where it works.
Reading the notes section of approx_fprime, there is a statement if f returns 2-d, but doesn't say anything about interpretation of 2d params. However, I think it explains the behavior in the 2-d row params case.
If a 2d array is returned
by f (e.g., with a value for each observation), it returns a 3d array
with the Jacobian of each observation with shape xk x nobs x xk. I.e.,
the Jacobian of the first observation would be [:, 0, :]
bug or inconsistency if only one param
bug for SVAR, with workaround in #9302 #8792 possible problem for other models if there is only 1 param
one 2-dim param is ambiguous because it is not clear whether row or column treatment applies.
need to clarify all cases, and which functions handle them
base function f(p)
f: R^k -> R => diff: R^k (standard case for score, sum/mean, no vectorization)
f: R^k -> R^n => diff: R^(n, k), f vectorized by n, p is 1dim, diff is 2d (n, k) (case for score_obs)
f: R -> R => diff: R^n, p is scalar vectorized by n, (case for scalar function diff,
f: R^k -> R => diff: R^(n, k) p and f vectorized by n rows, p is (n, k), f(p) is (n,) (which use case ?)?
... (anything more general ?)
main use cases:
model, loglike and score, score_obs: R^k -> R or f: R^k -> R^n
link, transformation functions: mostly f: R-> R vectorized by nobs
Activity
josef-pkt commentedon Sep 3, 2021
Reading the notes section of approx_fprime, there is a statement if f returns 2-d, but doesn't say anything about interpretation of 2d params. However, I think it explains the behavior in the 2-d row params case.
I don't remember details or use cases for this.
josef-pkt commentedon Jan 5, 2025
bug or inconsistency if only one param
bug for SVAR, with workaround in #9302
#8792 possible problem for other models if there is only 1 param
one 2-dim param is ambiguous because it is not clear whether row or column treatment applies.
need to clarify all cases, and which functions handle them
base function f(p)
main use cases: