Skip to content

Commit

Permalink
Add zero_basis (#377)
Browse files Browse the repository at this point in the history
* Add zero_basis

* Fix format
  • Loading branch information
blegat authored Jul 9, 2024
1 parent e4715c6 commit 1f7a718
Show file tree
Hide file tree
Showing 17 changed files with 226 additions and 106 deletions.
2 changes: 1 addition & 1 deletion docs/src/tutorials/Extension/certificate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ model = SOSModel(solver)
@variable(model, α)
@objective(model, Max, α)
basis = MB.FullBasis{MB.Monomial,typeof(x * y)}()
ideal_certificate = SOSC.Newton(SOSCone(), basis, tuple())
ideal_certificate = SOSC.Newton(SOSCone(), basis, basis, tuple())
certificate = Schmüdgen(ideal_certificate, SOSCone(), basis, maxdegree(p))
@constraint(model, c, p >= α, domain = S, certificate = certificate)
optimize!(model)
Expand Down
6 changes: 3 additions & 3 deletions src/Bridges/Constraint/sos_polynomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function MOI.Bridges.Constraint.bridge_constraint(
gram_bases = [gram_basis]
weights = [MB.constant_algebra_element(typeof(SA.basis(poly)), T)]
flat_gram_bases, flat_weights, flat_indices = _flatten(gram_bases, weights)
new_basis = SOS.Certificate.reduced_basis(
new_basis = SOS.Certificate.zero_basis(
set.certificate,
MB.explicit_basis(poly),
domain,
Expand Down Expand Up @@ -117,14 +117,14 @@ function MOI.Bridges.Constraint.concrete_bridge_type(
M = SOS.matrix_cone_type(CT)
W = SOS.Certificate._weight_type(T, BT)
B = MA.promote_operation(
SOS.Certificate.reduced_basis,
SOS.Certificate.zero_basis,
CT,
BT,
SemialgebraicSets.similar_type(DT, T),
Vector{BT},
Vector{W},
)
G = SOS.Certificate.gram_basis_type(CT)
G = MA.promote_operation(SOS.Certificate.gram_basis, CT)
return SOSPolynomialBridge{T,F,DT,M,BT,B,_eltype(G),CT,W}
end

Expand Down
4 changes: 1 addition & 3 deletions src/Certificate/Certificate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ const Index = Union{PreorderIndex,IdealIndex}

abstract type Attribute end

# For get
function cone end
function zero_basis end
function gram_basis end
# FIXME currently, this returns `MB.MonomialBasis` instead of `MB.MonomialBasis{MT, MVT}`
function gram_basis_type end
function reduced_polynomial end
function ideal_certificate end
function preprocessed_domain end
Expand Down
59 changes: 45 additions & 14 deletions src/Certificate/Sparsity/ideal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,52 @@ struct Ideal{S<:Pattern,C<:SumOfSquares.Certificate.AbstractIdealCertificate} <:
certificate::C
end

function Ideal(sp::Variable, basis, cone, maxdegree::Nothing, newton_polytope)
function Ideal(
sp::Variable,
gram_basis,
zero_basis,
cone,
maxdegree::Nothing,
newton_polytope,
)
return error(
"`maxdegree` cannot be `nothing` when `sparsity` is `Sparsity.Variable`.",
)
end
function Ideal(sp::Variable, basis, cone, maxdegree::Integer, newton_polytope)
return Ideal(sp, SumOfSquares.Certificate.MaxDegree(cone, basis, maxdegree))
function Ideal(
sp::Variable,
gram_basis,
zero_basis,
cone,
maxdegree::Integer,
newton_polytope,
)
return Ideal(
sp,
SumOfSquares.Certificate.MaxDegree(
cone,
gram_basis,
zero_basis,
maxdegree,
),
)
end
function Ideal(
sp::Union{Monomial,SignSymmetry},
basis,
gram_basis,
zero_basis,
cone,
maxdegree,
newton_polytope,
)
return Ideal(
sp,
SumOfSquares.Certificate.Newton(cone, basis, newton_polytope),
SumOfSquares.Certificate.Newton(
cone,
gram_basis,
zero_basis,
newton_polytope,
),
)
end

Expand All @@ -44,7 +72,7 @@ function sparsity(
H, cliques = chordal_csp_graph(basis, SemialgebraicSets.FullSpace())
return map(cliques) do clique
return SumOfSquares.Certificate.maxdegree_gram_basis(
certificate.basis,
certificate.gram_basis,
clique,
certificate.maxdegree,
)
Expand All @@ -71,10 +99,11 @@ end
function SumOfSquares.Certificate.gram_basis(certificate::Ideal, poly)
return sparsity(poly, certificate.sparsity, certificate.certificate)
end
function SumOfSquares.Certificate.gram_basis_type(
function MA.promote_operation(
::typeof(SumOfSquares.Certificate.gram_basis),
::Type{Ideal{S,C}},
) where {S,C}
return Vector{SumOfSquares.Certificate.gram_basis_type(C)}
return Vector{MA.promote_operation(SumOfSquares.Certificate.gram_basis, C)}
end
function SumOfSquares.Certificate.reduced_polynomial(
certificate::Ideal,
Expand All @@ -87,14 +116,14 @@ function SumOfSquares.Certificate.reduced_polynomial(
domain,
)
end
function SumOfSquares.Certificate.reduced_basis(
function SumOfSquares.Certificate.zero_basis(
certificate::Ideal,
basis,
domain,
gram_bases,
weights,
)
return SumOfSquares.Certificate.reduced_basis(
return SumOfSquares.Certificate.zero_basis(
certificate.certificate,
basis,
domain,
Expand All @@ -103,15 +132,15 @@ function SumOfSquares.Certificate.reduced_basis(
)
end
function MA.promote_operation(
::typeof(SumOfSquares.Certificate.reduced_basis),
::typeof(SumOfSquares.Certificate.zero_basis),
::Type{Ideal{S,C}},
::Type{B},
::Type{D},
::Type{G},
::Type{W},
) where {S,C,B,D,G,W}
return MA.promote_operation(
SumOfSquares.Certificate.reduced_basis,
SumOfSquares.Certificate.zero_basis,
C,
B,
D,
Expand All @@ -129,8 +158,10 @@ end
function SumOfSquares.Certificate.zero_basis(certificate::Ideal)
return SumOfSquares.Certificate.zero_basis(certificate.certificate)
end
function SumOfSquares.Certificate.zero_basis_type(

function MA.promote_operation(
b::typeof(SumOfSquares.Certificate.zero_basis),
::Type{Ideal{S,C}},
) where {S,C}
return SumOfSquares.Certificate.zero_basis_type(C)
return MA.promote_operation(b, C)
end
2 changes: 1 addition & 1 deletion src/Certificate/Sparsity/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function sparsity(
function bases(q)
return [
SumOfSquares.Certificate.maxdegree_gram_basis(
certificate.multipliers_certificate.basis,
certificate.multipliers_certificate.gram_basis,
clique,
SumOfSquares.Certificate.multiplier_maxdegree(
certificate.maxdegree,
Expand Down
20 changes: 14 additions & 6 deletions src/Certificate/Symmetry/wedderburn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,18 @@ end
function SumOfSquares.matrix_cone_type(::Type{<:Ideal{C}}) where {C}
return SumOfSquares.matrix_cone_type(C)
end
function SumOfSquares.Certificate.gram_basis_type(::Type{<:Ideal})
function MA.promote_operation(
::typeof(SumOfSquares.Certificate.gram_basis),
::Type{<:Ideal},
)
return Vector{Vector{MB.FixedPolynomialBasis}}
end
SumOfSquares.Certificate.zero_basis_type(::Type{<:Ideal}) = MB.Monomial
function MA.promote_operation(
::typeof(SumOfSquares.Certificate.zero_basis),
::Type{<:Ideal},
)
return MB.Monomial
end
SumOfSquares.Certificate.zero_basis(::Ideal) = MB.Monomial
function SumOfSquares.Certificate.reduced_polynomial(
certificate::Ideal,
Expand All @@ -91,14 +99,14 @@ function SumOfSquares.Certificate.reduced_polynomial(
domain,
)
end
function SumOfSquares.Certificate.reduced_basis(
function SumOfSquares.Certificate.zero_basis(
certificate::Ideal,
basis,
domain,
gram_bases,
weights,
)
return SumOfSquares.Certificate.reduced_basis(
return SumOfSquares.Certificate.zero_basis(
certificate.certificate,
basis,
domain,
Expand All @@ -107,15 +115,15 @@ function SumOfSquares.Certificate.reduced_basis(
)
end
function MA.promote_operation(
::typeof(SumOfSquares.Certificate.reduced_basis),
::typeof(SumOfSquares.Certificate.zero_basis),
::Type{Ideal{S,C}},
::Type{B},
::Type{D},
::Type{G},
::Type{W},
) where {S,C,B,D,G,W}
return MA.promote_operation(
SumOfSquares.Certificate.reduced_basis,
SumOfSquares.Certificate.zero_basis,
C,
B,
D,
Expand Down
Loading

0 comments on commit 1f7a718

Please sign in to comment.