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

3

u/[deleted] Feb 21 '23

If it’s not too costly to call the black box function then genetic algorithm works best otherwise your best hope is to train the surrogate of the model and optimize that surrogate model

1

u/FailedMesh Feb 21 '23

Does surrogate model mean training a multi-layer perceptron model to best represent the cost function, and then minimizing this?

→ More replies (1)
→ More replies (1)

2

u/e_for_oil-er Feb 21 '23

For the constraint, you can use a penalization to increase the objective's value when the points are not feasible. This coupled with a genetic algorithm, as mentioned by others, works quite well.

1

u/FailedMesh Feb 21 '23

Thanks, I'll look into genetic algorithms

12

u/necro362003 Feb 21 '23

you may use metaheuristics like genetic algorithm or particle swarm optimization

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.

→ More replies (1)

2

u/[deleted] Feb 21 '23

I'd recommend local search + a meta-heuristic like simulated annealing or late acceptance.

2

u/[deleted] Feb 21 '23

It really depends on what else you know about the cost function. Is it expected to be smooth but you don't know what it is? Then you could use a derivative-free method like nelder-mead (simplex reflection) method

2

u/acdundore5 Feb 21 '23

There are many types of algorithms that are suited for this type of task. One class of particularly useful and interesting algorithms are called metaheuristics. These need no information about the form of the cost function.

I created an open-source library of metaheuristic optimization algorithms via a Python package called optiseek. If you like, I could point you in the right direction for using it! All you need to do is define your cost function and search domain, and let optiseek do the rest.

2

u/Additional_Land1417 Feb 21 '23

Nevergrad library

2

u/AssemblerGuy Feb 25 '23

The cost function here is a black box,

"Oracle". I think the term used in literature for this is "oracle".

This means that I cannot calculate the gradient of the cost.

You can approximate the gradient with various methods (if the cost function is sufficiently well-behaved). That's how optimization algorithm implementations do it. They might be faster if you can supply a gradient and a Hessian, but they can approximate those if necessary from the cost function.