|
| 1 | +""" |
| 2 | + verify_eigen(A[, λ, X0]; w=0.1, ϵ=1e-16, maxiter=10) |
| 3 | +
|
| 4 | +Finds a rigorous bound for the eigenvalues and eigenvectors of `A`. Eigenvalues are treated |
| 5 | +as simple. |
| 6 | +
|
| 7 | +### Input |
| 8 | +
|
| 9 | +- `A` -- matrix |
| 10 | +- `λ` -- (optional) approximate value for an eigenvalue of `A` |
| 11 | +- `X0` -- (optional) eigenvector associated to `λ` |
| 12 | +- `w` -- relative inflation parameter |
| 13 | +- `ϵ` -- absolute inflation parameter |
| 14 | +- `maxiter` -- maximum number of iterations |
| 15 | +
|
| 16 | +### Output |
| 17 | +
|
| 18 | +- Interval bounds on eigenvalues and eigenvectors. |
| 19 | +- A boolean certificate (or a vector of booleans if all eigenvalues are computed) `cert`. |
| 20 | + If `cert[i]==true`, then the bounds for the ith eigenvalue and eigenvectore are rigorous, |
| 21 | + otherwise not. |
| 22 | +
|
| 23 | +### Algorithm |
| 24 | +
|
| 25 | +The algorithm for this function is described in [[RUM01]](@ref). |
| 26 | +
|
| 27 | +### Example |
| 28 | +
|
| 29 | +```julia |
| 30 | +julia> A = Symmetric([1 2;2 3]) |
| 31 | +2×2 Symmetric{Int64, Matrix{Int64}}: |
| 32 | + 1 2 |
| 33 | + 2 3 |
| 34 | +
|
| 35 | +julia> evals, evecs, cert = verify_eigen(A); |
| 36 | +
|
| 37 | +julia> evals |
| 38 | +2-element Vector{Interval{Float64}}: |
| 39 | + [-0.236068, -0.236067] |
| 40 | + [4.23606, 4.23607] |
| 41 | +
|
| 42 | +julia> evecs |
| 43 | +2×2 Matrix{Interval{Float64}}: |
| 44 | + [-0.850651, -0.85065] [0.525731, 0.525732] |
| 45 | + [0.525731, 0.525732] [0.85065, 0.850651] |
| 46 | +
|
| 47 | +julia> cert |
| 48 | +2-element Vector{Bool}: |
| 49 | + 1 |
| 50 | + 1 |
| 51 | +``` |
| 52 | +""" |
| 53 | +function verify_eigen(A; kwargs...) |
| 54 | + evals, evecs = eigen(mid.(A)) |
| 55 | + |
| 56 | + T = interval_eigtype(A, evals[1]) |
| 57 | + evalues = similar(evals, T) |
| 58 | + evectors = similar(evecs, T) |
| 59 | + |
| 60 | + cert = Vector{Bool}(undef, length(evals)) |
| 61 | + @inbounds for (i, λ₀) in enumerate(evals) |
| 62 | + λ, v, flag = verify_eigen(A, λ₀, view(evecs, :,i); kwargs...) |
| 63 | + evalues[i] = λ |
| 64 | + evectors[:, i] .= v |
| 65 | + cert[i] = flag |
| 66 | + |
| 67 | + end |
| 68 | + return evalues, evectors, cert |
| 69 | +end |
| 70 | + |
| 71 | +function verify_eigen(A, λ, X0; kwargs...) |
| 72 | + ρ, X, cert = _verify_eigen(A, λ, X0; kwargs...) |
| 73 | + return (real(λ) ± ρ) + (imag(λ) ± ρ) * im, X0 + X, cert |
| 74 | +end |
| 75 | + |
| 76 | +function verify_eigen(A::Symmetric, λ, X0; kwargs...) |
| 77 | + ρ, X, cert = _verify_eigen(A, λ, X0; kwargs...) |
| 78 | + return λ ± ρ, X0 + real.(X), cert |
| 79 | +end |
| 80 | + |
| 81 | +function _verify_eigen(A, λ::Number, X0::AbstractVector; |
| 82 | + w=0.1, ϵ=floatmin(), maxiter=10) |
| 83 | + |
| 84 | + _, v = findmax(abs.(X0)) |
| 85 | + |
| 86 | + R = mid.(A) - λ * I |
| 87 | + R[:, v] .= -X0 |
| 88 | + R = inv(R) |
| 89 | + C = IA.Interval.(A) - λ * I |
| 90 | + Z = -R * (C * X0) |
| 91 | + C[:, v] .= -X0 |
| 92 | + C = I - R * C |
| 93 | + Zinfl = w * IA.Interval.(-mag.(Z), mag.(Z)) .+ IA.Interval(-ϵ, ϵ) |
| 94 | + |
| 95 | + X = Complex.(Z) |
| 96 | + cert = false |
| 97 | + @inbounds for _ in 1:maxiter |
| 98 | + Y = (real.(X) + Zinfl) + (imag.(X) + Zinfl) * im |
| 99 | + |
| 100 | + Ytmp = Y * Y[v] |
| 101 | + Ytmp[v] = 0 |
| 102 | + |
| 103 | + X = Z + C * Y + R * Ytmp |
| 104 | + cert = all(X .⊂ Y) |
| 105 | + cert && break |
| 106 | + end |
| 107 | + |
| 108 | + ρ = mag(X[v]) |
| 109 | + X[v] = 0 |
| 110 | + |
| 111 | + return ρ, X, cert |
| 112 | +end |
| 113 | + |
| 114 | + |
| 115 | +""" |
| 116 | + bound_perron_frobenius_eigenvalue(A, max_iter=10) |
| 117 | +
|
| 118 | +Finds an upper bound for the Perron-Frobenius eigenvalue of the **non-negative** matrix `A`. |
| 119 | +
|
| 120 | +### Input |
| 121 | +
|
| 122 | +- `A` -- square real non-negative matrix |
| 123 | +- `max_iter` -- maximum number of iterations of the power method used internally to compute |
| 124 | + an initial approximation of the Perron-Frobenius eigenvector |
| 125 | +
|
| 126 | +### Example |
| 127 | +
|
| 128 | +```julia-repl |
| 129 | +julia> A = [1 2;3 4] |
| 130 | +2×2 Matrix{Int64}: |
| 131 | + 1 2 |
| 132 | + 3 4 |
| 133 | +
|
| 134 | +julia> bound_perron_frobenius_eigenvalue(A) |
| 135 | +5.372281323275249 |
| 136 | +``` |
| 137 | +""" |
| 138 | +function bound_perron_frobenius_eigenvalue(A::AbstractMatrix{T}, max_iter=10) where {T<:Real} |
| 139 | + any(A .< 0) && throw(ArgumentError("Matrix contains negative entries")) |
| 140 | + return _bound_perron_frobenius_eigenvalue(A, max_iter) |
| 141 | +end |
| 142 | + |
| 143 | +function _bound_perron_frobenius_eigenvalue(M, max_iter=10) |
| 144 | + |
| 145 | + size(M, 1) == 1 && return M[1] |
| 146 | + xpf = IA.Interval.(_power_iteration(M, max_iter)) |
| 147 | + Mxpf = M * xpf |
| 148 | + ρ = zero(eltype(M)) |
| 149 | + @inbounds for (i, xi) in enumerate(xpf) |
| 150 | + iszero(xi) && continue |
| 151 | + tmp = Mxpf[i] / xi |
| 152 | + ρ = max(ρ, tmp.hi) |
| 153 | + end |
| 154 | + return ρ |
| 155 | +end |
| 156 | + |
| 157 | +function _power_iteration(A, max_iter) |
| 158 | + n = size(A,1) |
| 159 | + xp = rand(n) |
| 160 | + @inbounds for _ in 1:max_iter |
| 161 | + xp .= A*xp |
| 162 | + xp ./= norm(xp) |
| 163 | + end |
| 164 | + return xp |
| 165 | +end |
| 166 | + |
| 167 | + |
| 168 | +interval_eigtype(::Symmetric, ::T) where {T<:Real} = Interval{T} |
| 169 | +interval_eigtype(::AbstractMatrix, ::T) where {T<:Real} = Complex{Interval{T}} |
| 170 | +interval_eigtype(::AbstractMatrix, ::Complex{T}) where {T<:Real} = Complex{Interval{T}} |
0 commit comments