pysolvegn.build_batch_numerical_jacobian#
- build_batch_numerical_jacobian(residual_func, method='central', epsilon=None)[source]#
Build a batched Jacobian function for the batched Gauss-Newton optimization by computing the numerical derivatives of a batched residual function with respect to the parameters using finite differences.
This is the batched counterpart of
pysolvegn.build_numerical_jacobian(): themproblems of the batch are perturbed simultaneously, so the residual function is calledn_parameters + 1times (2 * n_parameterstimes for the"central"method) whatever the number of problems.For the problem \(k\), with the relative step \(h_{k,j} = \epsilon \max(1, |p_{k,j}|)\) (the representable step \((p_{k,j} + h_{k,j}) - p_{k,j}\) is used), the
"central"method computes:\[J_{k,i,j} = \frac{R_{k,i}(p_k + h_{k,j} e_j) - R_{k,i}(p_k - h_{k,j} e_j)}{2 h_{k,j}}\]With the
"forward"method:\[J_{k,i,j} = \frac{R_{k,i}(p_k + h_{k,j} e_j) - R_{k,i}(p_k)}{h_{k,j}}\]With the
"backward"method:\[J_{k,i,j} = \frac{R_{k,i}(p_k) - R_{k,i}(p_k - h_{k,j} e_j)}{h_{k,j}}\]- Parameters:
residual_func (Callable) – A batched function
residual_func(parameters, indices)that computes the residuals. It takes the parameters ofmindependent problems as a 2D array with shape(m, n_parameters)(mis any positive integer) and the indices of these problems in the full batch as a 1D array with shape(m,), and returns a 2D array of residuals with shape(m, n_residuals), where the rowaof the residuals only depends on the rowaof the parameters.method (str, optional (default="central")) – The finite difference method to use for computing the numerical Jacobian. Must be one of “central”, “forward”, or “backward”.
epsilon (Optional[Real], optional (default=None)) – The relative step \(\epsilon\) of the finite differences. If None, the default step of the method is used (see
pysolvegn.build_numerical_jacobian()).
- Returns:
jacobian_func – A batched function
jacobian_func(parameters, indices)that computes the Jacobian matrices of themproblems. It takes the parameters with shape(m, n_parameters)and the indices with shape(m,), and returns a 3D array with shape(m, n_residuals, n_parameters).- Return type:
Callable