CLVModel.fit#

CLVModel.fit(data=None, *, method='mcmc', progressbar=None, random_seed=None, sample_kwargs=None, map_kwargs=None, **kwargs)[source]#

Infer the model posterior.

Sets attrs on the inference data of the model.

Parameters:
dataAny, optional

Input data for model fitting. If None, the data already held by the instance is used. Models that do not override _prepare_fit raise a NotImplementedError when data is passed here.

methodstr

Method used to fit the model. Options are:

  • "mcmc": Samples from the posterior via pymc.sample (default)

  • "map": Finds maximum a posteriori via pymc.find_MAP

  • "demz": Samples from the posterior via pymc.sample using DEMetropolisZ

  • "advi": Samples via pymc.fit(method="advi") and Approximation.sample

  • "fullrank_advi": As "advi", with a full-rank approximation

Note this selects the sampler, not pymc.find_MAP’s method argument (the scipy optimizer). Use map_kwargs to reach the latter.

progressbarbool, optional

Specifies whether the fit progress bar should be displayed. Defaults to True.

random_seedRandomState, optional

Provides the sampler with an initial random seed for reproducible samples.

sample_kwargsdict, optional

Only used by the variational methods; forwarded to Approximation.sample (e.g. {"draws": 1_000}).

map_kwargsdict, optional

Only used by method="map"; forwarded to pymc.find_MAP after the other keyword arguments have been filtered. Use it for names fit would otherwise shadow, e.g. {"method": "Powell"} to pick the optimizer.

**kwargsAny

Custom sampler settings, passed to the underlying PyMC routine.

Returns:
xr.DataTree

Inference data of the fitted model.

Examples

model = MyModel()
idata = model.fit(data)
idata = model.fit(data, method="map")