Skip to content

Commit

Permalink
Simplify Kaczmarz
Browse files Browse the repository at this point in the history
  • Loading branch information
nHackel committed Feb 19, 2024
1 parent e79c600 commit 29aa336
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/Kaczmarz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mutable struct Kaczmarz{matT,T,U,R,RN} <: AbstractRowActionSolver
rowIndexCycle::Vector{Int64}
x::Vector{T}
vl::Vector{T}
εw::Vector{T}
εw::T
τl::T
αl::T
randomized::Bool
Expand Down Expand Up @@ -94,7 +94,7 @@ function Kaczmarz(A
u = zeros(eltype(A),M)
x = zeros(eltype(A),N)
vl = zeros(eltype(A),M)
εw = zeros(eltype(A),length(rowindex))
εw = zero(eltype(A))

Check warning on line 97 in src/Kaczmarz.jl

View check run for this annotation

Codecov / codecov/patch

src/Kaczmarz.jl#L97

Added line #L97 was not covered by tests
τl = zero(eltype(A))
αl = zero(eltype(A))

Expand Down Expand Up @@ -134,14 +134,10 @@ function init!(solver::Kaczmarz, b; x0 = 0)
solver.x .= x0
solver.vl .= 0

weights = solverweights(solver)
solver.u .= b
for (i, weight) = enumerate(weights[solver.rowindex])
solver.ɛw[i] = sqrt(λ_)
end
solver.ɛw = sqrt(λ_)

Check warning on line 138 in src/Kaczmarz.jl

View check run for this annotation

Codecov / codecov/patch

src/Kaczmarz.jl#L137-L138

Added lines #L137 - L138 were not covered by tests
end

solverweights(::Type{<:Kaczmarz}, A::ProdOp{T, <:WeightingOp, matT}) where {T, matT} = A.A.weights

function solversolution(solver::Kaczmarz)
# backtransformation of solution with Tikhonov matrix
Expand Down Expand Up @@ -176,9 +172,9 @@ end
iterate_row_index(solver::Kaczmarz, A::AbstractLinearSolver, row, index) = iterate_row_index(solver, Matrix(A[row, :]), row, index)
function iterate_row_index(solver::Kaczmarz, A, row, index)
solver.τl = dot_with_matrix_row(A,solver.x,row)
solver.αl = solver.denom[index]*(solver.u[row]-solver.τl-solver.ɛw[index]*solver.vl[row])
solver.αl = solver.denom[index]*(solver.u[row]-solver.τl-solver.ɛw*solver.vl[row])
kaczmarz_update!(A,solver.x,row,solver.αl)
solver.vl[row] += solver.αl*solver.ɛw[index]
solver.vl[row] += solver.αl*solver.ɛw

Check warning on line 177 in src/Kaczmarz.jl

View check run for this annotation

Codecov / codecov/patch

src/Kaczmarz.jl#L172-L177

Added lines #L172 - L177 were not covered by tests
end

@inline done(solver::Kaczmarz,iteration::Int) = iteration>=solver.iterations
Expand Down Expand Up @@ -216,9 +212,8 @@ function initkaczmarz(A,λ)
denom = T[]
rowindex = Int64[]

weights = solverweights(Kaczmarz, A)
for (i, weight) in enumerate(weights)
= rownorm²(A,i)*weight^2
for i in size(A, 1)
= rownorm²(A,i)

Check warning on line 216 in src/Kaczmarz.jl

View check run for this annotation

Codecov / codecov/patch

src/Kaczmarz.jl#L215-L216

Added lines #L215 - L216 were not covered by tests
if>0
push!(denom,1/(s²+λ))

Check warning on line 218 in src/Kaczmarz.jl

View check run for this annotation

Codecov / codecov/patch

src/Kaczmarz.jl#L218

Added line #L218 was not covered by tests
push!(rowindex,i)
Expand Down

0 comments on commit 29aa336

Please sign in to comment.