Skip to content

Commit

Permalink
Merge pull request #123 from JuliaReach/schillic/75
Browse files Browse the repository at this point in the history
#75 - Truncated exponential sum
  • Loading branch information
schillic authored Feb 10, 2020
2 parents a82937a + 454d310 commit 2c77108
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 27 deletions.
73 changes: 47 additions & 26 deletions src/exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,45 @@ function quadratic_expansion(A::IntervalMatrix, α::Real, β::Real)
return IntervalMatrix(B)
end

function _truncated_exponential_series(A::IntervalMatrix{T}, t, p::Integer;
n=checksquare(A)) where {T}
if p == 0
# index i = 0 (identity matrix)
return IntervalMatrix(Interval(one(T)) * I, n)
elseif p == 1
# index i = 1
S = A * t
else
# indices i = 1 and i = 2
S = quadratic_expansion(A, t)
end

# index i = 0, (identity matrix, added implicitly)
for i in 1:n
S[i, i] += one(T)
end

if p < 3
return S
end

# indices i >= 3
pow = IntervalMatrixPower(A)
increment!(pow)
fact_num = t^2
fact_denom = 2
for i in 3:p
fact_num *= t
fact_denom *= i
Aⁱ = increment!(pow)
S += Aⁱ * (fact_num / fact_denom)
end

return S
end

"""
exp_overapproximation(M::IntervalMatrix{T, Interval{T}}, t, p) where {T}
exp_overapproximation(A::IntervalMatrix{T, Interval{T}}, t, p) where {T}
Overapproximation of the exponential of an interval matrix.
Expand All @@ -139,26 +176,9 @@ Parameters and Inputs* by M. Althoff, O. Stursberg, M. Buss.
"""
function exp_overapproximation(A::IntervalMatrix{T, Interval{T}}, t, p) where {T}
n = checksquare(A)

S = _truncated_exponential_series(A, t, p; n=n)
E = _exp_remainder(A, t, p; n=n)
S = IntervalMatrix(zeros(Interval{T}, n, n))
Ai = square(A)
fact_num = t^2
fact_denom = 2
for i in 3:p
fact_num *= t
fact_denom *= i
Ai *= A
S += Ai * (fact_num / fact_denom)
end
W = quadratic_expansion(A, t)
res = W + S + E

# add identity matrix implicitly
for i in 1:n
res[i, i] += one(T)
end
return res
return S + E
end

# Implementation of Prop. 1 in Althoff, Matthias, Bruce H. Krogh, and Olaf Stursberg.
Expand Down Expand Up @@ -263,24 +283,25 @@ See Theorem 2 in *Reachability Analysis of Linear Systems with Uncertain
Parameters and Inputs* by M. Althoff, O. Stursberg, M. Buss.
"""
function exp_underapproximation(A::IntervalMatrix{T, Interval{T}}, t, p) where {T}
@assert p > 1 "the order $p < 2 is not supported"
n = checksquare(A)

Y = zeros(n, n)
LA = inf(A)
Ail = LA^2
Aⁱl = LA^2
Z = zeros(n, n)
RA = sup(A)
Air = RA^2
Aⁱr = RA^2
fact_num = t^2
fact_denom = 2
for i in 3:p
fact_num *= t
fact_denom *= i
fact = fact_num / fact_denom
Ail *= LA
Y += Ail * fact
Air *= RA
Z += Air * fact
Aⁱl *= LA
Y += Aⁱl * fact
Aⁱr *= RA
Z += Aⁱr * fact
end

B = IntervalMatrix{T}(undef, n , n)
Expand Down
7 changes: 6 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using IntervalMatrices, Test, LinearAlgebra

using IntervalMatrices: scale_and_square
using IntervalMatrices: _truncated_exponential_series, scale_and_square

@testset "Interval arithmetic" begin
a = -1.5 ± 0.5
Expand Down Expand Up @@ -67,6 +67,11 @@ end

@testset "Interval matrix exponential" begin
m = IntervalMatrix([-1.1..0.9 -4.1.. -3.9; 3.9..4.1 -1.1..0.9])

for i in 0:4
_truncated_exponential_series(m, 1.0, i)
end

overapp1 = exp_overapproximation(m, 1.0, 4)
overapp2 = scale_and_square(m, 5, 1.0, 4)
underapp = exp_underapproximation(m, 1.0, 4)
Expand Down

0 comments on commit 2c77108

Please sign in to comment.