class_docstr: PyMC model-fitting backend.
class_docstr_tok: ["PyMC","model-fitting","backend","."]
docstr: Fit a model using a Laplace approximation.
  
  Mainly for pedagogical use, provides reasonable results for approximately
  Gaussian posteriors. The approximation can be very poor for some models
  like hierarchical ones. Use ``mcmc``, ``nuts_numpyro``, ``nuts_blackjax``
  or ``vi`` for better approximations.
  
  Parameters
  ----------
  draws: int
      The number of samples to draw from the posterior distribution.
  omit_offsets: bool
      Omits offset terms in the ``InferenceData`` object returned when the model includes
      group specific effects.
  include_mean: bool
      Compute the posterior of the mean response.
  
  Returns
  -------
  An ArviZ's InferenceData object.
docstr_tok: ["Fit","a","model","using","a","Laplace","approximation",".","Mainly","for","pedagogical","use",",","provides","reasonable","results","for","approximately","Gaussian","posteriors",".","The","approximation","can","be","very","poor","for","some","models","like","hierarchical","ones",".","Use","``","mcmc","``",",","``","nuts_numpyro","``",",","``","nuts_blackjax","``","or","``","vi","``","for","better","approximations",".","Parameters","--","--","--","--","--","draws",":","int","The","number","of","samples","to","draw","from","the","posterior","distribution",".","omit_offsets",":","bool","Omits","offset","terms","in","the","``","InferenceData","``","object","returned","when","the","model","includes","group","specific","effects",".","include_mean",":","bool","Compute","the","posterior","of","the","mean","response",".","Returns","--","--","--","-","An","ArviZ","'s","InferenceData","object","."]
code: def _run_laplace(self, draws, omit_offsets, include_mean):
      """Fit a model using a Laplace approximation.
  
      Mainly for pedagogical use, provides reasonable results for approximately
      Gaussian posteriors. The approximation can be very poor for some models
      like hierarchical ones. Use ``mcmc``, ``nuts_numpyro``, ``nuts_blackjax``
      or ``vi`` for better approximations.
  
      Parameters
      ----------
      draws: int
          The number of samples to draw from the posterior distribution.
      omit_offsets: bool
          Omits offset terms in the ``InferenceData`` object returned when the model includes
          group specific effects.
      include_mean: bool
          Compute the posterior of the mean response.
  
      Returns
      -------
      An ArviZ's InferenceData object.
      """
      with self.model:
          maps = pm.find_MAP()
          n_maps = deepcopy(maps)
          for m in maps:
              if pm.util.is_transformed_name(m):
                  n_maps.pop(pm.util.get_untransformed_name(m))
  
          hessian = pm.find_hessian(n_maps)
  
      if np.linalg.det(hessian) == 0:
          raise np.linalg.LinAlgError(
              "Singular matrix. Use mcmc or vi method"
          )
  
      cov = np.linalg.inv(hessian)
      modes = np.concatenate(
          [np.atleast_1d(v) for v in n_maps.values()]
      )
  
      samples = np.random.multivariate_normal(modes, cov, size=draws)
  
      idata = _posterior_samples_to_idata(samples, self.model)
      idata = self._clean_results(idata, omit_offsets, include_mean)
      return idata
  
imports: import functools
  import logging
  import traceback
  from copy import deepcopy
  from importlib.metadata import version
  import numpy
  import pymc
  import pytensor.tensor
  from pytensor.tensor.special import softmax
  from bambi.backend.links import cloglog, identity, inverse_squared, logit, probit, arctan_2
  from bambi.backend.model_components import ConstantComponent, DistributionalComponent
  from bambi.utils import get_aliased_name
label_desc: Use image node_id 9 for calling the PyMCModel obj's underlying member method code with example usage: obj._run_laplace(draws, omit_offsets, include_mean) and returns: idata