Calculating log-likelihood for scVI (and possibly other models)

Hi Adam @adamgayoso,
I am sorry if this question is already asked by someone else. In your scVI paper, you have mentioned about how to calculate Log-likelihood for scVI in the Supplemental Note 6 as the following:

I am not quite sure how we can keep the generative model’s parameters fixed and optimize the inference network during test time using the functions provided by scvi-tools. Also, could you please briefly explain how can it be equivalent to the marginal likelihood of the held-out data conditioned on a latent representation learned for that data? Does the get_elbo function provide the same estimation as mentioned in the above script?

Thanks a lot in advance.

Kind regards,

Hi @tu.le, while the feature

is not supported in the latest version of scvi-tools anymore, you would do so by fixing the decoder/generative network of the scVI model (you can do so by zeroing the gradient for the other parameters during back propagation), then optimizing the encoder’s parameters using the held out data.

Sorry, this sentence just seems a bit ambiguous. I believe what is trying to be said is that we are assessing the overall marginal likelihood with the extra condition of the encoder parameters being trained on the held-out data.

As mentioned before get_elbo does not support the feature in the script (optimizing the inference network on held out data), instead it just computes the lower bound on the likelihood with the previously learned parameters of the model. However, the encoder parameters should generalize well enough to the held out data that this is not an issue. Additionally, one can estimate the marginal likelihood of the held-out data using the get_marginal_ll function which provides a Monte Carlo estimate of the marginal likelihood.

Hi @Justin_Hong,

Thank you very much for a detailed explanation. It’s now clear to me regarding what was mentioned in the manuscript.

which parameters/settings in the current scVI implementation supporting zeroing the gradients of the decoder’s parameters? or do we need to rewrite the TrainingPlan module using the API provided by scvi-tools for this task? (Sorry for bothering. I have looked through the manual but could not find the option/setting with the function you have mentioned here).

Kind regards,

As Justin said this is not currently supported, but you could write a callback to set the requires grad flag of params correctly and then run the train method again.

1 Like

Sorry for my confusion and thanks for your explanation. It’s clear now!
Kind regards,