- Notifications
You must be signed in to change notification settings - Fork285
Commit6f8551a
authored
Fix issues related to providing a Jacobian function (#973)
* Updated the Minimizer.least_squares method to wrap the Jacobian function- The Jacobian function provided by the user is now handled similarly to how it is handled in, e.g., Minimizer.leastsq.- If the Jacobian function is called 'Dfun' in the keyword arguments, then it is also accepted (Minimizer.scalar_minimize already does this).* Updated the Minimizer.__jacobian method signature to fix exception- The signature now matches the signature of Minimizer.__residual. This was changed because the following exception was being raised whenever the user provided a function for calculating the Jacobian: "TypeError: Minimizer.__jacobian() got an unexpected keyword argument 'apply_bounds_transformation'".* Updated the Minimizer.__jacobian method to use the new parameter- The updating of the parameter values is now similar to how it is done in Minimizer.__residual.* Updated test_least_squares_jacobian_types to handle the wrapped Jacobian function- The params argument of the jac_array function is now an actual Parameters object like it is in the f function, which means that the parameters can be accessed via string keys.* Updated the coerce_float64 function- Added explicit support for sparse matrices (e.g., Block Sparse Row) and LinearOperator objects. This change is needed because the updated test_least_squares_jacobian_types would otherwise fail. Similar to how these types are handled when calculating the Hessian matrix in Minimizer.least_squares.* Renamed the Minimizer.__jacobian method to avoid a bug related to pickling- Attempting to make use of multiprocessing.Pool while providing, e.g., Minimizer.least_squares a function for calculating the Jacobian did not work prior to the renaming of the method due to an issue related to pickling and unpickling of private methods. See the (currently) open issue (python/cpython#77188) and pull request (python/cpython#21480) for more information.* Added a test for when the "least_squares" method is provided a function for the Jacobian- Verifies that a) the fitted parameters have the expected values, b) the jac function is actually called, and c) that there are indeed fewer function evaluations as a result.* Updated the docstring of Minimizer._jacobian- The docstring is updated to include the parameters and return values.* Added tests for (un)pickling Minimizer when a Jacobian function is provided* Updated timeout value in test_jacobian_with_forkingpickler- Increased the timeout value so that slow runners can actually succeed instead of timing out. If no timeout was specified, then a failing test could end up hanging instead.* Added an example that demonstrates the benefits of providing a Jacobian function* Updated the list of contributors1 parent3935485 commit6f8551a
File tree
5 files changed
+388
-8
lines changed- examples
- lmfit
- tests
5 files changed
+388
-8
lines changedLines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
55 | 55 |
| |
56 | 56 |
| |
57 | 57 |
| |
58 |
| - | |
| 58 | + | |
59 | 59 |
| |
60 | 60 |
| |
61 | 61 |
| |
|
Lines changed: 178 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + |
Lines changed: 35 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
553 | 553 |
| |
554 | 554 |
| |
555 | 555 |
| |
556 |
| - | |
| 556 | + | |
557 | 557 |
| |
558 | 558 |
| |
559 | 559 |
| |
560 | 560 |
| |
561 | 561 |
| |
562 | 562 |
| |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
563 | 577 |
| |
564 | 578 |
| |
565 | 579 |
| |
566 | 580 |
| |
567 | 581 |
| |
568 |
| - | |
569 |
| - | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
570 | 587 |
| |
571 | 588 |
| |
572 | 589 |
| |
| |||
931 | 948 |
| |
932 | 949 |
| |
933 | 950 |
| |
934 |
| - | |
| 951 | + | |
935 | 952 |
| |
936 | 953 |
| |
937 | 954 |
| |
| |||
1532 | 1549 |
| |
1533 | 1550 |
| |
1534 | 1551 |
| |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
1535 | 1559 |
| |
1536 | 1560 |
| |
1537 | 1561 |
| |
| |||
1639 | 1663 |
| |
1640 | 1664 |
| |
1641 | 1665 |
| |
1642 |
| - | |
| 1666 | + | |
1643 | 1667 |
| |
1644 | 1668 |
| |
1645 | 1669 |
| |
| |||
2386 | 2410 |
| |
2387 | 2411 |
| |
2388 | 2412 |
| |
2389 |
| - | |
| 2413 | + | |
| 2414 | + | |
| 2415 | + | |
| 2416 | + | |
| 2417 | + | |
| 2418 | + | |
2390 | 2419 |
| |
2391 | 2420 |
| |
2392 | 2421 |
| |
|
0 commit comments
Comments
(0)