Closed hjalmarlucius closed 2 years ago
If I get you right, you are proposing the classical Gradient Descent method (first-order) whereas the "lsq_gna" function is the Gauss-Newton method using a second order term. I am thinking of adding more optimization algorithms over time such as Newton-Raphson. Thanks for the suggestion anyways.
My proposal should give you the very same result as what you have already, just with two less matmuls. torch.linalg.lstsq
solves using the pseudoinverse so you don't need to calculate both sides with J.T
first. This doesn't work for the LM computation however since lstsq
can't apply Tikonov regularization.
https://github.com/hahnec/torchimize/blob/e0dcfc6eb8a8c86133dbdf17f8fbd35633a25d16/torchimize/functions/gna_fun.py#L67
Replace line with
h = -l * torch.linalg.lstsq(j, f, rcond=None, driver=None)[0]
and skip the other matmuls and transposes.