Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "julia" # See documentation for possible values
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
16 changes: 0 additions & 16 deletions .github/workflows/CompatHelper.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- '1.10'
- '1'
- 'nightly'
os:
Expand Down
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ version = "0.0.1-DEV"
AutoGrad = "6710c13c-97f1-543f-91c5-74e8f7d95b35"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
MultivariateBases = "be282fd4-ad43-11e9-1d11-8bd9d7e43378"
MultivariatePolynomials = "102ac46a-7ee4-5c85-9060-abc95bfdeaa3"
NLopt = "76087f3c-5699-56af-9a33-bf431cd00edd"
SemialgebraicSets = "8e049039-38e8-557d-ae3a-bc521ccf6204"
Expand All @@ -16,9 +17,10 @@ TrigPolys = "bbdedc48-cb31-4a37-9fe3-b015aecc8dd3"
[compat]
AutoGrad = "1"
MathOptInterface = "1"
MultivariateBases = "0.3"
MultivariatePolynomials = "0.5"
NLopt = "1"
SemialgebraicSets = "0.3"
SumOfSquares = "0.7"
SumOfSquares = "0.8"
TrigPolys = "0.1"
julia = "1.6"
julia = "1.10"
10 changes: 5 additions & 5 deletions src/BMSOS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function fgradfft(U::AbstractMatrix, p::TrigPolys.TrigPoly; mapfn = Base.map)
uB = mapfn(TrigPolys.evaluate, eachrow(Up))
d = sum(u .^ 2 for u in uB) - TrigPolys.evaluate(p)
g = reduce(hcat, mapfn(u -> TrigPolys.evaluateT(u .* d), uB))'
return [g[:, 1:xs+1] g[:, 2*xs+2:3*xs+1]]
return [g[:, 1:(xs+1)] g[:, (2*xs+2):(3*xs+1)]]
end

"""
Expand Down Expand Up @@ -49,7 +49,7 @@ function value_and_gradient!(
uB = mapfn(TrigPolys.evaluate, eachrow(Up))
d = sum(u .^ 2 for u in uB) - TrigPolys.evaluate(p)
g = reduce(hcat, mapfn(u -> TrigPolys.evaluateT(u .* d), uB))'
grad[:] = reshape([g[:, 1:xs+1] g[:, 2*xs+2:3*xs+1]], :)
grad[:] = reshape([g[:, 1:(xs+1)] g[:, (2*xs+2):(3*xs+1)]], :)
return sum(d .^ 2)
end

Expand Down Expand Up @@ -86,7 +86,7 @@ function get_Up(U::AbstractArray, p::TrigPolys.TrigPoly)
# FIXME why not `2 * xs + 2` ?
xn = 2 * xs + 1
@assert xn == n "Inconsistent matrix dimension"
Up = [U[:, 1:xs+1] zeros(r, xs) U[:, xs+2:xn] zeros(r, xs)]
Up = [U[:, 1:(xs+1)] zeros(r, xs) U[:, (xs+2):xn] zeros(r, xs)]
return r, xs, xn, Up
end

Expand Down Expand Up @@ -171,7 +171,7 @@ function sos_opt(
nvars = rank * xn + 1

function f(x)
slices = [x[xn*(i-1)+1:xn*i] for i in 1:rank]
slices = [x[(xn*(i-1)+1):(xn*i)] for i in 1:rank]
gam = last(x)
uB = sum([evaluate(pad_to(u, p.n)) .^ 2 for u in slices])
return sum((uB - evaluate(p) .+ gam) .^ 2)
Expand Down Expand Up @@ -203,7 +203,7 @@ function sos_opt(
@time (minf, minx, ret) = NLopt.optimize(opt, xinit)
@show ret

Uopt = reshape(minx[1:nvars-1], rank, xn)
Uopt = reshape(minx[1:(nvars-1)], rank, xn)
xopt = last(minx)
return f, fgrad, fvals, xvals, Uopt, xopt, ret, minx
end
Expand Down
4 changes: 3 additions & 1 deletion src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import MultivariatePolynomials as MP
import MultivariateBases as MB
import SemialgebraicSets
import MathOptInterface as MOI
import SumOfSquares
Expand Down Expand Up @@ -57,7 +58,8 @@ function MOI.add_constraint(
error("Nonconstant polynomials are not supported yet!")
end
# FIXME don't ignore `set.certificate`
optimizer.poly = MP.polynomial(func.constants, set.monomials)
optimizer.poly =
MP.polynomial(func.constants, MB.keys_as_monomials(set.basis))
return MOI.ConstraintIndex{typeof(func),typeof(set)}(0)
end

Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function test_decomp(n = 20)
B = reduce(hcat, [TrigPolys.basis(p.n, xi) for xi in samples])
ps = reshape(p.(samples), 1, s)
function f(U)
Up = [U[:, 1:xs+1] zeros(r, xs) U[:, xs+2:xn] zeros(r, xs)]
Up = [U[:, 1:(xs+1)] zeros(r, xs) U[:, (xs+2):xn] zeros(r, xs)]
return sum((sum((Up * B) .^ 2, dims = 1) - ps) .^ 2)
end
#f(U) = sum((sum((U*B).^2, dims=1)-ps).^2)
Expand Down
Loading