Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3117 - Generalize exponential backend in symmetric_interval_hull methods #3253

Merged
merged 1 commit into from
Apr 5, 2023
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
3 changes: 2 additions & 1 deletion src/Approximations/Approximations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ using LazySets, ReachabilityBase.Arrays, Requires, LinearAlgebra, SparseArrays

using ReachabilityBase.Comparison: _isapprox, _leq, _geq, _rtol, isapproxzero
using LazySets: default_lp_solver, _isbounded_stiemke, require, dim, linprog,
is_lp_optimal, _normal_Vector
is_lp_optimal, _normal_Vector,
get_exponential_backend, _expmv
using LazySets.JuMP: Model, set_silent, @variable, @constraint, optimize!,
value, @NLobjective

Expand Down
3 changes: 2 additions & 1 deletion src/Approximations/init.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function __init__()
@require Expokit = "a1e7a1ef-7a5d-5822-a38c-be74e1bb89f4" include("init_Expokit.jl")
@require Expokit = "a1e7a1ef-7a5d-5822-a38c-be74e1bb89f4" (nothing,)
@require ExponentialUtilities = "d4d017d3-3776-5f7e-afef-a10c40355c18" (nothing,)
@require IntervalMatrices = "5c1f47dc-42dd-5697-8aaa-4d102d140ba9" include("init_IntervalMatrices.jl")
@require IntervalConstraintProgramming = "138f1668-1576-5ad7-91b9-7425abbf3153" include("init_IntervalConstraintProgramming.jl")
@require Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9" include("init_Ipopt.jl")
Expand Down
9 changes: 0 additions & 9 deletions src/Approximations/init_Expokit.jl

This file was deleted.

16 changes: 7 additions & 9 deletions src/Approximations/symmetric_interval_hull.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,29 +102,27 @@ function symmetric_interval_hull(lm::LinearMap{N, <:AbstractHyperrectangle}) whe
return Hyperrectangle(zeros(N, n), r)
end

function symmetric_interval_hull(E::ExponentialMap{N, <:AbstractSingleton}) where {N}
require(@__MODULE__, :Expokit; fun_name="symmetric_interval_hull")

v = expmv(one(N), E.spmexp.M, element(E.X))
function symmetric_interval_hull(E::ExponentialMap{N, <:AbstractSingleton};
backend=get_exponential_backend()) where {N}
v = _expmv(backend, one(N), E.spmexp.M, element(E.X))
c = zeros(N, dim(E))
r = abs.(v)
return Hyperrectangle(c, r)
end

function symmetric_interval_hull(E::ExponentialMap{N, <:AbstractHyperrectangle}) where {N}
require(@__MODULE__, :Expokit; fun_name="symmetric_interval_hull")

function symmetric_interval_hull(E::ExponentialMap{N, <:AbstractHyperrectangle};
backend=get_exponential_backend()) where {N}
H = set(E)
n = dim(H)
x = zeros(N, n)
r = abs.(expmv(one(N), E.spmexp.M, center(H)))
r = abs.(_expmv(backend, one(N), E.spmexp.M, center(H)))
@inbounds for i in 1:n
x[i] = radius_hyperrectangle(H, i)
if isapproxzero(x[i])
x[i] = 0
continue
end
r .+= abs.(expmv(one(N), E.spmexp.M, x))
r .+= abs.(_expmv(backend, one(N), E.spmexp.M, x))
x[i] = 0
end
return Hyperrectangle(zeros(N, n), r)
Expand Down
9 changes: 8 additions & 1 deletion test/LazyOperations/ExponentialMap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,14 @@ for exp_backend in [ExponentialUtilities, Expokit]
# the exponential map applied to an exponential map
ExponentialMap(SparseMatrixExp(2*m), emap)

# for projection tests, let's assume that n is divisible by three
# symmetric_interval_hull
sih = symmetric_interval_hull(emap)
@test sih isa Hyperrectangle{N} && center(sih) == zeros(N, 6)
@test radius_hyperrectangle(sih) ≈
N[1.4615602805461578, 1.7892495373142225, 1.1215454866370536,
1.9033524001317403, 0.5475680039922208, 1.3374631184550847]

# for projection tests, assume that n is divisible by three
@assert mod(n, 3) == 0
nb = div(n, 3)
# the projection of exp(A) on the (m, m)-dimensional right-most upper block
Expand Down