2
$\begingroup$

I am looking for a test function that is differentiable since I'd like to test some gradient-based optimization methods. But the function's derivatives (both gradient and hessian) should be very hard (if not impossible) to compute analytically, any example?

(To give a counterexample, a multivariate Rosenbrock function may be an easy example, though it still takes some time for one to compute its derivatives)

$\endgroup$

1 Answer 1

2
$\begingroup$

If $f(x,y)$ then $g(x)=inf_y f(x,y)$ can be smooth. Computing the derivative of the inf requires finding the minimising $y$, which won't have an analytic solution in most cases. Computing the function value also requires optimisation, but you don't specify that the function value should be easy to compute.

I picked a random polynomial that might do the job:

import numpy as np
import matplotlib.pyplot as plt
import scipy.optimize

def f(x,y):
    return (pow(y-x,6) + 2*pow(y-2*x,4) + 3*pow(y+3*x,2) + 2*y + x*x)

def g(x):
    return scipy.optimize.minimize(lambda y: f(x, y), 0).fun
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.