theislab / scgen

Single cell perturbation prediction
https://scgen.readthedocs.io
GNU General Public License v3.0
255 stars 51 forks source link

get_marginal_ll not implemented for perturbation example model #93

Open ajaynadig opened 1 month ago

ajaynadig commented 1 month ago

Hello, Thank you for your great work on this package. I am interested in computing the log-likelihood for unseen observation given a trained scGen model. However, I found that using get_marginal_ll throws an error "marginal_ll is not implemented for current model. Please raise an issue on github if you need it.", and appears to do so as well for the perturbation tutorial:

import logging
import scanpy as sc
import scgen

train = sc.read("train.h5ad") #Kang interferon dataset
train_new = train[~((train.obs["cell_type"] == "CD4T") &
                    (train.obs["condition"] == "stimulated"))].copy()

scgen.SCGEN.setup_anndata(train_new, batch_key="condition", labels_key="cell_type")

model = scgen.SCGEN(train_new)

model.train(
    max_epochs=100,
    batch_size=32,
    early_stopping=True,
    early_stopping_patience=25
)

likelihoods = model.get_marginal_ll(return_mean = False)

Which gives this error: NotImplementedError: marginal_ll is not implemented for current model. Please raise an issue on github if you need it.

I realize this may be an issue with scvi-tools rather than scGen, but in any case, it would be very helpful to have easy access to log-likelihoods for scGen models, both to interpret models and for methods development on top of scGen.

Thanks!