Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sense support for all algorithms #9

Open
agerlach opened this issue Jun 1, 2023 · 3 comments
Open

Add sense support for all algorithms #9

agerlach opened this issue Jun 1, 2023 · 3 comments
Labels
good first issue Good for newcomers

Comments

@agerlach
Copy link

agerlach commented Jun 1, 2023

Currently sense is only supported for a subset of algorithms. This breaks the common interface as some solvers solve min vs max. Furthermore, since sense is a kwarg for OptimizationProblem and not solve, the interface and docs give the impression that it is supported for all algorithms.

using Optimization, OptimizationBBO

J(x,p) = x

F = OptimizationFunction(J)
prob = Optimization.OptimizationProblem(F, 0.0; lb = -10, ub =10, sense = MaxSense)
solve(prob, BBO_adaptive_de_rand_1_bin_radiuslimited()).objective # -10.0
@soldasim
Copy link

soldasim commented Sep 23, 2023

Also encountered this issue. The sense kwarg completely breaks some solvers but does so silently without any error.

Consider the following MWE:

using Optimization
using OptimizationOptimJL

obj(x, p) = x[1] + x[2]

lb, ub = [0.,0.], [10.,10.]
x0 = [5.,5.]

# without `sense`
prob = OptimizationProblem(OptimizationFunction(obj, AutoForwardDiff()), x0, nothing; lb, ub)
sol = solve(prob, LBFGS(); x_tol=0.1)
println("no-sense: $(sol.u)")

# with `MinSense`
prob = OptimizationProblem(OptimizationFunction(obj, AutoForwardDiff()), x0, nothing; lb, ub, sense=Optimization.MinSense)
sol = solve(prob, LBFGS(); x_tol=0.1)
println("MinSense: $(sol.u)")

# with `MaxSense`
prob = OptimizationProblem(OptimizationFunction(obj, AutoForwardDiff()), x0, nothing; lb, ub, sense=Optimization.MaxSense)
sol = solve(prob, LBFGS(); x_tol=0.1)
println("MaxSense: $(sol.u)")

This outputs:

julia> 

no-sense: [4.8342920314099165e-9, 4.8342920314099165e-9]
MinSense: [4.8342920314099165e-9, 4.8342920314099165e-9]
MaxSense: [5.0, 5.0]

As you can see the solver does nothing when MaxSense is provided.

@ChrisRackauckas
Copy link
Member

@Vaibhavdixit02 can you prioritize adding a trait to catch this?

@Vaibhavdixit02 Vaibhavdixit02 transferred this issue from SciML/Optimization.jl Feb 23, 2024
@Vaibhavdixit02 Vaibhavdixit02 added the good first issue Good for newcomers label Mar 1, 2024
@Vaibhavdixit02
Copy link
Member

What we'd like to do here is instead of changing it in the solvers handle it in the instantiate_function method and add the negative sign to the objective function evaluation and derivatives when MaxSense is passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants