diff --git a/docs/src/API/regularization.md b/docs/src/API/regularization.md index 3887043b..5f880d18 100644 --- a/docs/src/API/regularization.md +++ b/docs/src/API/regularization.md @@ -4,7 +4,7 @@ REPL one can access this documentation by entering the help mode with `?` ```@docs RegularizedLeastSquares.L1Regularization -RegularizedLeastSquares.L2Regularization +RegularizedLeastSquares.SqrL2Regularization RegularizedLeastSquares.L21Regularization RegularizedLeastSquares.LLRRegularization RegularizedLeastSquares.NuclearRegularization diff --git a/docs/src/regularization.md b/docs/src/regularization.md index ddcb3281..559c128d 100644 --- a/docs/src/regularization.md +++ b/docs/src/regularization.md @@ -26,8 +26,8 @@ This group of regularization terms features a regularization parameter `λ` that These terms are constructed by supplying a `λ` and optionally term specific keyword arguments: ```jldoctest l2 -julia> l2 = L2Regularization(0.3) -L2Regularization{Float64}(0.3) +julia> l2 = SqrL2Regularization(0.3) +SqrL2Regularization{Float64}(0.3) ``` Parameterized regularization terms implement: ```julia diff --git a/src/Direct.jl b/src/Direct.jl index 117dd6d5..b54c5b96 100644 --- a/src/Direct.jl +++ b/src/Direct.jl @@ -12,11 +12,11 @@ mutable struct DirectSolver{matT,vecT, R, PR} <: AbstractDirectSolver proj::Vector{PR} end -function DirectSolver(A; reg::Vector{<:AbstractRegularization} = [L2Regularization(zero(real(eltype(A))))], normalizeReg::AbstractRegularizationNormalization = NoNormalization()) +function DirectSolver(A; reg::Vector{<:AbstractRegularization} = [SqrL2Regularization(zero(real(eltype(A))))], normalizeReg::AbstractRegularizationNormalization = NoNormalization()) reg = normalize(DirectSolver, normalizeReg, reg, A, nothing) - idx = findsink(L2Regularization, reg) + idx = findsink(SqrL2Regularization, reg) if isnothing(idx) - L2 = L2Regularization(zero(T)) + L2 = SqrL2Regularization(zero(T)) else L2 = reg[idx] deleteat!(reg, idx) @@ -98,11 +98,11 @@ mutable struct PseudoInverse{R, vecT, PR} <: AbstractDirectSolver proj::Vector{PR} end -function PseudoInverse(A; reg::Vector{<:AbstractRegularization} = [L2Regularization(zero(real(eltype(A))))], normalizeReg::AbstractRegularizationNormalization = NoNormalization()) +function PseudoInverse(A; reg::Vector{<:AbstractRegularization} = [SqrL2Regularization(zero(real(eltype(A))))], normalizeReg::AbstractRegularizationNormalization = NoNormalization()) reg = normalize(PseudoInverse, normalizeReg, reg, A, nothing) - idx = findsink(L2Regularization, reg) + idx = findsink(SqrL2Regularization, reg) if isnothing(idx) - L2 = L2Regularization(zero(T)) + L2 = SqrL2Regularization(zero(T)) else L2 = reg[idx] deleteat!(reg, idx) diff --git a/src/Kaczmarz.jl b/src/Kaczmarz.jl index c751e41f..abb34e6f 100644 --- a/src/Kaczmarz.jl +++ b/src/Kaczmarz.jl @@ -26,7 +26,7 @@ mutable struct Kaczmarz{matT,T,U,R,RN} <: AbstractRowActionSolver end """ - Kaczmarz(A; reg = L2Regularization(0), normalizeReg = NoNormalization(), weights=nothing, randomized=false, subMatrixFraction=0.15, shuffleRows=false, seed=1234, iterations=10, regMatrix=nothing) + Kaczmarz(A; reg = SqrL2Regularization(0), normalizeReg = NoNormalization(), weights=nothing, randomized=false, subMatrixFraction=0.15, shuffleRows=false, seed=1234, iterations=10, regMatrix=nothing) Creates a Kaczmarz object for the forward operator `A`. @@ -46,7 +46,7 @@ Creates a Kaczmarz object for the forward operator `A`. See also [`createLinearSolver`](@ref), [`solve!`](@ref). """ function Kaczmarz(A - ; reg = L2Regularization(0) + ; reg = SqrL2Regularization(0) , normalizeReg::AbstractRegularizationNormalization = NoNormalization() , weights = nothing , randomized::Bool = false @@ -68,9 +68,9 @@ function Kaczmarz(A # Prepare regularization terms reg = isa(reg, AbstractVector) ? reg : [reg] reg = normalize(Kaczmarz, normalizeReg, reg, A, nothing) - idx = findsink(L2Regularization, reg) + idx = findsink(SqrL2Regularization, reg) if isnothing(idx) - L2 = L2Regularization(zero(T)) + L2 = SqrL2Regularization(zero(T)) else L2 = reg[idx] deleteat!(reg, idx) diff --git a/src/RegularizedLeastSquares.jl b/src/RegularizedLeastSquares.jl index 3236ac8e..0a96b9a6 100644 --- a/src/RegularizedLeastSquares.jl +++ b/src/RegularizedLeastSquares.jl @@ -202,7 +202,7 @@ isapplicable(::Type{T}, reg::Vector{<:AbstractRegularization}) where T <: Abstra function isapplicable(::Type{T}, reg::Vector{<:AbstractRegularization}) where T <: AbstractRowActionSolver applicable = true applicable &= length(findsinks(AbstractParameterizedRegularization, reg)) <= 2 - applicable &= length(findsinks(L2Regularization, reg)) == 1 + applicable &= length(findsinks(SqrL2Regularization, reg)) == 1 return applicable end diff --git a/src/proximalMaps/ProxL2.jl b/src/proximalMaps/ProxL2.jl index 8e000354..35567e91 100644 --- a/src/proximalMaps/ProxL2.jl +++ b/src/proximalMaps/ProxL2.jl @@ -3,7 +3,7 @@ export L2Regularization """ L2Regularization -Regularization term implementing the proximal map for Tikhonov regularization. +Regularization term implementing the proximal map for `l_2` regularization. """ struct L2Regularization{T} <: AbstractParameterizedRegularization{T} λ::T @@ -12,11 +12,12 @@ end """ prox!(reg::L2Regularization, x, λ) - -performs the proximal map for Tikhonov regularization. + Tikhonov +performs the proximal map for `l_2` regularization. """ function prox!(::L2Regularization, x::AbstractArray{Tc}, λ::T) where {T, Tc <: Union{T, Complex{T}}} - x[:] .*= 1. / (1. + 2. *λ)#*x + scale = max(0, 1 - λ / norm(x)) + x[:] .*= scale return x end @@ -25,4 +26,4 @@ end returns the value of the L2-regularization term """ -norm(::L2Regularization, x::AbstractArray{Tc}, λ::T) where {T, Tc <: Union{T, Complex{T}}} = λ*norm(x,2)^2 +norm(::L2Regularization, x::AbstractArray{Tc}, λ::T) where {T, Tc <: Union{T, Complex{T}}} = λ*norm(x,2) diff --git a/src/proximalMaps/ProxSqrL2.jl b/src/proximalMaps/ProxSqrL2.jl new file mode 100644 index 00000000..401975aa --- /dev/null +++ b/src/proximalMaps/ProxSqrL2.jl @@ -0,0 +1,28 @@ +export SqrL2Regularization + +""" + SqrL2Regularization + +Regularization term implementing the proximal map for Tikhonov regularization. +""" +struct SqrL2Regularization{T} <: AbstractParameterizedRegularization{T} + λ::T + SqrL2Regularization(λ::T; kargs...) where T = new{T}(λ) +end + +""" + prox!(reg::SqrL2Regularization, x, λ) + +performs the proximal map for Tikhonov regularization. +""" +function prox!(::SqrL2Regularization, x::AbstractArray{Tc}, λ::T) where {T, Tc <: Union{T, Complex{T}}} + x[:] .*= 1. / (1. + 2. *λ)#*x + return x +end + +""" + norm(reg::SqrL2Regularization, x, λ) + +returns the value of the L2-regularization term +""" +norm(::SqrL2Regularization, x::AbstractArray{Tc}, λ::T) where {T, Tc <: Union{T, Complex{T}}} = λ*norm(x,2)^2 diff --git a/src/proximalMaps/ProximalMaps.jl b/src/proximalMaps/ProximalMaps.jl index bee0a2c3..de273784 100644 --- a/src/proximalMaps/ProximalMaps.jl +++ b/src/proximalMaps/ProximalMaps.jl @@ -1,5 +1,6 @@ include("ProxL1.jl") include("ProxL2.jl") +include("ProxSqrL2.jl") include("ProxL21.jl") include("ProxLLR.jl") # includes/ProxSLR.jl")