How to start
First we need to install a SDP solver, e.g. CSDP:
] add CSDPThen we set the SDP solver to be used in the Moment programs:
using MomentPolynomialOpt
using CSDP; mpo_optimizer(CSDP.Optimizer)See mpo_optimizer.
Now we solve a moment optimization program
using DynamicPolynomials # for multivariate polynomials
X = @polyvar x y
f = x*y+y^3 # objective function
g = 1-x^2-y^2 # sign constraint g>=0
v, M = maximize(f, [], [g], X, 3 )We specify the variables array X, the order of the relaxation $\ell=3$, which means that the moments of order $\le 2\ell$ are used. See optimize, maximize, minimize.
To get the optimal measure as a weighted sum of Diracs:
w, Xi = get_measure(M)We obtain
([0.9999999991407329], [0.30029543782848245; 0.9538462396080524;;])that is, the Dirac measure at the point $[0.30029543782848245, 0.9538462396080524]$ with weight $\approx 1$. See get_measure.
The corresponding optimal pseudo-moment sequence is given as a series:
get_series(M)
1.0 + 0.953846dy + 0.300295dx + 0.909822dy^2 + 0.286435dx*dy + ... + 0.000733dx^6The coefficient of the monomial $\mathbf{dx}^\alpha$ in this series is the pseudo-moment of the optimal linear functional. See get_series.
Let us add an equality constraint, e.g. the diagonal $x-y=0$, and another sign constraint $x\ge 0$:
v, M = maximize(f, [x-y], [g, x], X, 3 )
Xi = get_optimizers(M)We get the single point on the diagonal intersected with the half unit disk such that f is maximal:
2×1 Matrix{Float64}:
0.7071067810309548
0.7071067812499313See get_optimizers.