Generate cell expression from latent space directly

Hi, thanks for this amazing tool!
I trained a scVI model(scvi.model.SCVI) and tried to generate cell expression(cells number x genes number) from latent space(cells number x latent dims). I try to make this by using scvi.model.SCVI.generative() and get a set of ZINB distribution. But when I run ZINB.sample() I get an error:

Expected parameter rate (Tensor of shape (68579, 17789)) of distribution Gamma(concentration: torch.Size([68579, 17789]), rate: torch.Size([68579, 17789])) to satisfy the constraint GreaterThan(lower_bound=0.0), but found invalid values:\ntensor([[0., 0., 0., …, 0., 0., 0.], [0., 0., 0., …, 0., 0., 0.], [0., 0., 0., …, 0., 0., 0.], …, [0., 0., 0., …, 0., 0., 0.], [0., 0., 0., …, 0., 0., 0.], [0., 0., 0., …, 0., 0., 0.]], device=‘cuda:0’)"

I fund that the generated mu for the ZINB is all inf. I wander is there anything wrong when I generate the cell expression? I used the latent expression from get_latent_representation() and library size from get_latent_library_size().

Or is there any easier way to directly generate cell expression from the latent representation? Any help would be very appreciated!

Hi EperLuo,

I am trying to do the same and running into the exact same problem with the NegativeBionomial distribution. Did you manage to solve it in the end?

Hi EperLuo,

Not sure if you’re still trying this. I found out for me that it was the library size was the problem. This gets exponentiated in the generative() function, so make sure that the library size is the logarithm of the library size that you want. See also this post: link