Skip to content

Commit aa2ed69

Browse files
committed
remove out_of_bound flag
1 parent 174040a commit aa2ed69

File tree

1 file changed

+13
-30
lines changed

1 file changed

+13
-30
lines changed

src/cico_one_pass.jl

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,12 @@ function get_right_endpoint(
3838
local_opt = Opt(local_alg, n_theta)
3939
ftol_abs!(local_opt, scan_tol)
4040
ftol_rel!(local_opt, scan_rtol)
41-
# XXX: testing
42-
#is_auto = initial_step(local_opt, theta_init)
43-
#initial_step!(local_opt, is_auto)
44-
45-
# flags to analyze fitting stop
46-
out_of_bound::Bool = false
47-
48-
function constraints_func(x, g) # testing grad methods
49-
# function constraints_func(x) # testing grad methods
50-
# this part is necessary to understand the difference between
51-
# "stop out of bounds" and "stop because of function call error"
52-
# in NLopt >= 1.0.2 we need to0 throw ForcedStop() to stop optimization
53-
loss_value = try
54-
loss_func(x)
55-
catch e
56-
@warn "Error when call loss_func($x)"
57-
# throw(e) # last wersion for NLopt <= 1.0.1 when there was no difference between ForcedStop and Error
58-
throw(NLopt.ForcedStop()) # XXX: temporary solution to suport both NLopt versions: 0.6 and 1.0.3
59-
end
41+
42+
function constraints_func(x, g) # testing grad methods
43+
loss_value = loss_func(x)
6044

6145
if (loss_value < 0.) && (scan_func(x) > scan_bound)
62-
out_of_bound = true
63-
throw(NLopt.ForcedStop())
46+
throw(NLopt.ForcedStop()) # stop optimization because of scan_bound reached
6447
elseif length(g) > 0
6548
if isa(loss_grad, Function)
6649
g .= loss_grad(x)
@@ -90,9 +73,6 @@ function get_right_endpoint(
9073
# constrain optimizer
9174
opt = Opt(:LN_AUGLAG, n_theta)
9275
ftol_abs!(opt, scan_tol)
93-
# XXX: testing
94-
#is_auto_glob = initial_step(opt, theta_init)
95-
#initial_step!(opt, is_auto_glob)
9676

9777
max_objective!(
9878
opt,
@@ -128,15 +108,18 @@ function get_right_endpoint(
128108
=#
129109

130110
# start optimization
131-
(optf, optx, ret) = optimize(opt, theta_init)
111+
# TODO: just throw error if optimization fails, not :LOSS_ERROR_STOP
112+
(optf, optx, ret) = try
113+
optimize(opt, theta_init)
114+
catch e
115+
@warn "Error when call optimize($opt, $theta_init)"
116+
return (nothing, ProfilePoint[], :LOSS_ERROR_STOP)
117+
end
132118

133-
if ret == :FORCED_STOP && !out_of_bound
134-
pp = ProfilePoint[]
135-
res = (nothing, pp, :LOSS_ERROR_STOP)
136-
elseif ret == :MAXEVAL_REACHED
119+
if ret == :MAXEVAL_REACHED
137120
pp = ProfilePoint[]
138121
res = (nothing, pp, :MAX_ITER_STOP)
139-
elseif (ret == :FORCED_STOP || ret == :FAILURE) && out_of_bound # successful result
122+
elseif ret == :FORCED_STOP || ret == :FAILURE # successful result
140123
pp = ProfilePoint[]
141124
res = (nothing, pp, :SCAN_BOUND_REACHED)
142125
elseif ret == :FTOL_REACHED # successful result

0 commit comments

Comments
 (0)