Skip to content

Commit

Permalink
Update row probabiltiies to weight prodop
Browse files Browse the repository at this point in the history
Only compute probabilities if they will be needed and reformulate the computation based on rownom², s.t. the code there can be reused
  • Loading branch information
nHackel committed Feb 20, 2024
1 parent ace388d commit eb8b66d
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/Kaczmarz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ function Kaczmarz(A
# setup denom and rowindex
denom, rowindex = initkaczmarz(A, λ(L2))

Check warning on line 87 in src/Kaczmarz.jl

View check run for this annotation

Codecov / codecov/patch

src/Kaczmarz.jl#L87

Added line #L87 was not covered by tests
rowIndexCycle = collect(1:length(rowindex))
probabilities = T.(rowProbabilities(A, rowindex))
probabilities = eltype(denom)[]
if randomized
probabilities = T.(rowProbabilities(A, rowindex))

Check warning on line 91 in src/Kaczmarz.jl

View check run for this annotation

Codecov / codecov/patch

src/Kaczmarz.jl#L89-L91

Added lines #L89 - L91 were not covered by tests
end

M,N = size(A)
subMatrixSize = round(Int, subMatrixFraction*M)
Expand Down Expand Up @@ -120,7 +123,9 @@ function init!(solver::Kaczmarz, b; x0 = 0)
if λ_ != λ_prev
solver.denom, solver.rowindex = initkaczmarz(solver.A, λ_)
solver.rowIndexCycle = collect(1:length(rowindex))
solver.probabilities = T.(rowProbabilities(solver.A, rowindex))
if solver.randomized
solver.probabilities = T.(rowProbabilities(solver.A, rowindex))

Check warning on line 127 in src/Kaczmarz.jl

View check run for this annotation

Codecov / codecov/patch

src/Kaczmarz.jl#L123-L127

Added lines #L123 - L127 were not covered by tests
end
end

if solver.shuffleRows || solver.randomized
Expand Down Expand Up @@ -184,20 +189,16 @@ end
This function calculates the probabilities of the rows of the system matrix
"""

function rowProbabilities(A::AbstractMatrix, rowindex)
M,N = size(A)
normS = norm(A)^2
function rowProbabilities(A, rowindex)
normA² = rownorm²(A, 1:size(A, 1))

Check warning on line 193 in src/Kaczmarz.jl

View check run for this annotation

Codecov / codecov/patch

src/Kaczmarz.jl#L192-L193

Added lines #L192 - L193 were not covered by tests
p = zeros(length(rowindex))
for i=1:length(rowindex)
j = rowindex[i]
p[i] = (norm(A[j,:]))^2 / (normS)
p[i] = rownorm²(A, j) / (normA²)

Check warning on line 197 in src/Kaczmarz.jl

View check run for this annotation

Codecov / codecov/patch

src/Kaczmarz.jl#L197

Added line #L197 was not covered by tests
end

return p
end

rowProbabilities(A::AbstractLinearOperator, rowindex) = rowProbabilities(Matrix(A[rowindex, :]), 1:length(rowindex))
rowProbabilities(A::ProdOp{T, <:WeightingOp, matT}, rowindex) where {T, matT} = rowProbabilities(A.B, rowindex)

### initkaczmarz ###

Expand Down

0 comments on commit eb8b66d

Please sign in to comment.