pymc.find_MAP#

pymc.find_MAP(method='L-BFGS-B', *, vars=None, use_grad=None, use_hess=None, use_hessp=None, initvals=None, jitter=None, jitter_max_retries=10, random_seed=None, progressbar=True, compute_hessian=False, return_inferencedata=False, idata_kwargs=None, model=None, backend=None, compile_kwargs=None, **optimizer_kwargs)[source]#

Find the local maximum a posteriori point of a model with scipy.optimize.

find_MAP should not be used to initialize the NUTS sampler. Simply call pymc.sample() and it will automatically initialize NUTS in a better way.

Parameters:
methodstr

Optimization method. Any scipy.optimize.minimize method (Nelder-Mead, Powell, CG, BFGS, L-BFGS-B, TNC, COBYLA, SLSQP, trust-constr, dogleg, trust-ncg, trust-exact, trust-krylov, Newton-CG) or "basinhopping". Defaults to "L-BFGS-B".

varslist of TensorVariable, optional

Free random variables (or their value variables) to optimize over. All other variables are held fixed at their initial values. Defaults to all continuous variables. Passing discrete variables switches to the gradient-free "powell" method.

use_grad, use_hess, use_hesspbool, optional

Whether to compile and pass the gradient, hessian and hessian-vector product to the optimizer. None (default) chooses based on method. If gradients are requested automatically but the model has none, "powell" is used instead.

initvalsdict, optional

Initial values for (transformed) variables, overriding the model defaults. Partial initialization is permitted, as in pymc.sample().

jitterbool, optional

Add U(-1, 1) jitter to the initial point of the optimized variables, as pymc.sample does. This avoids getting stuck at saddle points of the default initial point (e.g. products of zero-centered variables). Set random_seed for reproducible results. Not jittering is the current default, with a FutureWarning; a future release will jitter by default.

jitter_max_retriesint

Maximum number of attempts at drawing a jittered initial point with finite log-probability.

random_seedint, array_like of int, or Generator, optional

Seed for jitter and stochastic optimizers (basinhopping). With a fixed seed the result is fully reproducible.

progressbarbool or ProgressBarOptions, default True

Whether to display the optimizer’s progress bar. The string options of pymc.sample() are accepted and simply enable it.

compute_hessianbool, default False

Store the inverse Hessian of the negative model.logp(jacobian=False) at the optimum, taken over the optimized (unconstrained) value variables, as fit.covariance_matrix. This needs n Hessian-vector products and an n x n matrix, so it is expensive for large models.

return_inferencedatabool, default False

If True, return an arviz.InferenceData with the MAP point as a single-draw posterior (plus fit, optimizer_result, observed_data and constant_data groups). If False, return a dict mapping variable names to values, transformed ones included.

Deprecated since version The: dict return is deprecated: a future release will default to True, and later remove the option.

idata_kwargsdict, optional

Keyword arguments for pymc.to_inference_data(), e.g. include_transformed=True to also return transformed (unconstrained) values such as sigma_log__.

modelModel (optional if in with context)

Pass a model from pymc.model.transform.freeze_model() for constant folding and compiled functions cached across calls.

backendstr, optional

Computational backend, one of “numba”, “c” or “jax”. Defaults to the PyTensor default mode.

compile_kwargsdict, optional

Keyword arguments for the compiled functions. compile_kwargs["mode"] cannot be combined with backend.

**optimizer_kwargs

Passed on to scipy.optimize.minimize (e.g. maxiter, tol), or scipy.optimize.basinhopping when method="basinhopping", in which case minimizer_kwargs["method"] selects the inner optimizer (default "L-BFGS-B").

Returns:
arviz.InferenceData or dict

MAP estimate, see return_inferencedata.