Commit 3b61d27
Fix LBFGS/BFGS callback receiving Dual numbers instead of scalar loss values
Fixes #1073
When using LBFGS or BFGS with bounds, Optim.jl wraps the optimizer in Fminbox,
which may use ForwardDiff internally for gradient computation. This resulted in
the callback receiving ForwardDiff.Dual numbers instead of scalar loss values,
causing incorrect (sometimes negative) values to be reported.
Changes:
- Added ForwardDiff as a dependency in OptimizationOptimJL
- Added _scalar_value() utility function to extract scalar values from Dual numbers
- Updated all three _cb callback functions to extract scalar values before passing to user callbacks
- Added comprehensive test case verifying callbacks receive correct scalar non-negative values
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 36fbd85 commit 3b61d27
File tree
3 files changed
+53
-8
lines changed- lib/OptimizationOptimJL
- src
- test
3 files changed
+53
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | | - | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
6 | 10 | | |
7 | 11 | | |
8 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
9 | 19 | | |
10 | 20 | | |
11 | 21 | | |
| |||
149 | 159 | | |
150 | 160 | | |
151 | 161 | | |
| 162 | + | |
| 163 | + | |
152 | 164 | | |
153 | 165 | | |
154 | 166 | | |
155 | | - | |
| 167 | + | |
156 | 168 | | |
157 | 169 | | |
158 | 170 | | |
159 | | - | |
| 171 | + | |
160 | 172 | | |
161 | 173 | | |
162 | 174 | | |
| |||
270 | 282 | | |
271 | 283 | | |
272 | 284 | | |
| 285 | + | |
| 286 | + | |
273 | 287 | | |
274 | 288 | | |
275 | 289 | | |
276 | | - | |
| 290 | + | |
277 | 291 | | |
278 | 292 | | |
279 | 293 | | |
280 | | - | |
| 294 | + | |
281 | 295 | | |
282 | 296 | | |
283 | 297 | | |
| |||
357 | 371 | | |
358 | 372 | | |
359 | 373 | | |
| 374 | + | |
| 375 | + | |
360 | 376 | | |
361 | 377 | | |
362 | 378 | | |
363 | 379 | | |
364 | 380 | | |
365 | | - | |
| 381 | + | |
366 | 382 | | |
367 | | - | |
| 383 | + | |
368 | 384 | | |
369 | 385 | | |
370 | 386 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
202 | 231 | | |
203 | 232 | | |
204 | 233 | | |
| |||
0 commit comments