-
Notifications
You must be signed in to change notification settings - Fork 9
add NullRegularizer #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MaxenceGollier
wants to merge
12
commits into
JuliaSmoothOptimizers:master
Choose a base branch
from
MaxenceGollier:null-regularizer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add NullRegularizer #156
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d3331e5
add NullRegularizer
MaxenceGollier e5de4b6
add iprox for null regularizer
MaxenceGollier da702d0
rename variables
MaxenceGollier dd8843c
add null regularizer box
MaxenceGollier 0e3e465
use the prox_zero and iprox_zero functions
MaxenceGollier 6489190
update iprox!
MaxenceGollier b8c0825
remove constructor
MaxenceGollier 565914b
add shiftedNullBox regularizer
MaxenceGollier cbb4315
add allocation tests
MaxenceGollier 55e05e7
fix allocation tests
MaxenceGollier 650b0a6
add parametric type
MaxenceGollier 6b45e45
add shifted constructor with selected argument
MaxenceGollier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # Null regularizer | ||
| export NullRegularizer | ||
|
|
||
| @doc raw""" | ||
| NullRegularizer(::Type{T}) where {T <: Real} | ||
| NullRegularizer(lambda::T) where {T <: Real} | ||
|
|
||
|
|
||
| Returns the null regularizer, i.e., the function that is identically zero. | ||
| ```math | ||
| h(x) = 0 | ||
| ``` | ||
|
|
||
| ### Arguments | ||
| - `T`: The type of zero that is expected to be returned by the regularizer. | ||
|
|
||
| In the second constructor, the type of lambda is used to infer the type of zero that is expected to be returned by the regularizer. The value of lambda is ignored. | ||
| """ | ||
| struct NullRegularizer{T <: Real} <: ShiftedProximableFunction end | ||
|
|
||
| NullRegularizer(lambda::T) where {T <: Real} = NullRegularizer{T}() | ||
| NullRegularizer(::Type{T}) where {T <: Real} = NullRegularizer{T}() | ||
|
|
||
| shifted(h::NullRegularizer{T}, xk::AbstractVector{T}) where {T <: Real} = | ||
| NullRegularizer(T) | ||
|
|
||
| function shift!(h::NullRegularizer{T}, xk::AbstractVector{T}) where {T <: Real} | ||
| return h | ||
| end | ||
|
|
||
| function (h::NullRegularizer{T})(y) where {T <: Real} | ||
| return zero(T) | ||
| end | ||
|
|
||
| fun_name(h::NullRegularizer{T}) where {T <: Real} = "null regularizer" | ||
| fun_expr(h::NullRegularizer{T}) where {T <: Real} = "t ↦ 0" | ||
| fun_params(h::NullRegularizer{T}) where {T <: Real} = "" | ||
|
|
||
| function Base.show(io::IO, h::NullRegularizer{T}) where {T <: Real} | ||
| println(io, "description : ", fun_name(h)) | ||
| println(io, "expression : ", fun_expr(h)) | ||
| println(io, "parameters : ", fun_params(h)) | ||
| end | ||
|
|
||
| function prox!( | ||
| y::AbstractVector{T}, | ||
| h::NullRegularizer{T}, | ||
| q::AbstractVector{T}, | ||
| ν::T | ||
| ) where {T <: Real} | ||
| @assert ν > zero(T) | ||
| y .= q | ||
| return y | ||
| end | ||
|
|
||
| function iprox!( | ||
| y::AbstractVector{T}, | ||
| h::NullRegularizer{T}, | ||
| g::AbstractVector{T}, | ||
| d::AbstractVector{T}, | ||
| ) where {T <: Real} | ||
| @inbounds for i ∈ eachindex(y) | ||
| @assert d[i] > 0 | ||
| y[i] = - g[i] / d[i] | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # Null box regularizer | ||
| export ShiftedNullRegularizerBox | ||
|
|
||
| @doc raw""" | ||
| ShiftedNullRegularizerBox(h, sj, shifted_twice, l, u) | ||
|
|
||
| Returns the shifted box null regularizer, i.e., the function that is identically zero on a box and +∞ outside of it. | ||
| ```math | ||
| ψ(x) = h(xk + sj + x) + \chi(sj + x | [l, u]) | ||
| ``` | ||
| where `h` is identically zero, `xk`represents a shift, `sj` is an additional shift that is applied to the indicator | ||
| function as well and `[l, u]` is the box that defines the domain of the function. | ||
|
|
||
| ### Arguments | ||
| - `h`: The unshifted null regularizer (see `NullRegularizer`). | ||
| - `sj`: The shift of the indicator function. | ||
| - `shifted_twice`: A boolean indicating whether `sj` is updated or not on shifts, true means that `sj` is updated, false means that `xk` is updated. | ||
| - `l`: The lower bound of the box. | ||
| - `u`: The upper bound of the box. | ||
| """ | ||
| mutable struct ShiftedNullRegularizerBox{T <: Real, V <: AbstractVector{T}, VT <: Union{AbstractVector{T}, T}} <: ShiftedProximableFunction | ||
| h::NullRegularizer{T} | ||
| sj::V | ||
| shifted_twice::Bool | ||
| l::VT | ||
| u::VT | ||
|
|
||
| function ShiftedNullRegularizerBox( | ||
| h::NullRegularizer{T}, | ||
| sj::V, | ||
| shifted_twice::Bool, | ||
| l::VT, | ||
| u::VT, | ||
| ) where {T <: Real, V <: AbstractVector{T}, VT <: Union{AbstractVector{T}, T}} | ||
| new{T, V, VT}(h, sj, shifted_twice, l, u) | ||
| end | ||
| end | ||
|
|
||
| shifted( | ||
| h::NullRegularizer{T}, | ||
| xk::AbstractVector{T}, | ||
| l, | ||
| u, | ||
| selected::AbstractArray{I} = 1:length(xk), | ||
| ) where {T <: Real, I <: Integer} = shifted(h, xk, l, u) | ||
| shifted( | ||
| h::NullRegularizer{T}, | ||
| xk::AbstractVector{T}, | ||
| l::VT, | ||
| u::VT, | ||
| ) where {T <: Real, VT} = ShiftedNullRegularizerBox(h, zero(xk), false, l, u) | ||
| shifted( | ||
| h::NullRegularizer{T}, | ||
| xk::AbstractVector{T}, | ||
| Δ::T, | ||
| χ::Conjugate{IndBallL1{T}}, | ||
| ) where {T <: Real} = ShiftedNullRegularizerBox(h, zero(xk), false, -Δ, Δ) | ||
| shifted( | ||
| ψ::ShiftedNullRegularizerBox{T, V, VT}, | ||
| sj::AbstractVector{T}, | ||
| ) where {T <: Real, V <: AbstractVector{T}, VT} = ShiftedNullRegularizerBox(ψ.h, sj, true, ψ.l, ψ.u) | ||
|
|
||
| function shift!(ψ::ShiftedNullRegularizerBox{T, V, VT}, shift::AbstractVector{T}) where {T <: Real, V <: AbstractVector{T}, VT} | ||
| ψ.shifted_twice && (ψ.sj .= shift) | ||
| end | ||
|
|
||
| function (ψ::ShiftedNullRegularizerBox{T, V})(y) where {T <: Real, V <: AbstractVector{T}} | ||
| ϵ = √eps(eltype(y)) | ||
| @inbounds for i in eachindex(y) | ||
| l = ψ.l isa AbstractVector ? ψ.l[i] : ψ.l | ||
| u = ψ.u isa AbstractVector ? ψ.u[i] : ψ.u | ||
| if !(l - ϵ ≤ ψ.sj[i] + y[i] ≤ u + ϵ) | ||
| return T(Inf) | ||
| end | ||
| end | ||
| return zero(T) | ||
| end | ||
|
|
||
| fun_name(ψ::ShiftedNullRegularizerBox{T, V}) where {T <: Real, V <: AbstractVector{T}} = "shifted null regularizer with box indicator" | ||
| fun_expr(ψ::ShiftedNullRegularizerBox{T, V}) where {T <: Real, V <: AbstractVector{T}} = "t ↦ χ({sj + t .∈ [l,u]})" | ||
| fun_params(ψ::ShiftedNullRegularizerBox{T, V}) where {T <: Real, V <: AbstractVector{T}} = | ||
| "sj = $(ψ.sj)\n" * " "^14 * "l = $(ψ.l)\n" * " "^14 * "u = $(ψ.u)" | ||
|
|
||
| function prox!( | ||
| y::AbstractVector{T}, | ||
| ψ::ShiftedNullRegularizerBox{T, V}, | ||
| q::AbstractVector{T}, | ||
| σ::T, | ||
| ) where {T <: Real, V <: AbstractVector{T}} | ||
| @assert σ > zero(T) | ||
| @inbounds for i ∈ eachindex(y) | ||
| l = ψ.l isa AbstractVector ? ψ.l[i] : ψ.l | ||
| u = ψ.u isa AbstractVector ? ψ.u[i] : ψ.u | ||
| y[i] = prox_zero(q[i], l - ψ.sj[i], u - ψ.sj[i]) | ||
| end | ||
| return y | ||
| end | ||
|
|
||
| function iprox!( | ||
| y::AbstractVector{T}, | ||
| ψ::ShiftedNullRegularizerBox{T, V}, | ||
| g::AbstractVector{T}, | ||
| d::AbstractVector{T}, | ||
| ) where {T <: Real, V <: AbstractVector{T}} | ||
| @inbounds for i ∈ eachindex(y) | ||
| l = ψ.l isa AbstractVector ? ψ.l[i] : ψ.l | ||
| u = ψ.u isa AbstractVector ? ψ.u[i] : ψ.u | ||
| y[i] = iprox_zero(d[i], g[i], l - ψ.sj[i], u - ψ.sj[i]) | ||
| end | ||
| return y | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.