Skip to content

Commit 4af4b3e

Browse files
authored
Sampling basis (#378)
* Sampling basis * Fixes * Fixes * Fix format * Fix * Fix * Fix format * Fix * Update src/constraints.jl * Delete docs/src/tutorials/Getting started/sampling.jl
1 parent 1f7a718 commit 4af4b3e

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

src/Certificate/ideal.jl

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,22 @@ function _combine_with_gram(
4040
return MB.SubBasis{B}(keys(SA.coeffs(p)))
4141
end
4242

43-
_reduce_with_domain(basis::MB.SubBasis, ::FullSpace) = basis
43+
function _reduce_with_domain(basis::MB.SubBasis, zero_basis, ::FullSpace)
44+
return MB.explicit_basis_covering(zero_basis, basis)
45+
end
4446

45-
function _reduce_with_domain(basis::MB.SubBasis{B}, domain) where {B}
46-
if B !== MB.Monomial
47-
error("Only Monomial basis support with an equalities in domain")
48-
end
47+
function _reduce_with_domain(basis, zero_basis, domain)
48+
return __reduce_with_domain(basis, zero_basis, domain)
49+
end
50+
51+
function __reduce_with_domain(_, _, _)
52+
return error("Only Monomial basis support with an equalities in domain")
53+
end
54+
function __reduce_with_domain(
55+
basis::MB.SubBasis{MB.Monomial},
56+
::MB.FullBasis{MB.Monomial},
57+
domain,
58+
)
4959
I = ideal(domain)
5060
# set of standard monomials that are hit
5161
standard = Set{eltype(basis.monomials)}()
@@ -60,14 +70,15 @@ function _reduce_with_domain(basis::MB.SubBasis{B}, domain) where {B}
6070
end
6171

6272
function zero_basis(
63-
::AbstractIdealCertificate,
73+
cert::AbstractIdealCertificate,
6474
basis,
6575
domain,
6676
gram_bases,
6777
weights,
6878
)
6979
return _reduce_with_domain(
7080
_combine_with_gram(basis, gram_bases, weights),
81+
_zero_basis(cert),
7182
domain,
7283
)
7384
end
@@ -270,15 +281,27 @@ function _quotient_basis_type(
270281
}
271282
end
272283

284+
_zero_basis(c::SimpleIdealCertificate) = c.zero_basis
285+
286+
function _zero_basis_type(::Type{<:SimpleIdealCertificate{C,G,Z}}) where {C,G,Z}
287+
return Z
288+
end
289+
290+
_zero_basis(c::Remainder) = _zero_basis(c.gram_certificate)
291+
292+
function _zero_basis_type(::Type{Remainder{C}}) where {C}
293+
return _zero_basis_type(C)
294+
end
295+
273296
function MA.promote_operation(
274297
::typeof(zero_basis),
275-
::Type{<:Union{SimpleIdealCertificate,Remainder}},
276-
::Type{B},
298+
C::Type{<:Union{SimpleIdealCertificate,Remainder}},
299+
::Type,
277300
::Type{SemialgebraicSets.FullSpace},
278301
::Type,
279302
::Type,
280-
) where {B}
281-
return B
303+
)
304+
return MB.explicit_basis_type(_zero_basis_type(C))
282305
end
283306

284307
function MA.promote_operation(

src/constraints.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,11 @@ function _default_basis(p::MP.AbstractPolynomialLike, basis)
438438
)
439439
end
440440

441+
_default_zero_basis(basis, ::Nothing) = MB.implicit_basis(basis)
442+
function _default_zero_basis(basis, nodes::MB.AbstractNodes)
443+
return MB.ImplicitLagrangeBasis(MP.variables(basis), nodes)
444+
end
445+
441446
function JuMP.build_constraint(
442447
_error::Function,
443448
p,
@@ -447,10 +452,13 @@ function JuMP.build_constraint(
447452
kws...,
448453
)
449454
__coefs, basis, gram_basis = _default_basis(p, basis)
450-
if isnothing(zero_basis)
451-
zero_basis = MB.implicit_basis(basis)
452-
end
453-
set = JuMP.moi_set(cone, basis, gram_basis, zero_basis; kws...)
455+
set = JuMP.moi_set(
456+
cone,
457+
basis,
458+
gram_basis,
459+
_default_zero_basis(basis, zero_basis);
460+
kws...,
461+
)
454462
_coefs = PolyJuMP.non_constant(__coefs)
455463
# If a polynomial with real coefficients is used with the Hermitian SOS
456464
# cone, we want to promote the coefficients to complex

0 commit comments

Comments
 (0)