-
Notifications
You must be signed in to change notification settings - Fork 374
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
feat: add get_normalized_expression to more models #3121
Open
ori-kron-wis
wants to merge
12
commits into
main
Choose a base branch
from
Ori-Additional-Models-Get-Norm-Expr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
125d377
peakvi as first example
ori-kron-wis 51b126b
remove the additonal flag
ori-kron-wis ff08cf3
destvi fix - not 100% its fine
ori-kron-wis ce0fe4a
fixed condscvi failed test
ori-kron-wis bc8901d
Merge remote-tracking branch 'origin/main' into Ori-Additional-Models…
ori-kron-wis c1492a6
Merge branch 'main' into Ori-Additional-Models-Get-Norm-Expr
ori-kron-wis 8388cea
Merge remote-tracking branch 'origin/main' into Ori-Additional-Models…
ori-kron-wis 598ad19
Merge remote-tracking branch 'origin/Ori-Additional-Models-Get-Norm-E…
ori-kron-wis 453e459
added AutoZI, CellAssign
ori-kron-wis fa21102
revert destvi, added poissonvi, gimvi
ori-kron-wis ee3d278
Merge branch 'main' into Ori-Additional-Models-Get-Norm-Expr
ori-kron-wis 5193e4d
Merge branch 'main' into Ori-Additional-Models-Get-Norm-Expr
ori-kron-wis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
from collections import OrderedDict | ||
from typing import Literal | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import numpy as np | ||
import torch | ||
from torch.distributions import Normal | ||
|
||
from scvi import REGISTRY_KEYS | ||
from scvi.distributions import NegativeBinomial | ||
from scvi.module._constants import MODULE_KEYS | ||
from scvi.module.base import BaseModuleClass, LossOutput, auto_move_data | ||
from scvi.nn import FCLayers | ||
|
||
if TYPE_CHECKING: | ||
from collections import OrderedDict | ||
from typing import Literal | ||
|
||
import numpy as np | ||
from torch.distributions import Distribution | ||
|
||
|
||
def identity(x): | ||
"""Identity function.""" | ||
|
@@ -179,24 +187,47 @@ def __init__( | |
torch.nn.Linear(n_hidden, n_labels + 1), | ||
) | ||
|
||
def _get_inference_input(self, tensors): | ||
# we perform MAP here, so we just need to subsample the variables | ||
return {} | ||
def _get_inference_input( | ||
self, tensors: dict[str, torch.Tensor] | ||
) -> dict[str, torch.Tensor | None]: | ||
return { | ||
MODULE_KEYS.X_KEY: tensors[REGISTRY_KEYS.X_KEY], | ||
MODULE_KEYS.BATCH_INDEX_KEY: tensors.get(REGISTRY_KEYS.BATCH_KEY, None), | ||
} | ||
|
||
def _get_generative_input(self, tensors, inference_outputs): | ||
def _get_generative_input(self, tensors, inference_outputs, transform_batch=None): | ||
x = tensors[REGISTRY_KEYS.X_KEY] | ||
ind_x = tensors[REGISTRY_KEYS.INDICES_KEY].long().ravel() | ||
|
||
input_dict = {"x": x, "ind_x": ind_x} | ||
batch_index = tensors[REGISTRY_KEYS.BATCH_KEY] | ||
if transform_batch is not None: | ||
batch_index = torch.ones_like(batch_index) * transform_batch | ||
|
||
input_dict = {"x": x, "ind_x": ind_x, "batch_index": batch_index} | ||
return input_dict | ||
|
||
@auto_move_data | ||
def inference(self): | ||
"""Run the inference model.""" | ||
return {} | ||
def inference( | ||
self, | ||
x: torch.Tensor, | ||
batch_index: torch.Tensor | None = None, | ||
n_samples: int = 1, | ||
) -> dict[str, torch.Tensor | Distribution]: | ||
"""High level inference method. | ||
|
||
Runs the inference (encoder) model. | ||
""" | ||
encoder_input = [x] | ||
|
||
z = self.V_encoder(*encoder_input) | ||
# z = self.gamma_encoder(*encoder_input) | ||
|
||
return { | ||
MODULE_KEYS.Z_KEY: z, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't really make sense. Please remove VAEmixin from DestVI |
||
} | ||
|
||
@auto_move_data | ||
def generative(self, x, ind_x): | ||
def generative(self, x, ind_x, batch_index, transform_batch: torch.Tensor | None = None): | ||
"""Build the deconvolution model for every cell in the minibatch.""" | ||
m = x.shape[0] | ||
library = torch.sum(x, dim=1, keepdim=True) | ||
|
@@ -206,6 +237,9 @@ def generative(self, x, ind_x): | |
x_ = torch.log(1 + x) | ||
# subsample parameters | ||
|
||
if transform_batch is not None: | ||
batch_index = torch.ones_like(batch_index) * transform_batch | ||
|
||
if self.amortization in ["both", "latent"]: | ||
gamma_ind = torch.transpose(self.gamma_encoder(x_), 0, 1).reshape( | ||
(self.n_latent, self.n_labels, -1) | ||
|
@@ -245,10 +279,11 @@ def generative(self, x, ind_x): | |
|
||
return { | ||
"px_o": self.px_o, | ||
"px_rate": px_rate, | ||
"px": px_rate, | ||
"px_scale": px_scale, | ||
"gamma": gamma_ind, | ||
"v": v_ind, | ||
"batch_index": batch_index, | ||
} | ||
|
||
def loss( | ||
|
@@ -261,7 +296,7 @@ def loss( | |
): | ||
"""Compute the loss.""" | ||
x = tensors[REGISTRY_KEYS.X_KEY] | ||
px_rate = generative_outputs["px_rate"] | ||
px_rate = generative_outputs["px"] | ||
px_o = generative_outputs["px_o"] | ||
gamma = generative_outputs["gamma"] | ||
v = generative_outputs["v"] | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is CellAssign intended for these functions? I would remove it here.