scvi.model.AmortizedLDA

class scvi.model.AmortizedLDA(adata, n_topics=20, n_hidden=128, cell_topic_prior=None, topic_feature_prior=None)[source]

Amortized Latent Dirichlet Allocation [Blei03].

Parameters
adata : AnnDataAnnData

AnnData object that has been registered via setup_anndata().

n_topics : intint (default: 20)

Number of topics to model.

n_hidden : intint (default: 128)

Number of nodes in the hidden layer of the encoder.

cell_topic_prior : float | Sequence[float] | NoneUnion[float, Sequence[float], None] (default: None)

Prior of cell topic distribution. If None, defaults to 1 / n_topics.

topic_feature_prior : float | Sequence[float] | NoneUnion[float, Sequence[float], None] (default: None)

Prior of topic feature distribution. If None, defaults to 1 / n_topics.

Examples

>>> adata = anndata.read_h5ad(path_to_anndata)
>>> scvi.model.AmortizedLDA.setup_anndata(adata)
>>> model = scvi.model.AmortizedLDA(adata)
>>> model.train()
>>> feature_by_topic = model.get_feature_by_topic()
>>> adata.obsm["X_LDA"] = model.get_latent_representation()

Attributes

device

history

Returns computed metrics during training.

is_trained

test_indices

train_indices

validation_indices

Methods

get_elbo([adata, indices, batch_size])

Return the ELBO for the data.

get_feature_by_topic([n_samples])

Gets a Monte-Carlo estimate of the expectation of the feature by topic matrix.

get_latent_representation([adata, indices, ...])

Converts a count matrix to an inferred topic distribution.

get_perplexity([adata, indices, batch_size])

Computes approximate perplexity for adata.

load(dir_path[, adata, use_gpu])

Instantiate a model from the saved output.

save(dir_path[, overwrite, save_anndata])

Save the state of the model.

setup_anndata(adata[, layer, copy])

Sets up the AnnData object for this model.

to_device(device)

Move model to device.

train([max_epochs, use_gpu, train_size, ...])

Train the model.