aimz.ImpactModel.log_likelihood#
- ImpactModel.log_likelihood(X, y=None, *, shard_axis='obs', batch_size=None, output_dir=None, progress=True, **kwargs)[source]#
Compute the log-likelihood of the data under the given model.
Results are written to disk in the Zarr format, with computing and file writing decoupled and executed concurrently.
- Parameters:
X (ArrayLike | ArrayLoader) – Input data. If array-like, the leading axis is
Alternatively (the observation axis.)
array-like (a data loader that holds all)
internally. (objects and handles batching)
y (ArrayLike | None) – Output data. The leading axis is the observation axis. Must be
NoneifXis a data loader.shard_axis (Literal['obs', 'draw']) – Multi-device sharding strategy; no effect on a single device.
"obs"(default) shards the input across devices and replicates the posterior."draw"shards the posterior across devices and replicates the input, which must be an array, not a data loader. If the model has no posterior samples, the data path is used regardless ofshard_axis.batch_size (int | None) – Size of each batch, taken from the input under
shard_axis="obs"and from the draws undershard_axis="draw". Also used as the chunk size when storing results. IfNone, it is determined automatically from the input size and number of samples. Ignored ifXis a data loader, in which case the data loader is expected to handle batching internally.output_dir (str | Path | None) – The directory where the outputs will be saved. If the specified directory does not exist, it will be created automatically. If
None, a model-owned temporary directory is used. A subdirectory is generated within this directory to store the outputs. The temporary directory is removed bycleanup(),cleanup_models(), or when the model is garbage-collected. Pass an explicitoutput_dirto keep results beyond the model’s lifetime.progress (bool) – Whether to display a progress bar.
**kwargs (object) – Additional arguments passed to the model.
- Returns:
Log-likelihood values. Posterior samples are included if available.
- Raises:
TypeError – If
shard_axis="draw"is used with a data loaderX.ValueError – If
shard_axisis not"obs"or"draw".NotImplementedError – If a return site’s axis-1 size does not match the input batch size (
shard_axis="obs"only).
- Return type:
xr.DataTree
See also
cleanup()to remove the temporary directory if created.