What is the simplest way to minimize f(x) with |x|=1 where x is a vector ? (I know the gradient of f)
I’ve checked the example on Using Equality and Inequality Constraints · Optimization.jl but the solution calls AmplNLWriter.jl.
Given that the constraint |x|=1 is a super basic one, is there a more straightforward way to solve the problem just with Optimization.jl ?
You can just eliminate one of the values. For example, z = sqrt(1 - x^2 + y^2)
, and then only optimize the other values.
Or maybe define a non-constrained optimization problem, with a similar minimum. Something along the lines of:
function g(x)
r = norm(x)
factor = exp(-(r-1)^2)
return f(x) / factor
end
The idea is that x
with |x| = 1
is still a minimizer of g(x)
as factor = 1
there and smaller everywhere else.
You could just solve the unconstrained problem
Another option is to use spherical coordinates:
where
This enforces \|\boldsymbol{x}\| = 1, so you can write the optimization problem in terms of \phi_1, \ldots, \phi_{n - 1} and solve as an unconstrained problem.
Equations adapted from n-sphere - Wikipedia.
If you’re talking about the Euclidean norm, then the sphere is a manifold and you can use Manopt.jl to work directly on that manifold.