Gradient-Free-Optimizers icon indicating copy to clipboard operation
Gradient-Free-Optimizers copied to clipboard

add support to maximize and minimize objective-function

Open SimonBlanke opened this issue 2 years ago • 1 comments

SimonBlanke avatar Mar 27 '23 15:03 SimonBlanke

This new parameter would determine if the optimum the algorithm is searching for is the minimum or maximum of the objective-function. The API for this could look as follows:

import numpy as np
from gradient_free_optimizers import RandomSearchOptimizer


def parabola_function(para):
    loss = para["x"] * para["x"]
    return -loss


search_space = {"x": np.arange(-10, 10, 0.1)}

opt = RandomSearchOptimizer(search_space, optimum="minimum")
opt.search(parabola_function, n_iter=100000)

opt = RandomSearchOptimizer(search_space, optimum="maximum")
opt.search(parabola_function, n_iter=100000)

SimonBlanke avatar May 29 '23 08:05 SimonBlanke