scyan.module.ScyanModule
Bases: LightningModule
Core logic contained inside the main class Scyan. Do not use this class directly.
Attributes:
Name | Type | Description |
---|---|---|
real_nvp |
RealNVP
|
The Normalizing Flow (a RealNVP object) |
prior |
PriorDistribution
|
The prior \(U\) (a PriorDistribution object) |
pi_logit |
Tensor
|
Logits used to learn the population weights |
Source code in scyan/module/scyan_module.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
log_pi: Tensor
property
Log population weights \(log \; \pi\).
pi: Tensor
property
Population weights \(\pi\)
prior_z: distributions.Distribution
property
Population prior, i.e. \(Categorical(\pi)\).
Returns:
Type | Description |
---|---|
Distribution
|
Distribution of the population index. |
__init__(rho, n_covariates, is_continuum_marker, hidden_size, n_hidden_layers, n_layers, prior_std, temperature)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rho |
Tensor
|
Tensor $ ho$ representing the knowledge table. |
required |
n_covariates |
int
|
Number of covariates \(M_c\) considered. |
required |
hidden_size |
int
|
MLP ( |
required |
n_hidden_layers |
int
|
Number of hidden layers for the MLP ( |
required |
n_layers |
int
|
Number of coupling layers. |
required |
prior_std |
float
|
Standard deviation \(\sigma\) of the cell-specific random variable \(H\). |
required |
temperature |
float
|
Temperature to favour small populations. |
required |
Source code in scyan/module/scyan_module.py
compute_probabilities(x, covariates, use_temp=False)
Compute probabilities used in the loss function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Tensor
|
Inputs of size \((B, M)\). |
required |
covariates |
Tensor
|
Covariates of size \((B, M_c)\). |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, Tensor, Tensor]
|
Log probabilities of size \((B, P)\), the log det jacobian and the latent expressions of size \((B, M)\). |
Source code in scyan/module/scyan_module.py
forward(x, covariates)
Forward implementation, going through the complete flow \(f_{\phi}\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Tensor
|
Inputs of size \((B, M)\). |
required |
covariates |
Tensor
|
Covariates of size \((B, M_c)\) |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, Tensor, Tensor]
|
Tuple of (outputs, covariates, lod_det_jacobian sum) |
Source code in scyan/module/scyan_module.py
inverse(u, covariates)
Go through the flow in reverse direction, i.e. \(f_{\phi}^{-1}\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
u |
Tensor
|
Latent expressions of size \((B, M)\). |
required |
covariates |
Tensor
|
Covariates of size \((B, M_c)\) |
required |
Returns:
Type | Description |
---|---|
Tensor
|
Outputs of size \((B, M)\). |
Source code in scyan/module/scyan_module.py
kl(x, covariates, use_temp)
Compute the module loss for one mini-batch.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Tensor
|
Inputs of size \((B, M)\). |
required |
covariates |
Tensor
|
Covariates of size \((B, M_c)\). |
required |
use_temp |
bool
|
Whether to consider temperature is the KL term. |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, Tensor]
|
The KL loss term. |
Source code in scyan/module/scyan_module.py
log_pi_temperature(T)
Compute the log weights with temperature \(log \; \pi^{(-T)}\)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
T |
float
|
Temperature. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
Log weights with temperature. |
Source code in scyan/module/scyan_module.py
sample(n_samples, covariates, z=None, return_z=False)
Sampling cell-marker expressions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_samples |
int
|
Number of cells to sample. |
required |
covariates |
Tensor
|
Tensor of covariates. |
required |
z |
Union[int, Tensor, None]
|
Either one population index or a Tensor of population indices. If None, sampling from all populations. |
None
|
return_z |
bool
|
Whether to return the population Tensor. |
False
|
Returns:
Type | Description |
---|---|
Tuple[Tensor, Tensor]
|
Sampled cells expressions and, if |