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:
- method
str Optimization method. Any
scipy.optimize.minimizemethod (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".- vars
listofTensorVariable, 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 onmethod. If gradients are requested automatically but the model has none,"powell"is used instead.- initvals
dict, 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.sampledoes. This avoids getting stuck at saddle points of the default initial point (e.g. products of zero-centered variables). Setrandom_seedfor reproducible results. Not jittering is the current default, with aFutureWarning; a future release will jitter by default.- jitter_max_retries
int Maximum number of attempts at drawing a jittered initial point with finite log-probability.
- random_seed
int, array_like ofint, orGenerator, optional Seed for jitter and stochastic optimizers (basinhopping). With a fixed seed the result is fully reproducible.
- progressbarbool or
ProgressBarOptions, defaultTrue 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, asfit.covariance_matrix. This needsnHessian-vector products and ann x nmatrix, so it is expensive for large models.- return_inferencedatabool, default
False If True, return an
arviz.InferenceDatawith the MAP point as a single-drawposterior(plusfit,optimizer_result,observed_dataandconstant_datagroups). If False, return adictmapping variable names to values, transformed ones included.Deprecated since version The:
dictreturn is deprecated: a future release will default to True, and later remove the option.- idata_kwargs
dict, optional Keyword arguments for
pymc.to_inference_data(), e.g.include_transformed=Trueto also return transformed (unconstrained) values such assigma_log__.- model
Model(optionalifinwithcontext) Pass a model from
pymc.model.transform.freeze_model()for constant folding and compiled functions cached across calls.- backend
str, optional Computational backend, one of “numba”, “c” or “jax”. Defaults to the PyTensor default mode.
- compile_kwargs
dict, optional Keyword arguments for the compiled functions.
compile_kwargs["mode"]cannot be combined withbackend.- **optimizer_kwargs
Passed on to
scipy.optimize.minimize(e.g.maxiter,tol), orscipy.optimize.basinhoppingwhenmethod="basinhopping", in which caseminimizer_kwargs["method"]selects the inner optimizer (default"L-BFGS-B").
- method
- Returns:
arviz.InferenceDataordictMAP estimate, see
return_inferencedata.