Skip to content

group norm prox updates from r1 #116

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
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 27 additions & 25 deletions src/shiftedGroupNormL2Binf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ end

function (ψ::ShiftedGroupNormL2Binf)(y)
@. ψ.xsy = ψ.sj + y
indball_val = IndBallLinf(1.1 * ψ.Δ)(ψ.xsy)
indball_val = IndBallLinf(1.01 * ψ.Δ)(ψ.xsy)
ψ.xsy .+= ψ.xk
return ψ.h(ψ.xsy) + indball_val
end
Expand Down Expand Up @@ -78,40 +78,42 @@ function prox!(
V2 <: AbstractVector{R},
}
ψ.sol .= q .+ ψ.xk .+ ψ.sj
ϵ = 1 ## sasha's initial guess

softthres(x, a) = sign.(x) .* max.(0, abs.(x) .- a)
l2prox(x, a) = max(0, 1 - a / norm(x)) .* x
linfproj(x) = max.(-ψ.Δ, min.(ψ.Δ, x))
for (idx, λ) ∈ zip(ψ.h.idx, ψ.h.lambda)
σλ = λ * σ
## find root for each block
froot(n) =
n - norm(
σ .* softthres(
(ψ.sol[idx] ./ σ .- (n / (σ * (n - σλ))) .* ψ.xk[idx]),
ψ.Δ * (n / (σ * (n - σλ))),
) .- ψ.sol[idx],
(n / (n - σλ)) .* (
ψ.xk[idx] .+ linfproj(
((n - σλ)/n) .* ψ.sol[idx] .- ψ.xk[idx]
)
)
)
lmin = σλ * (1 + eps(R)) # lower bound
fl = froot(lmin)

ansatz = lmin + ϵ #ansatz for upper bound
step = ansatz / (σ * (ansatz - σλ))
zlmax = norm(softthres((ψ.sol[idx] ./ σ .- step .* ψ.xk[idx]), ψ.Δ * step))
lmax = norm(ψ.sol[idx]) + σ * (zlmax + abs((ϵ - 1) / ϵ + 1) * λ * norm(ψ.xk[idx]))
fm = froot(lmax)
if fl * fm > 0
xlength = length(ψ.xk[idx])
xnorminf = ψ.χ(ψ.xk[idx])
xnorm = norm(ψ.xk[idx])
qnorm = norm(ψ.sol[idx])
qproj = sum(linfproj(ψ.sol[idx] .- ψ.xk[idx]) - ψ.xk[idx])
τ = 1e4*eps(R)
n = NaN
if xnorminf > ψ.Δ #case 1
n = find_zero(froot, (σλ + xnorminf - ψ.Δ, σλ + xnorm + ψ.Δ*√xlength), Roots.A42())
elseif qnorm > σλ && xnorminf < ψ.Δ #case 2a
n = find_zero(froot, (σλ + τ, qnorm + xnorm + ψ.Δ*√xlength), Roots.A42())
elseif qnorm > σλ && xnorm ≈ ψ.Δ && qproj ≈ 0.0 #case 4a
n = find_zero(froot, (σλ + τ, min(σλ + xnorm + ψ.Δ*sqrt(n), qnorm)), Roots.A42())
end
if isnan(n)
y[idx] .= 0
else
n = fzero(froot, lmin, lmax)
step = n / (σ * (n - σλ))
if abs(n - σλ) ≈ 0
y[idx] .= 0
else
y[idx] .= l2prox(
ψ.sol[idx] .- σ .* softthres((ψ.sol[idx] ./ σ .- step .* ψ.xk[idx]), ψ.Δ * step),
σλ,
)
end
y[idx] .= l2prox(
ψ.sol[idx] .- σ .* softthres((ψ.sol[idx] ./ σ .- step .* ψ.xk[idx]), ψ.Δ * step),
σλ,
)
end
y[idx] .-= (ψ.xk[idx] + ψ.sj[idx])
end
Expand Down