hahnec / torchimize

numerical optimization in pytorch
https://hahnec.github.io/torchimize/
GNU General Public License v3.0
130 stars 7 forks source link

Numerical jacobian #3

Closed pkienzle closed 8 months ago

pkienzle commented 1 year ago

Comment out the the jacobian function input from the parallel fitter, e.g., here:

https://github.com/hahnec/torchimize/blob/2ccbec4e68f41c34bb7d242ff4848d26d72a9765/tests/unit_test_parallel.py#L234

and the test fails with:

======================================================================
ERROR: test_lma_emg_conditions (__main__.ParallelOptimizationTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython-input-59-7536f068804a>", line 215, in test_lma_emg_conditions
    coeffs = lsq_lma_parallel(
  File "/usr/local/lib/python3.10/dist-packages/torchimize/functions/parallel/lma_fun_parallel.py", line 95, in lsq_lma_parallel
    p, f, g, H = newton_step_parallel(p, fun, jac_fun, wvec)
  File "/usr/local/lib/python3.10/dist-packages/torchimize/functions/parallel/newton_parallel.py", line 40, in newton_step_parallel
    gc = torch.einsum('bcnp,bcnp->bcp', j, f[..., None])
  File "/usr/local/lib/python3.10/dist-packages/torch/functional.py", line 378, in einsum
    return _VF.einsum(equation, operands)  # type: ignore[attr-defined]
RuntimeError: einsum(): the number of subscripts in the equation (4) does not match the number of dimensions (5) for operand 0 and no ellipsis was given

Version 0.0.14 installed from pypi using pip

hahnec commented 8 months ago

I noticed that a batched jacobian was required to get the numerical approach working. This functionality is now featured with version pip install torchimize >= 0.0.15.