Minimize f(x) with |x|=1

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.

4 Likes

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.

1 Like

You could just solve the unconstrained problem

\min_{y\in \mathbb{R}^n} f(y / \Vert y \Vert)
10 Likes

Another option is to use spherical coordinates:

\begin{aligned} x_1 &= \cos(\phi_1) \\ x_2 &= \sin(\phi_1) \cos(\phi_2) \\ &\vdots \\ x_{n - 1} &= \sin(\phi_1) \cdots \sin(\phi_{n - 2}) \cos(\phi_{n - 1}) \\ x_n &= \sin(\phi_1) \cdots \sin(\phi_{n - 2}) \sin(\phi_{n - 1}) \end{aligned}

where

\begin{aligned} \phi_1, \ldots, \phi_{n - 2} &\in [0, \pi] \\ \phi_{n - 1} &\in [0, 2\pi) \end{aligned}

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.

2 Likes

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.

6 Likes