scvi.external.drvi.DecoderDRVI#

class scvi.external.drvi.DecoderDRVI(n_input, n_output, n_split, split_method='split_map', n_split_output='auto', split_aggregation='logsumexp', n_cat_list=None, n_continuous_cov=0, n_layers=1, n_hidden=128, reuse_weights='everywhere', inject_covariates=True, use_batch_norm=False, use_layer_norm=True, model_cell_dispersion=False, model_zero_inflation=False, **kwargs)[source]#

Bases: Module

DRVI additive decoder: split the latent, decode each split, then aggregate.

Reuses scvi’s head structure (px_scale_decoder, px_r_decoder, px_dropout_decoder) but, unlike DecoderSCVI, returns the per-gene parameters in log space (aggregated scale logits, dispersion logits and zero-inflation logits). The library-size, softmax and exp transforms into count space are applied by the module (see generative()).

The latent z of dimension n_latent is mapped into n_split independent groups, each decoded by SplitFCLayers, and the per-split parameters are aggregated over the split dimension (in log space; the count-space transforms are applied by the module).

Parameters:
n_input int

Dimensionality of the latent space (n_latent); the dimension that is split.

n_output int

Number of genes.

n_split int

Number of latent splits. Must divide n_input for both split_mask and split_map.

split_method Literal['split_mask', 'split_map'] (default: 'split_map')

How the latent is mapped to splits.

  • "split_mask" — reshape into n_split contiguous chunks and place each chunk on its own split, zeroing the other chunks. Each split keeps the full latent width n_input; e.g. with n_input=10 and n_split=2 the latent [1..10] becomes [[1,2,3,4,5,0,0,0,0,0], [0,0,0,0,0,6,7,8,9,10]].

  • "split_map" — reshape into n_split chunks of size n_input // n_split and apply a learned per-split linear map (StackedLinearLayer).

n_split_output int | Literal['auto'] (default: 'auto')

Per-split projection output width, i.e. the input dimension to each split’s decoder body. "auto" (default) uses n_input (= n_latent). For "split_map" it is the output size of the learned per-split projection; for "split_mask" it must equal n_input.

split_aggregation Literal['mean', 'logsumexp'] (default: 'logsumexp')

How per-split parameters are combined over the split dimension.

  • "mean" — sum / n_split.

  • "logsumexp" — logsumexp - log(n_split) (additive decoder in log space).

n_continuous_cov int (default: 0)

Number of continuous covariates injected into the decoder layers.

reuse_weights Literal['everywhere', 'last', 'hidden', 'nowhere', 'hidden_except_first'] (default: 'everywhere')

Weight-sharing policy across splits, applied to the FC body (its n_layers hidden layers) and the parameter heads (“last”):

  • "everywhere" (default) — hidden layers and heads all shared.

  • "hidden" — hidden layers shared, heads per-split.

  • "last" — hidden layers per-split, heads shared.

  • "hidden_except_first" — first hidden layer per-split, the rest and heads shared.

  • "nowhere" — hidden layers and heads all per-split.

Per-split weights use StackedLinearLayer; shared weights are a single Linear broadcast over the split dimension.

model_cell_dispersion bool (default: False)

Whether to build a per-cell dispersion head (px_r_decoder). If False (default), the decoder returns None for the dispersion and the module uses a shared dispersion parameter instead (needed only for dispersion="gene-cell").

model_zero_inflation bool (default: False)

Whether to build a zero-inflation head (px_dropout_decoder). If False (default), the decoder returns None for the zero-inflation logits (needed only for the zinb likelihood).

**kwargs

Keyword arguments for SplitFCLayers.

Attributes table#

Methods table#

forward(z, *cat_list[, cont])

Decode z into log-space per-gene parameters.

Attributes#

DecoderDRVI.training: bool#

Methods#

DecoderDRVI.forward(z, *cat_list, cont=None, **kwargs)[source]#

Decode z into log-space per-gene parameters.

Returns (px_scale_logit, px_r_logit, px_dropout_logit, px_scale_logit_per_split): the aggregated per-gene scale logits (log space, before softmax), the per-cell dispersion logits, the zero-inflation logits, and the per-split scale logits before aggregation (only when inspect_mode is set, else None). The dispersion and zero-inflation outputs are None unless the corresponding head was built (model_cell_dispersion / model_zero_inflation). The library-size, softmax and exp transforms are applied by the module (not here). Any number of leading dimensions (e.g. an n_samples axis) is supported and preserved: the split transform, the per-split FC layers and the aggregation all act on the last one or two dimensions.

The split-mapping is an overridable seam (_apply_split); any extra **kwargs are threaded to it and to the per-split FC body.