@@ -38,29 +38,12 @@ function get_right_endpoint(
38
38
local_opt = Opt (local_alg, n_theta)
39
39
ftol_abs! (local_opt, scan_tol)
40
40
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)
60
44
61
45
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
64
47
elseif length (g) > 0
65
48
if isa (loss_grad, Function)
66
49
g .= loss_grad (x)
@@ -90,9 +73,6 @@ function get_right_endpoint(
90
73
# constrain optimizer
91
74
opt = Opt (:LN_AUGLAG , n_theta)
92
75
ftol_abs! (opt, scan_tol)
93
- # XXX : testing
94
- # is_auto_glob = initial_step(opt, theta_init)
95
- # initial_step!(opt, is_auto_glob)
96
76
97
77
max_objective! (
98
78
opt,
@@ -128,15 +108,18 @@ function get_right_endpoint(
128
108
=#
129
109
130
110
# 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
132
118
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
137
120
pp = ProfilePoint[]
138
121
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
140
123
pp = ProfilePoint[]
141
124
res = (nothing , pp, :SCAN_BOUND_REACHED )
142
125
elseif ret == :FTOL_REACHED # successful result
0 commit comments