rfeinman / pytorch-minimize

Newton and Quasi-Newton optimization with PyTorch
https://pytorch-minimize.readthedocs.io
MIT License
292 stars 34 forks source link

Passing extra args to the objective function #12

Closed richinex closed 2 years ago

richinex commented 2 years ago

Is there a way to pass in extra arguments to the objective function like we have in scipy with the keyword argument args?

rfeinman commented 2 years ago

Hi @richinex

For simplicity of the source code I chose to leave this out because the same behavior is easily obtained using lambda functions and/or functools.partial.

For example

minimize(func, x0, args=(3,))

is equivalent to

minimize(lambda x: func(x, 3), x0)
richinex commented 2 years ago

Ah yes I got it. Gracias.