Skip to content

Commit

Permalink
Add cgls-shift algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigot committed Feb 3, 2024
1 parent 0379bf8 commit 62bc634
Show file tree
Hide file tree
Showing 17 changed files with 430 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ makedocs(
"CRAIG" => "examples/craig.md",
"CRAIGMR" => "examples/craigmr.md",
"CGLS" => "examples/cgls.md",
"CGLS-LANCZOS-SHIFT" => "examples/cgls_lanczos_shift.md",
"CRLS" => "examples/crls.md",
"LSQR" => "examples/lsqr.md",
"LSMR" => "examples/lsmr.md"],
Expand Down
1 change: 1 addition & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ BilqSolver
QmrSolver
BilqrSolver
CglsSolver
CglsLanczosShiftSolver
CrlsSolver
CgneSolver
CrmrSolver
Expand Down
35 changes: 35 additions & 0 deletions docs/src/examples/cgls_lanczos_shift.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# TODO

```@example cgls_lanczos_shift
using MatrixMarket, SuiteSparseMatrixCollection
using Krylov, LinearOperators
using LinearAlgebra, Printf
function residuals(A, b, shifts, x)
nshifts = length(shifts)
r = [ A' * (A * x - b) + shifts[i] * x[i] for i = 1 : nshifts ]
return r
end
ssmc = ssmc_db(verbose=false)
matrix = ssmc_matrices(ssmc, "HB", "well1033")
path = fetch_ssmc(matrix, format="MM")
A = MatrixMarket.mmread(joinpath(path[1], "$(matrix.name[1]).mtx"))
b = MatrixMarket.mmread(joinpath(path[1], "$(matrix.name[1])_b.mtx"))[:]
(m, n) = size(A)
@printf("System size: %d rows and %d columns\n", m, n)
# Define regularization parameters.
shifts = [1.0, 2.0, 3.0, 4.0]
(x, stats) = cgls_lanczos_shift(A, b, shifts)
show(stats)
r = residuals(A, b, shifts, x)
resids = map(norm, r) / norm(b)
@printf("CGLS: Relative residuals with shifts:\n")
for resid in resids
@printf(" %8.1e", resid)
end
@printf("\n")
```
2 changes: 1 addition & 1 deletion docs/src/inplace.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Given an operator `A` and a right-hand side `b`, you can create a `KrylovSolver`
For example, use `S = Vector{Float64}` if you want to solve linear systems in double precision on the CPU and `S = CuVector{Float32}` if you want to solve linear systems in single precision on an Nvidia GPU.

!!! note
`DiomSolver`, `FomSolver`, `DqgmresSolver`, `GmresSolver`, `BlockGmresSolver`, `FgmresSolver`, `GpmrSolver` and `CgLanczosShiftSolver` require an additional argument (`memory` or `nshifts`).
`DiomSolver`, `FomSolver`, `DqgmresSolver`, `GmresSolver`, `BlockGmresSolver`, `FgmresSolver`, `GpmrSolver`, `CgLanczosShiftSolver` and `CglsLanczosShiftSolver` require an additional argument (`memory` or `nshifts`).

The workspace is always the first argument of the in-place methods:

Expand Down
2 changes: 1 addition & 1 deletion docs/src/preconditioners.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ However, there is no need to specify $L$ and one may specify $P_c = LL^H$ or its

### Linear least-squares problems

Methods concerned: [`CGLS`](@ref cgls), [`CRLS`](@ref crls), [`LSLQ`](@ref lslq), [`LSQR`](@ref lsqr) and [`LSMR`](@ref lsmr).
Methods concerned: [`CGLS`](@ref cgls), [`CGLS-LANCZOS-SHIFT`](@ref cgls_lanczos_shift), [`CRLS`](@ref crls), [`LSLQ`](@ref lslq), [`LSQR`](@ref lsqr) and [`LSMR`](@ref lsmr).

