SimonBlanke / Gradient-Free-Optimizers

Simple and reliable optimization with local, global, population-based and sequential techniques in numerical discrete search spaces.
https://simonblanke.github.io/gradient-free-optimizers-documentation
MIT License
1.21k stars 84 forks source link

add support to maximize and minimize objective-function #39

Open SimonBlanke opened 1 year ago

SimonBlanke commented 1 year ago

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)