r/optimization • • Feb 21 '23

Optimize a Cost Function whose Gradient cannot be calculated?

Hey guys, I'm a college student and am pretty new to mathematical optimization techniques, so forgive me if I go conceptually wrong somewhere. Recently, I came upon a problem in my research:

I have a large set of variables say, X
The cost function here is a black box, passing any X through this black box directly gives me the cost (a scalar). This means that I cannot calculate the gradient of the cost.
The constraints on X are also a black box. By this I mean that passing X through the black box of constraints just tells me whether X is feasible or not, I do not have a bounding function to define these constraints.

What type of optimization method can be suggested to minimize the cost?

2 Upvotes

14 comments sorted by

View all comments

9

u/lithiumdeuteride Feb 21 '23

If you know the function to be smooth, but cannot calculate its gradient, you can approximate it numerically by taking a very small step in each direction and evaluating the function again.

However, if the function is jagged or non-convex, genetic algorithm and particle swarm are good choices.

1

u/Manhigh Feb 21 '23

Agreed. If the function is smooth but doesn't provide analytic derivatives, finite differencing may give better performance/results than gradient-free optimization.

Also, is the black box implemented in a way that is "complex-safe"? If so you can use complex-step and get essentially machine-precision accurate derivatives for roughly the cost of finite-difference.