| Formulation | Without preconditioning | With preconditioning |
|:---------------------:|:------------------------------------:|:-------------------------------------------:|
Expand Down
2 changes: 1 addition & 1 deletion docs/src/processes.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Note that depending on how we normalize the vectors that compose $V_k$, $T_{k+1,

The function [`hermitian_lanczos`](@ref hermitian_lanczos(::Any, ::AbstractVector{FC}, ::Int) where FC <: (Union{Complex{T}, T} where T <: AbstractFloat)) returns $V_{k+1}$, $\beta_1$ and $T_{k+1,k}$.

Related methods: [`SYMMLQ`](@ref symmlq), [`CG`](@ref cg), [`CR`](@ref cr), [`CAR`](@ref car), [`MINRES`](@ref minres), [`MINRES-QLP`](@ref minres_qlp), [`MINARES`](@ref minares), [`CGLS`](@ref cgls), [`CRLS`](@ref crls), [`CGNE`](@ref cgne), [`CRMR`](@ref crmr), [`CG-LANCZOS`](@ref cg_lanczos) and [`CG-LANCZOS-SHIFT`](@ref cg_lanczos_shift).
Related methods: [`SYMMLQ`](@ref symmlq), [`CG`](@ref cg), [`CR`](@ref cr), [`CAR`](@ref car), [`MINRES`](@ref minres), [`MINRES-QLP`](@ref minres_qlp), [`MINARES`](@ref minares), [`CGLS`](@ref cgls), [`CGLS-LANCZOS-SHIFT`](@ref cgls_lanczos_shift), [`CRLS`](@ref crls), [`CGNE`](@ref cgne), [`CRMR`](@ref crmr), [`CG-LANCZOS`](@ref cg_lanczos) and [`CG-LANCZOS-SHIFT`](@ref cg_lanczos_shift).

```@docs
hermitian_lanczos(::Any, ::AbstractVector{FC}, ::Int) where FC <: (Union{Complex{T}, T} where T <: AbstractFloat)
Expand Down
2 changes: 2 additions & 0 deletions docs/src/solvers/ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
```@docs
cgls
cgls!
cgls_lanczos_shift
cgls_lanczos_shift!
```

## CRLS
Expand Down
6 changes: 3 additions & 3 deletions docs/src/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ This section provides the storage requirements of all Krylov methods available i

We denote by $m$ and $n$ the number of rows and columns of the linear problem.
The memory parameter of DIOM, FOM, DQGMRES, GMRES, FGMRES and GPMR is $k$.
The numbers of shifts of CG-LANCZOS-SHIFT is $p$.
The numbers of shifts of CG-LANCZOS-SHIFT and CGLS-LANCZOS-SHIFT is $p$.

## Theoretical storage requirements

Expand Down Expand Up @@ -81,9 +81,9 @@ Each table summarizes the storage requirements of Krylov methods recommended to

#### Least-squares problems

| Methods | [`USYMQR`](@ref usymqr) | [`CGLS`](@ref cgls) | [`CRLS`](@ref crls) | [`LSLQ`](@ref lslq) | [`LSQR`](@ref lsqr) | [`LSMR`](@ref lsmr) |
| Methods | [`USYMQR`](@ref usymqr) | [`CGLS`](@ref cgls) | [`CG-LANCZOS-SHIFT`](@ref cg_lanczos_shift) | [`CRLS`](@ref crls) | [`LSLQ`](@ref lslq) | [`LSQR`](@ref lsqr) | [`LSMR`](@ref lsmr) |
|:-------:|:-----------------------:|:-------------------:|:-------------------:|:-------------------:|:-------------------:|:-------------------:|
| Storage | $6n + 3m$ | $3n + 2m$ | $4n + 3m$ | $4n + 2m$ | $4n + 2m$ | $5n + 2m$ |
| Storage | $6n + 3m$ | $3n + 2m$ | $3n + 2m + Xp$ | $4n + 3m$ | $4n + 2m$ | $4n + 2m$ | $5n + 2m$ |

#### Adjoint systems

Expand Down
1 change: 1 addition & 0 deletions src/Krylov.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ include("qmr.jl")
include("bilqr.jl")

include("cgls.jl")
include("cgls_lanczos_shift.jl")
include("crls.jl")

include("cgne.jl")
Expand Down
Loading

0 comments on commit 62bc634

Please sign in to comment.