scvi.model.base.PyroSampleMixin#
- class scvi.model.base.PyroSampleMixin[source]#
Mixin class for generating samples from posterior distribution.
Works using both minibatches and full data.
Methods table#
|
Summarise posterior distribution. |
Methods#
- PyroSampleMixin.sample_posterior(adata=None, input_dl=None, indices=None, num_samples=1000, return_sites=None, accelerator='auto', device='auto', batch_size=None, return_observed=False, return_samples=False, summary_frequency=None, summary_fun=None, **sample_kwargs)[source]#
Summarise posterior distribution.
Generate samples from posterior distribution for each parameter and compute mean, 5th/95th quantiles, standard deviation.
- Parameters:
- adata anndata.AnnData |
None(default:None) AnnData object to use for sampling. If
None, uses the registered AnnData object.- input_dl
AnnDataLoader|None(default:None) DataLoader object to use for sampling. If
None, creates one based onadata.- indices
ndarray|None(default:None) Indices of cells to use for sampling. If
None, uses all cells.- num_samples
int(default:1000) Number of posterior samples to generate.
- return_sites
list|None(default:None) List of variables for which to generate posterior samples, defaults to all variables.
- accelerator
str(default:'auto') Supports passing different accelerator types
("cpu", "gpu", "tpu", "ipu", "hpu", "mps, "auto")as well as custom accelerator instances.- device
int|str(default:'auto') The device to use. Can be set to a non-negative index (
intorstr) or"auto"for automatic selection based on the chosen accelerator. If set to"auto"andacceleratoris not determined to be"cpu", thendevicewill be set to the first available device.- batch_size
int|None(default:None) Minibatch size for data loading into model. Defaults to
scvi.settings.batch_size.- return_observed
bool(default:False) Return observed sites/variables? Observed count matrix can be very large so not returned by default.
- return_samples
bool(default:False) Return all generated posterior samples in addition to sample mean, 5th/95th quantile and SD?
- summary_frequency
int|None(default:None) Compute summary_fn after summary_frequency batches. Reduces memory footprint.
- summary_fun
dict[str,Callable] |None(default:None) a dict in the form {“means”: np.mean, “std”: np.std} which specifies posterior distribution summaries to compute and which names to use. See below for default returns.
- sample_kwargs
Keyword arguments for
_get_posterior_samples.
- adata anndata.AnnData |
- Returns:
- post_sample_meansdict[str, numpy.ndarray]
Mean of the posterior distribution for each variable, a dictionary of numpy arrays for each variable;
- post_sample_q05dict[str, numpy.ndarray]
5th quantile of the posterior distribution for each variable;
- post_sample_q95dict[str, numpy.ndarray]
95th quantile of the posterior distribution for each variable;
- post_sample_stdsdict[str, numpy.ndarray]
Standard deviation of the posterior distribution for each variable;
- posterior_samplesdict[str, numpy.ndarray], optional
Posterior distribution samples for each variable as numpy arrays of shape
(n_samples, ...).
Notes
Note for developers: requires overwritten
list_obs_plate_varsproperty, which lists observation/minibatch plate name and variables. Seelist_obs_plate_varsfor details of the variables it should contain. This dictionary can be returned by model class propertyself.module.model.list_obs_plate_varsto keep all model-specific variables in one place.