Neural network utils#

class scconfluence.nn.DSBatchNorm(num_features, n_domain, eps=1e-05, momentum=0.1)#

Bases: Module

Domain-specific Batch Normalization, implementation from https://github.com/woozch/DSBN

Parameters:
  • num_features – dimension of the features

  • n_domain – domain number

forward(x, y)#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

reset_parameters()#
reset_running_stats()#
class scconfluence.nn.DecoderPeakVI(n_input: int, n_output: int, n_layers: int = 2, n_hidden: int = 128, n_batch: int = 1, use_batch_norm: str | None = None, deeply_inject_covariates: bool = True)#

Bases: Module

Imported from https://github.com/YosefLab/scvi-tools/ and adapted. Decodes data from latent space of n_input dimensions n_output``dimensions. Uses a fully-connected neural network of ``n_hidden layers.

forward(z: Tensor, batch_index: Tensor)#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class scconfluence.nn.DecoderSCVI(n_input: int, n_output: int, n_layers: int = 1, n_hidden: int = 128, n_batch: int = 1, use_batch_norm: str | None = None, deeply_inject_covariates: bool = True, use_poisson: bool = False)#

Bases: Module

Imported from https://github.com/YosefLab/scvi-tools/ and adapted. Decodes data from latent space of n_input dimensions into n_output dimensions. Uses a fully-connected neural network of n_hidden layers.

forward(dispersion: str, z: Tensor, log_library: Tensor, batch_index: Tensor)#

The forward computation for a single sample.

class scconfluence.nn.FCLayers(n_layers, n_input, n_hidden, n_output, n_batch=1, deeply_inject_covariates=True, use_batch_norm=None, activation_fn=<class 'torch.nn.modules.activation.ReLU'>, last_activation=False, positive_out=False, dropout_rate=0.0, bias=True)#

Bases: Module

Imported from https://github.com/YosefLab/scvi-tools/ and adapted.

forward(x, batch_index)#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

inject_into_layer(layer_num) bool#

Helper to determine if covariates should be injected.

class scconfluence.nn.VariationalEncoder(n_input: int, n_output: int, n_layers: int = 1, n_hidden: int = 128, n_batch: int = 1, deeply_inject_covariates: bool = True, dropout_rate: float = 0.1, var_eps: float = 0.0001, var_activation=None, **kwargs)#

Bases: Module

Imported from https://github.com/YosefLab/scvi-tools/ and adapted. Encodes data of n_input dimensions into a latent space of n_output dimensions. Uses a fully-connected neural network of n_hidden layers.

forward(x: Tensor, batch_index: Tensor)#

The forward computation for a single sample.

scconfluence.nn.get_batch_norm(flag, n_out, n_batch)#

Wrapper to obtain a batch normalization layer. :param flag: whether to use batch norm and which type :param n_out: the number of features :param n_batch: the number of batches in the data

scconfluence.nn.one_hot(index: Tensor, n_cat: int) Tensor#

One hot a tensor of categories.

scconfluence.nn.reparameterize_gaussian(mu, var)#