Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include MoG and ConditionalNorms. #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

canergen
Copy link
Member

No description provided.

Copy link
Member

@martinkim0 martinkim0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some small questions about the implementation

src/embedding_scvi/_components.py Outdated Show resolved Hide resolved
src/embedding_scvi/_components.py Outdated Show resolved Hide resolved
Comment on lines +81 to +82
cat_dim: int | None = None,
conditional: bool = False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs documentation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It currently fails. Can you add something like batch_key (it's the site in mrVI) and ConditionalNorm is only computed on this. It would be 'assay_suspension' for census.

Comment on lines +60 to +73
if self.prior=='mog':
self.register_buffer(
"u_prior_logits", torch.ones([mixture_components]))
self.register_buffer(
"u_prior_means", torch.randn([n_latent, mixture_components]))
self.register_buffer(
"u_prior_scales", torch.zeros([n_latent, mixture_components]))
elif self.prior=='mog_celltype':
self.register_buffer(
"u_prior_logits", torch.ones([n_labels]))
self.register_buffer(
"u_prior_means", torch.randn([n_latent, n_labels]))
self.register_buffer(
"u_prior_scales", torch.zeros([n_latent, n_labels]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these parameters updated during model training?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes they are learnable and are updated in my hands.

# (n_obs, n_latent) -> (n_obs,)
kl_div = dist.kl_divergence(posterior, prior).sum(dim=-1)
if self.prior=='mog' or self.prior=='mog_celltype':
u = posterior.rsample(sample_shape=(10,))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add the sample shape as a parameter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially, in mrVI we fixed it. We should then expose it through model.train.

def forward(self, x, y):
out = self.bn(x)
gamma, beta = self.embed(y.long().ravel()).chunk(2, 1)
out = gamma.view(-1, self.num_features) * out + beta.view(-1, self.num_features)
Copy link
Member Author

@canergen canergen Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure the .view() thing is needed anymore?

Suggested change
out = gamma.view(-1, self.num_features) * out + beta.view(-1, self.num_features)
out = gamma * out + beta

def forward(self, x, y):
out = self.ln(x)
gamma, beta = self.embed(y.long().ravel()).chunk(2, 1)
out = gamma.view(-1, self.num_features) * out + beta.view(-1, self.num_features)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants