Skip to content

Instantly share code, notes, and snippets.

@mforets
Created December 5, 2019 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mforets/8a1a2d37ec2d3067b0d6f131c94acf52 to your computer and use it in GitHub Desktop.
Save mforets/8a1a2d37ec2d3067b0d6f131c94acf52 to your computer and use it in GitHub Desktop.
Convert TM to zonotop
using LazySets, TaylorModels
import IntervalArithmetic
const IA = IntervalArithmetic
const zeroI = IA.Interval(0.0) # [0.0, 0.0]
const oneI = IA.Interval(1.0) # [1.0, 1.0]
const symI = IA.Interval(-1.0, 1.0)
@inline zeroBox(m) = IntervalBox(zeroI, m)
@inline symBox(m) = IntervalBox(symI, m)
# cuts the Δt into NΔt pieces, returning a vector of zonotopes
function TM_Zono(tTM, vTM, n, NΔt)
N = length(tTM)
Rsets = Vector{Zonotope{Float64}}(undef, NΔt)
X = vTM[:, i]
# pick the time domain of the given TM (same in all dimensions)
Δt = TaylorModels.domain(X[1])
if NΔt > 1
Δt_div = range(IA.inf(Δt), stop=IA.sup(Δt), length=NΔt+1)
else
Δt_div = Δt
end
for k in 1:(length(Δt_div)-1)
# evaluate the Taylor model in time, the coefficents are now intervals
X_Δt = evaluate(X, IA.Interval(Δt_div[k], Δt_div[k+1]))
# builds the associated taylor model for each coordinate j = 1...n
X̂ = [TaylorModelN(X_Δt[j], X[j].rem, zeroBox(n), symBox(n)) for j in 1:n]
# floating point rigorous polynomial approximation
fX̂ = TaylorModels.fp_rpa.(X̂)
# LazySets can overapproximate a Taylor model with a Zonotope
Zi = overapproximate(fX̂, Zonotope)
t0 = Δt_div[k]
t1 = Δt_div[k+1]
Rsets[NΔt * (i - 1) + k] = Zi
end
return Rsets
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment