Skip to content

Commit 0d727aa

Browse files
authored
migrate iminuit docs (#631)
1 parent 1f95f25 commit 0d727aa

2 files changed

Lines changed: 56 additions & 32 deletions

File tree

docs/source/algorithms.md

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3920,48 +3920,36 @@ addition to optimagic when using an NLOPT algorithm. To install nlopt run
39203920

39213921
optimagic supports the [IMINUIT MIGRAD Optimizer](https://iminuit.readthedocs.io/). To
39223922
use MIGRAD, you need to have
3923-
[the iminuit package](https://github.com/scikit-hep/iminuit) installed (pip install
3924-
iminuit).
3923+
[the iminuit package](https://github.com/scikit-hep/iminuit) installed
3924+
(`pip install iminuit`).
39253925

39263926
```{eval-rst}
39273927
.. dropdown:: iminuit_migrad
39283928
3929-
.. code-block::
3930-
3931-
"iminuit_migrad"
3932-
3933-
`MIGRAD <https://iminuit.readthedocs.io/en/stable/reference.html#iminuit.Minuit.migrad>`_ is
3934-
the workhorse algorithm of the MINUIT optimization suite, which has been widely used in the
3935-
high-energy physics community since 1975. The IMINUIT package is a Python interface to the
3936-
Minuit2 C++ library developed by CERN.
3929+
**How to use this algorithm:**
39373930
3938-
Migrad uses a quasi-Newton method, updating the Hessian matrix iteratively
3939-
to guide the optimization. The algorithm adapts dynamically to challenging landscapes
3940-
using several key techniques:
3931+
.. code-block::
39413932
3942-
- **Quasi-Newton updates**: The Hessian is updated iteratively rather than recalculated at
3943-
each step, improving efficiency.
3944-
- **Steepest descent fallback**: When the Hessian update fails, Migrad falls back to steepest
3945-
descent with line search.
3946-
- **Box constraints handling**: Parameters with bounds are transformed internally to ensure
3947-
they remain within allowed limits.
3948-
- **Heuristics for numerical stability**: Special cases such as flat gradients or singular
3949-
Hessians are managed using pre-defined heuristics.
3950-
- **Stopping criteria based on Estimated Distance to Minimum (EDM)**: The optimization halts
3951-
when the predicted improvement becomes sufficiently small.
3952-
3953-
For details see :cite:`JAMES1975343`.
3933+
import optimagic as om
3934+
om.minimize(
3935+
...,
3936+
algorithm=om.algos.iminuit_migrad(stopping_maxfun=10_000, ...)
3937+
)
3938+
3939+
or
3940+
3941+
.. code-block::
39543942
3955-
**Optimizer Parameters:**
3943+
om.minimize(
3944+
...,
3945+
algorithm="iminuit_migrad",
3946+
algo_options={"stopping_maxfun=10_000, ...}
3947+
)
39563948
3957-
- **stopping.maxfun** (int): Maximum number of function evaluations. If reached, the optimization stops
3958-
but this is not counted as successful convergence. Function evaluations used for numerical gradient
3959-
calculations do not count toward this limit. Default is 1,000,000.
3949+
**Description and available options:**
39603950
3961-
- **n_restarts** (int): Number of times to restart the optimizer if convergence is not reached.
3951+
.. autoclass:: optimagic.optimizers.iminuit_migrad.IminuitMigrad
39623952
3963-
- A value of 1 (the default) indicates that the optimizer will only run once, disabling the restart feature.
3964-
- Values greater than 1 specify the maximum number of restart attempts.
39653953
```
39663954

39673955
## Nevergrad Optimizers

src/optimagic/optimizers/iminuit_migrad.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,44 @@
4242
)
4343
@dataclass(frozen=True)
4444
class IminuitMigrad(Algorithm):
45+
"""Minimize a scalar differentiable function using the MIGRAD algorithm from
46+
iminuit.
47+
48+
This optimizer wraps the MIGRAD algorithm from the iminuit package, which provides a
49+
Python interface to the Minuit2 C++ library developed and maintained by CERN.
50+
51+
MIGRAD is a local optimization method in the quasi-Newton family. It iteratively
52+
builds an approximation of the inverse Hessian matrix using the DFP variable-metric
53+
method to efficiently navigate optimization landscapes.
54+
55+
At each iteration, the algorithm attempts a Newton step, using gradient and Hessian
56+
approximations to move toward the function’s minimum. If this step fails to reduce
57+
the objective function, MIGRAD conducts a line search along the gradient direction
58+
to maintain progress. This continues until the convergence criteria, such as the
59+
Estimated Distance to Minimum (EDM) are met, that is, they fall below preset
60+
thresholds.
61+
62+
MIGRAD is designed for statistical optimization problems where accurate parameter
63+
uncertainty estimates are essential. It excels at maximum-likelihood and least-
64+
squares fits common in scientific computing, and is best suited for smooth,
65+
differentiable cost functions.
66+
67+
For best performance, supply analytical gradients. Convergence and solution will
68+
depend on your starting values. Bound constraints (limits) supported.
69+
70+
"""
71+
4572
stopping_maxfun: int = STOPPING_MAXFUN
73+
"""Maximum number of function evaluations."""
74+
4675
n_restarts: int = N_RESTARTS
76+
"""Number of times to restart the optimizer if convergence is not reached.
77+
78+
A value of 1 (the default) indicates that the optimizer will only run once,
79+
disabling the restart feature. Values greater than 1 specify the maximum number of
80+
restart attempts.
81+
82+
"""
4783

4884
def _solve_internal_problem(
4985
self, problem: InternalOptimizationProblem, params: NDArray[np.float64]

0 commit comments

Comments
 (0)