Skip to content

Commit a4cc680

Browse files
authored
Add an implementation of cgls-shift (#853)
1 parent 902ee6a commit a4cc680

21 files changed

+527
-55
lines changed

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ makedocs(
4646
"CRAIG" => "examples/craig.md",
4747
"CRAIGMR" => "examples/craigmr.md",
4848
"CGLS" => "examples/cgls.md",
49+
"CGLS-LANCZOS-SHIFT" => "examples/cgls_lanczos_shift.md",
4950
"CRLS" => "examples/crls.md",
5051
"LSQR" => "examples/lsqr.md",
5152
"LSMR" => "examples/lsmr.md"],

docs/src/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ BilqSolver
4141
QmrSolver
4242
BilqrSolver
4343
CglsSolver
44+
CglsLanczosShiftSolver
4445
CrlsSolver
4546
CgneSolver
4647
CrmrSolver
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
```@example cgls_lanczos_shift
2+
using MatrixMarket, SuiteSparseMatrixCollection
3+
using Krylov, LinearOperators
4+
using LinearAlgebra, Printf
5+
6+
function residuals(A, b, shifts, x)
7+
nshifts = length(shifts)
8+
r = [ A' * (A * x[i] - b) + shifts[i] * x[i] for i = 1 : nshifts ]
9+
return r
10+
end
11+
ssmc = ssmc_db(verbose=false)
12+
matrix = ssmc_matrices(ssmc, "HB", "well1033")
13+
path = fetch_ssmc(matrix, format="MM")
14+
15+
A = MatrixMarket.mmread(joinpath(path[1], "$(matrix.name[1]).mtx"))
16+
b = MatrixMarket.mmread(joinpath(path[1], "$(matrix.name[1])_b.mtx"))[:]
17+
(m, n) = size(A)
18+
@printf("System size: %d rows and %d columns\n", m, n)
19+
20+
# Define regularization parameters.
21+
shifts = [1.0, 2.0, 3.0, 4.0]
22+
23+
(x, stats) = cgls_lanczos_shift(A, b, shifts)
24+
show(stats)
25+
r = residuals(A, b, shifts, x)
26+
27+
resids = map(norm, r) / norm(b)
28+
@printf("CGLS: Relative residuals with shifts:\n")
29+
for resid in resids
30+
@printf(" %8.1e", resid)
31+
end
32+
@printf("\n")
33+
```

docs/src/inplace.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Given an operator `A` and a right-hand side `b`, you can create a `KrylovSolver`
1616
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.
1717

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

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

docs/src/matrix_free.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Some methods only require `A * v` products, whereas other ones also require `A'
4141
| SYMMLQ, CG-LANCZOS, MINRES, MINRES-QLP, MINARES | LSLQ, LSQR, LSMR, LNLQ, CRAIG, CRAIGMR |
4242
| DIOM, FOM, DQGMRES, GMRES, FGMRES, BLOCK-GMRES | BiLQ, QMR, BiLQR, USYMLQ, USYMQR, TriLQR |
4343
| CGS, BICGSTAB | TriCG, TriMR |
44+
| CG-LANCZOS-SHIFT | CGLS-LANCZOS-SHIFT |
4445

4546
!!! info
4647
GPMR is the only method that requires `A * v` and `B * w` products.

docs/src/preconditioners.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ However, there is no need to specify $L$ and one may specify $P_c = LL^H$ or its
6161

6262
### Linear least-squares problems
6363

64-
Methods concerned: [`CGLS`](@ref cgls), [`CRLS`](@ref crls), [`LSLQ`](@ref lslq), [`LSQR`](@ref lsqr) and [`LSMR`](@ref lsmr).
64+
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).
6565

6666
| Formulation | Without preconditioning | With preconditioning |
6767
|:---------------------:|:------------------------------------:|:-------------------------------------------:|

docs/src/processes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Note that depending on how we normalize the vectors that compose $V_k$, $T_{k+1,
9191

9292
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}$.
9393

94-
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).
94+
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).
9595

9696
```@docs
9797
hermitian_lanczos(::Any, ::AbstractVector{FC}, ::Int) where FC <: (Union{Complex{T}, T} where T <: AbstractFloat)

docs/src/solvers/ls.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ cgls
99
cgls!
1010
```
1111

12+
## CGLS-LANCZOS-SHIFT
13+
14+
```@docs
15+
cgls_lanczos_shift
16+
cgls_lanczos_shift!
17+
```
18+
1219
## CRLS
1320

1421
```@docs

docs/src/storage.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ This section provides the storage requirements of all Krylov methods available i
3939

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

4444
## Theoretical storage requirements
4545

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

8282
#### Least-squares problems
8383

84-
| Methods | [`USYMQR`](@ref usymqr) | [`CGLS`](@ref cgls) | [`CRLS`](@ref crls) | [`LSLQ`](@ref lslq) | [`LSQR`](@ref lsqr) | [`LSMR`](@ref lsmr) |
85-
|:-------:|:-----------------------:|:-------------------:|:-------------------:|:-------------------:|:-------------------:|:-------------------:|
86-
| Storage | $6n + 3m$ | $3n + 2m$ | $4n + 3m$ | $4n + 2m$ | $4n + 2m$ | $5n + 2m$ |
84+
| 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) |
85+
|:-------:|:-----------------------:|:-------------------:|:-------------------------------------------:|:-------------------:|:-------------------:|:-------------------:|
86+
| Storage | $6n + 3m$ | $3n + 2m$ | $3n + 2m + 5p + 2np$ | $4n + 3m$ | $4n + 2m$ | $4n + 2m$ | $5n + 2m$ |
8787

8888
#### Adjoint systems
8989

src/Krylov.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ include("car.jl")
2020

2121
include("symmlq.jl")
2222
include("cg_lanczos.jl")
23-
include("cg_lanczos_shift.jl")
2423
include("minres.jl")
2524
include("minres_qlp.jl")
2625
include("minares.jl")
@@ -60,5 +59,8 @@ include("lnlq.jl")
6059
include("craig.jl")
6160
include("craigmr.jl")
6261

62+
include("cg_lanczos_shift.jl")
63+
include("cgls_lanczos_shift.jl")
64+
6365
include("krylov_solve.jl")
6466
end

0 commit comments

Comments
 (0)