Skip to content

Commit c149048

Browse files
authored
Ensure function value is finite for Static step (#101)
We should probably add some sort of debug / verbosity flag here to warn if this happens
1 parent 3c34346 commit c149048

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

src/backtracking.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,17 @@ function (ls::BackTracking)(ϕ, x::AbstractArray{T}, s::AbstractArray{T}, α_0::
5555

5656
ϕx_1 = ϕ(α_1)
5757

58+
# Hard-coded backtrack until we find a finite function value
5859
iterfinite = 0
59-
60-
# Backtrack until we satisfy sufficient decrease condition
6160
while !isfinite(ϕx_1) && iterfinite < iterfinitemax
6261
iterfinite += 1
6362
α_1 = α_2
6463
α_2 = α_1/2
6564

66-
# Backtrack until we satisfy sufficient decrease condition
6765
ϕx_1 = ϕ(α_2)
6866
end
6967

68+
# Backtrack until we satisfy sufficient decrease condition
7069
while ϕx_1 > ϕ_0 + c_1 * α_2 * dϕ_0
7170
# Increment the number of steps we've had to perform
7271
iteration += 1

src/static.jl

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,28 @@ function (ls::DeprecatedStatic)(df::AbstractObjective, x, s, α, x_new = similar
3232
ls(ϕ, x, s, α)
3333
end
3434

35-
function (ls::DeprecatedStatic)(ϕ, x, s, alpha)
36-
@unpack alpha, scaled = ls
37-
@assert alpha > zero(typeof(alpha)) # This should really be done at the constructor level
35+
function (ls::DeprecatedStatic)(ϕ, x, s, α::Tα) where
36+
@unpack α, scaled = ls
37+
@assert α > (0) # This should really be done at the constructor level
3838

39-
if scaled == true && (ns = vecnorm(s)) > zero(typeof(alpha))
40-
alpha = min(alpha, ns) / ns
39+
if scaled == true && (ns = vecnorm(s)) > (0)
40+
α = min(α, ns) / ns
4141
end
4242

43-
ϕα = ϕ(alpha)
43+
ϕα = ϕ(α)
4444

45-
return alpha, ϕα
45+
# Hard-coded backtrack until we find a finite function value
46+
iterfinite = 0
47+
iterfinitemax = -log2(eps(real(Tα)))
48+
while !isfinite(ϕα) && iterfinite < iterfinitemax
49+
iterfinite += 1
50+
αold = α
51+
α = αold/2
52+
53+
ϕα = ϕ(α)
54+
end
55+
56+
return α, ϕα
4657
end
4758
##########################
4859
## DELETE UNTIL THIS LINE
@@ -55,13 +66,25 @@ end
5566
"""
5667
immutable NewStatic end
5768

58-
function (ls::NewStatic)(df::AbstractObjective, x, s, α, x_new = similar(x), phi0 = nothing, dphi0 = nothing)
69+
function (ls::NewStatic)(df::AbstractObjective, x, s, α, x_new = similar(x), ϕ_0 = nothing, dϕ_0 = nothing)
5970
ϕ = make_ϕ(df, x_new, x, s)
6071
ls(ϕ, x, s, α)
6172
end
6273

63-
function (ls::NewStatic)(ϕ, x, s, alpha)
64-
ϕα = ϕ(alpha)
74+
function (ls::NewStatic)(ϕ, x, s, α::Tα) where
75+
@assert α > real((0))
76+
ϕα = ϕ(α)
77+
78+
# Hard-coded backtrack until we find a finite function value
79+
iterfinite = 0
80+
iterfinitemax = -log2(eps(real(Tα)))
81+
while !isfinite(ϕα) && iterfinite < iterfinitemax
82+
iterfinite += 1
83+
αold = α
84+
α = αold/2
85+
86+
ϕα = ϕ(α)
87+
end
6588

66-
return alpha, ϕα
89+
return α, ϕα
6790
end

0 commit comments

Comments
 (0)