© 2013---2015 The Contributors. Released under the MIT License.
IterativeSolvers
is a Julia package that provides flexible iterative algorithms for linear algebra.
This package provides iterative algorithms for solving linear systems, eigensystems, and singular value problems which are implemented with maximal flexibility without sacrificing performance.
-
Issue #1 documents the implementation roadmap for iterative solvers.
-
The interfaces between the various algorithms are still in flux, but aim to be consistent.
-
Issue #33 documents the implementation roadmap for randomized algorithms.
- All randomized algorithms start with
r_
. - All linear solvers do not have a prefix. Routines that accept preconditioners do not take a
p
prefix, e.g.cg
instead ofpcg
. - All other eigenvalue solvers start with
eigvals_
. - All other singular value solvers start with
svdvals_
.
-
All linear-algebraic routines will take as input a linear operator
A
that maps n-dimensional vectors to n-dimensional vectors.A
is not explicitly typed, but must either be aKrylovSubspace
or support multiplication*
or function composition (apply
) that behave as necessary to produce the correct mapping on the vector space. -
All linear solvers have a common function declaration
solver(A, b::Vector, [x, Pl, Pr, varargs...]; tol::Real, maxiter::Int, kwargs...)
A
is aKrylovSubspace
or linear operator as described above.b
is the vector to be solvedx
is a vector for the initial guess (if not specified, defaults to random unit vector on the unit hypersphere)Pl
is the (left) preconditioner (for routines that accept them)Pr
is the right preconditioner (for routines that accept them)tol
is the threshold for determining convergence (which is typically compared to the norm of the residual vector, but whose semantics may vary from solver to solver) and conventionally defaults tosize(A,1)^3*eps()
maxiter
is the maximum number of allowed iterations, which conventionally defaults tolength(b)
- additional
varargs
andkwargs
as necessary.
-
All linear solvers have a common return format
x::Vector
, the solution vectorh::ConvergenceHistory
, a special data type returning the convergence history as discussed in Issue #6
The KrylovSubspace
type collects information on the Krylov subspace generated over the course of an iterative Krylov solver.
Recall that the Krylov subspace of order r
given a starting vector b
and a linear operator A
is spanned by the vectors [b, A*b, A^2*b,... A^(r-1)*b]
. Many modern iterative solvers work on Krylov spaces which expand until they span enough of the range of A
for the solution vector to converge. Most practical algorithms, however, will truncate the order of the Krylov subspace to save memory and control the accumulation of roundoff errors. Additionally, they do not work directly with the raw iterates A^n*b
, but will orthogonalize subsequent vectors as they are computed so as to improve numerical stability. KrylovSubspace
s provide a natural framework to express operations such as a (possibly non-orthonormalized) basis for the Krylov subspace, retrieving the next vector in the subspace, and orthogonalizing an arbitrary vector against (part or all of) the subspace.
The implementation of KrylovSubspace
in this package differs from standard textbook presentations of iterative solvers. First, the KrylovSubspace
type shows clearly the relationship between the linear operator A
and the sequence of basis vectors for the Krylov subspace that is generated by each new iteration. Second, the grouping together of basis vectors also makes the orthogonalization steps in each iteration routine clearer. Third, unlike in other languages, the powerful type system of Julia allows for a simplified notation for iterative algorithms without compromising on performance, and enhances code reuse across multiple solvers.
A KrylovSubspace
can be initialized by three constructors, depending on the type of the linear operator:
KrylovSubspace{T}(A::AbstractMatrix{T}, [order::Int, v::Vector{Vector{T}}])
KrylovSubspace{T}(A::KrylovSubspace{T}, [order::Int, v::Vector{Vector{T}}])
KrylovSubspace(A, n::Int, [order::Int, v::Vector{Vector{T}}])
-
A
: The linear operator associated with theKrylovSubspace
. -
order
: the order of theKrylovSubspace
, i.e. the maximal number of Krylov vectors to remember. -
n
: the dimensionality of the underlying vector spaceT^n
. -
v
: the iterable collection of Krylov vectors (of maximal lengthorder
).The dimensionality of the underlying vector space is automatically inferred where possible, i.e. when the linear operator is an
AbstractMatrix
orKrylovSubspace
. (Note: the second constructor destroys the oldKrylovSubspace
.)
A ConvergenceHistory
type provides information about the iteration history. Currently, ConvergenceHistory
provides:
isconverged::Bool
, a flag for whether or not the algorithm is convergedthreshold
, the convergence thresholdresiduals::Vector
, the value of the convergence criteria at each iteration
Note: No warning or error is thrown when the solution is not converged. The user is expected to check convergence manually via the .isconverged
field.
Orthogonalizing the basis vectors for a KrylovSubspace
is crucial for numerical stability, and is a core low-level operation for many iterative solvers.
orthogonalize{T}(v::Vector{T}, K::KrylovSubspace{T}, [p::Int]; [method::Symbol], [normalize::Bool])
v
: The vector to orthogonalizeK
: TheKrylovSubspace
to orthogonalize againstp
: The number of Krylov vectors to orthogonalize against (the default is all available)method
: Orthogonalization method. Currently supported methods are::GramSchmidt
. Not recommended, as it is numerically unstable.:ModifiedGramSchmidt
. (default):Householder
. This is actually the same as:ModifiedGramSchmidt
.