juliareach / intervalmatrices.jl Goto Github PK
View Code? Open in Web Editor NEWMatrices with interval coefficients in Julia
Home Page: https://juliareach.github.io/IntervalMatrices.jl/
License: Other
Matrices with interval coefficients in Julia
Home Page: https://juliareach.github.io/IntervalMatrices.jl/
License: Other
#83 suggests to reformulate the matrix power with explicit intervals.
When interpreting an interval matrix M
as a set of matrices Aᵢ
, and we only require that
M^k ⊇ ⋃ᵢ Aᵢ^k
holds, we can do better: Perform the multiplications symbolically: e.g., in 2D, consider M = [a b; c d]
and write M^k
as a matrix whose entries are polynomials in the original intervals a,b,c,d
. Then in the end evaluate the final polynomials with interval arithmetic.
This issue is related to #88. Proposal: add a new IntervalMatrixPower
wrapper which holds the power k
of the matrix power. The purpose of this type is to experiment with lazy construction of the matrix power for evaluation using different methods. The new type can also have a cache for the representation of the power using symbols, eg. polynomials.
Builds fail due to insufficient access rights. This is probably another case where we integrated the key at the wrong Travis URL.
introduce notation for interval matrices [A]
revise example from the Quickstart about squaring interval matrices (ref. #80, Kosheleva et al's paper).
non-associativity of matrix products
SUE
Actually, what we need is, given an interval matrix M
, return the conventional matrix C
and the conventional matrix S
such that M = C + [-S, S]
.
The term "expm" comes from pre-1.0 Julia, which used expm
for the matrix exponential. It's now called exp
, so i propose to rename expm_overapproximation
to exp_overapproximation
and similarly to the other methods that use expm
.
As a reminder, the new method can be applied here:
IntervalMatrices.jl/src/exponential.jl
Line 121 in 0eb486f
Originally posted by @mforets in #73 (comment)
This is F
from [Theorem 3, 1].
The k
-th integer power of an interval matrix M
, M^k
, is not well-defined. The reason is that interval-matrix multiplication is not associative. Furthermore, even for a fixed order, the multiplication induces an error due to the intervals. The only safe case is squaring (i.e., k = 2
) (see #79).
Decompose the power k
such that many squares are used. In other words: use as few non-square multiplications as possible.
In the example below, we compute M^9
.
A
and B
use the naive power operation, which are the worst options. (Interestingly, ^
does something slightly more intelligent. ?> ^
says equivalent to \exp(p\log(A))
).C
, D
, E
use the fact that 9 = 2² + 2² + 1.F
, G
, H
use the fact that 9 = (2 + 1)³ + 2 + 1 (I only tried three permutations).julia> M = rand(IntervalMatrix)
2×2 IntervalMatrix{Float64,Interval{Float64},Array{Interval{Float64},2}}:
[-1.88661, 1.81318] [-0.483837, 0.892705]
[-0.893564, -0.447015] [-0.10882, 1.85449]
julia> A = M*M*M*M*M*M*M*M*M # 9 multiplications
2×2 IntervalMatrix{Float64,Interval{Float64},Array{Interval{Float64},2}}:
[-4394.68, 4388.85] [-4300.39, 4320.52]
[-3599.78, 3582.38] [-3495.86, 3545.53]
julia> B = M^9
2×2 IntervalMatrix{Float64,Interval{Float64},Array{Interval{Float64},2}}:
[-3734.67, 3685.31] [-3311.99, 3430.62]
[-3602.63, 3458.46] [-3008.63, 3290.32]
julia> M2 = square(M); M4 = square(M2);
julia> C = M4*M4*M # 2 multiplications
2×2 IntervalMatrix{Float64,Interval{Float64},Array{Interval{Float64},2}}:
[-2606.43, 2225.51] [-1907.27, 2779.07]
[-2700.44, 2863.45] [-2624.69, 2006.86]
julia> D = M4*M*M4 # 2 multiplications
2×2 IntervalMatrix{Float64,Interval{Float64},Array{Interval{Float64},2}}:
[-3126.19, 2073.73] [-2410.01, 2737.56]
[-2740.19, 2372.8] [-2575.55, 2563.49]
julia> E = M*M4*M4 # 2 multiplications
2×2 IntervalMatrix{Float64,Interval{Float64},Array{Interval{Float64},2}}:
[-3077.05, 2643.18] [-2871.06, 2697.84]
[-2781.74, 1880.41] [-2624.69, 2006.86]
julia> F = square(M2*M) * M2*M # 3 multiplications
2×2 IntervalMatrix{Float64,Interval{Float64},Array{Interval{Float64},2}}:
[-3310.01, 2898.24] [-2427.69, 3330.15]
[-2954.44, 2930.17] [-2664.27, 2640.69]
julia> G = M2*M * square(M2*M) # 3 multiplications
2×2 IntervalMatrix{Float64,Interval{Float64},Array{Interval{Float64},2}}:
[-3432.39, 2898.24] [-2646.09, 2878.82]
[-3104.07, 2437.67] [-2388.99, 2603.88]
julia> H = M2 * square(M2*M) * M # 3 multiplications
2×2 IntervalMatrix{Float64,Interval{Float64},Array{Interval{Float64},2}}:
[-3211.14, 2877.44] [-2416.47, 3160.68]
[-3121.46, 3105.47] [-2767.25, 2662.37]
Presumably there is no optimal way to decompose the power, even when ignoring the order of the multiplications. A heuristics could be to decompose into the largest square numbers.
There is another issue: In the above algorithm/heuristics we may compute certain matrix powers several times. It might be better to have some symbolic representation of the decomposition (as we had in the example) and then compute each term only once. However, that sounds more complicated.
t
and what is p
Currently the computation of the infinity norm uses left
and right
:
IntervalMatrices.jl/src/matrix.jl
Line 53 in a024782
However, these methods allocate one new vector (of the size of the matrix) each. Since in the end we are only interested in a single value, this is not necessary.
function infinity_norm(A)
res = abs(A[1, 1].left)
for itv in A
res = max(res, abs(itv.left), itv.right)
end
return res
end
(Note that I omitted the abs
on itv.right
for efficiency.)
We should also evaluate if the following is faster (rationale: write only when necessary).
function infinity_norm2(A)
res = abs(A[1, 1].left)
for itv in A
m = max(abs(itv.left), itv.right)
if m > res
res = m
end
end
return res
end
Write a function that computes the sum \sum_{i=i0}^{p} A^i * t^i / i!}
. Note that if i0=0
one should use the exact computation of At + 1/2A^2 t^2
(matrix W).
i0
julia> K = copy(Pint.s.A)
4×4 IntervalMatrix{Float64,IntervalArithmetic.Interval{Float64},Array{IntervalArithmetic.Interval{Float64},2}}:
[0, 0] [0, 0] [-2500, -2500] [2500, 2500]
[0, 0] [0, 0] [0, 0] [-2500, -2500]
[10, 10] [0, 0] [-100, -100] [0, 0]
[-10, -10] [10, 10] [0, 0] [-10, -10]
julia> expm_overapproximation(K, 0.002, 12)
4×4 IntervalMatrix{Float64,IntervalArithmetic.Interval{Float64},Array{IntervalArithmetic.Interval{Float64},2}}:
[-5619.76, 5621.58] [-5620.62, 5620.72] … [-5615.96, 5625.38]
[-5620.62, 5620.72] [-5619.72, 5621.62] [-5625.46, 5615.88]
[-5620.65, 5620.69] [-5620.67, 5620.67] [-5620.62, 5620.72]
[-5620.69, 5620.65] [-5620.65, 5620.69] [-5619.79, 5621.55]
julia> expm_overapproximation_old(K, 0.002, 12)
4×4 IntervalMatrix{Float64,IntervalArithmetic.Interval{Float64},Array{IntervalArithmetic.Interval{Float64},2}}:
[0.600556, 1.21044] [-0.256488, 0.353395] … [4.40467, 5.01456]
[-0.256488, 0.353395] [0.64621, 1.2561] [-5.09231, -4.48241]
[-0.287424, 0.322458] [-0.30463, 0.305252] [-0.259597, 0.350285]
[-0.32378, 0.286103] [-0.285792, 0.324091] [0.578608, 1.18849]
julia> exp(mid(K) * 0.002)
4×4 Array{Float64,2}:
0.905497 0.0484535 -4.37927 4.70961
0.0484535 0.951152 -0.0777469 -4.78736
0.0175171 0.000310987 0.77567 0.0453436
-0.0188385 0.0191494 0.0453436 0.883549
where expm_overapproximation_old
is using the function expm_overapproximation
before we made the changes that entered in v0.2.0, so it could be in PR#18 or PR#19, or it could be something else.
Note that in this example the intervals in K have width zero. The huge intervals [-5619.76, 5621.58]
seem like a bug.
Rump has a test for invertibility of an interval matrix.
This is E(r)
in [Theorem 1, 1].
Here are some optimizations for the function quadratic_expansion
(below):
i
/j
(iterate over columns in Julia).t^2/2
only once.S
first (avoids double access to each cell).k ≠ i
conditions (have two loops from 1 to i-1
and from i+1
to n
) (if
s in loops are performance killers); the version for k ≠ i && k ≠ j
needs three loops.A
(no performance improvement, but nice to have).IntervalMatrices.jl/src/exponential.jl
Lines 17 to 56 in a024782
Implement Proposition 1 in https://mediatum.ub.tum.de/doc/1287218/1287218.pdf
Given an interval matrix A
, we can compute A²
exactly. This is not true for higher powers. See [1, Section 6] for an algorithm.
[1] Olga Kosheleva, Vladik Kreinovich, Günter Mayer, Hung T. Nguyen: Computing the cube of an interval matrix is NP-Hard. SAC 2005. [PDF]
[Theorem 4.1.11, N90] yeilds an enclosure for the inverse of a strongly regular interval matrix.
[N90] - A. Neumaier. Interval Methods for Systems of Equations. Cambridge Univ. Press,
1990.
It would be great to implement Rump’s method for efficiently multiplying interval matrices using only floating-point matrix operations (with rounding mode changes).
Rump has a test for positive definiteness of interval matrices.
Here are some optimizations for the function expm_overapproximation
(below):
t^i/factorial(i)
in the loop and then just multiply with t/i
instead of recomputing from scratch.A
)A
(no performance improvement, but nice to have).IntervalMatrices.jl/src/exponential.jl
Lines 74 to 94 in a024782
Write a function that computes the sum \sum_{i=i0}^{p} A^i * t^{i+1} / (i+1)!}
.
It is handy to have a function for creating an identity matrix.
Maybe Diagonal(one_interval, n)
"just works" (not tested).
We can offer the in-place version and the out-of-place version.
In this line
https://github.com/JuliaReach/IntervalMatrices.jl/blob/master/src/exponential.jl#L91
both W
and E
are just of type Matrix{Interval}
instead of IntervalMatrix
.
If we call several functions that compute _expm_remainder
(like in Reachability
), it would be better to instead compute it only once and pass the result around.
julia> A = IntervalMatrix([-1.0 ± 0.05 -4.0 ± 0.05;
4.0 ± 0.05 -1.0 ± 0.05])
2×2 IntervalMatrix{Float64,IntervalArithmetic.Interval{Float64},Array{IntervalArithmetic.Interval{Float64},2}}:
[-1.05001, -0.949999] [-4.05001, -3.94999]
[3.94999, 4.05001] [-1.05001, -0.949999]
julia> typeof(A)
IntervalMatrix{Float64,IntervalArithmetic.Interval{Float64},Array{IntervalArithmetic.Interval{Float64},2}}
julia> B = copy(A)
2×2 Array{IntervalArithmetic.Interval{Float64},2}:
[-1.05001, -0.949999] [-4.05001, -3.94999]
[3.94999, 4.05001] [-1.05001, -0.949999]
julia> typeof(B) # not an IntervalMatrix!
Array{IntervalArithmetic.Interval{Float64},2}
See the Codecov report, which can be easily brought close to 100%.
Implement W* from Prop. 2 in [Reachability Analysis of Linear Systems
with Uncertain Parameters and Inputs] using SUE.
A - B
does not return an IntervalMatrix
.
julia> rand(IntervalMatrix) - rand(IntervalMatrix)
2×2 Array{Interval{Float64},2}:
[0.16067, 1.02546] [1.04121, 1.29847]
[-2.29271, -1.06139] [-0.32639, 0.903041]
The current behavior is rather arbitrary:
julia> [size(rand(IntervalMatrix, i), 2) for i in 2:5]
4-element Array{Int64,1}:
2
2
2
2
It would be arguably less arbitrary if rand(IntervalMatrix, i)
returns a square matrix of order i
.
There are several references, see e.g.
Bounding the eigenvectors of symmetric interval matrices. Dr. N. P. Seif S. Hashem Prof. Dr. A. S. Deif.
On the range of eigenvalues of an interval matrix. Jiri Rohn Assem Deif Assem Deif.
Eigenvalues of symmetric interval matrices. Nikolay Stoyanov Kaleyski
Computing the range of real eigenvalues of an interval
matrix. Milan Hladik & David Daney.
Hartman, David, Milan Hladík, and David Říha. "Computing the spectral decomposition of interval matrices and a study on interval matrix power." arXiv preprint arXiv:1912.05275 (2019). pdf
See also the package: https://github.com/dpsanders/IntervalEigenvalues.jl
julia> M
2×2 IntervalMatrix{Float64,Interval{Float64},Array{Interval{Float64},2}}:
[-11.0001, -9] [-41, -38.9999]
[38.9999, 41] [-11.0001, -9]
julia> mid(M)
2×2 Array{Float64,2}:
-10.0 -40.0
40.0 -10.0
julia> M * mid(M)
2×2 Array{Interval{Float64},2}:
[-1550, -1449.99] [749.999, 850.001]
[-850.001, -749.999] [-1550, -1449.99]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.