mofaflex.terms.MofaFlex#
- class mofaflex.terms.MofaFlex(n_factors, factor_prior='Normal', weight_prior='Normal', nonnegative_factors=False, nonnegative_weights=False, guiding_vars_obs_keys=None, guiding_vars_likelihoods='Normal', guiding_vars_scales=1.0, init_factors='random', init_scale=0.1)#
A MOFA-like term representing the product of two low-rank matrices.
The factor matrix has dimensions
n_samplesxn_total_factors, the weight matrix has dimensionsn_total_factorsxn_features. See the in-depth model description for details.- Parameters:
n_factors (
int) – Number of latent factors.factor_prior (
Union[Mapping[str|Sequence[str],Union[Literal['Constant','GaussianProcess','GSFA','Horseshoe','Normal','Laplace','SpikeSlab'],Prior]],Literal['Constant','GaussianProcess','GSFA','Horseshoe','Normal','Laplace','SpikeSlab'],Prior] (default:'Normal')) – Factor priors for each group (if dict) or for all groups (otherwise). The dictionary keys may be either strings, representing individual groups, or tuples of strings, in which case the corresponding value will be used for all groups named in the tuple.weight_prior (
Union[Mapping[str|Sequence[str],Union[Literal['Constant','GaussianProcess','Horseshoe','InformedHorseshoe','Normal','Laplace','SpikeSlab'],Prior]],Literal['Constant','GaussianProcess','Horseshoe','InformedHorseshoe','Normal','Laplace','SpikeSlab'],Prior] (default:'Normal')) – Weight priors for each group (if dict) or for all groups (otherwise). The dictionary keys may be either strings, representing individual views, or tuples of strings, in which case the corresponding value will be used for all views named in the tuple.nonnegative_factors (
Mapping[str,bool] |bool(default:False)) – Non-negativity constraints for factors for each group (if dict) or for all groups (if bool).nonnegative_weights (
Mapping[str,bool] |bool(default:False)) – Non-negativity constraints for weights for each view (if dict) or for all views (if bool).guiding_vars_obs_keys (
str|Sequence[str] |Mapping[str,Mapping[str,str]] |None(default:None)) – Keys of .obs attribute of eachAnnDataobject that contains guiding variable values.guiding_vars_likelihoods (
Union[Mapping[str,str],Literal['Normal','Categorical','Bernoulli'],None] (default:'Normal')) – Likelihood for each guiding variable (if dict) or for all guiding variables (if str).guiding_vars_scales (
Mapping[str,float] |float(default:1.0)) – Scale for the likelihood of each guiding variable, to put more or less emphasis on them during training.init_factors (
Union[float,Literal['random','orthogonal','pca']] (default:'random')) – Initialization method for factors.init_scale (
float(default:0.1)) – Initialization scale of Normal distribution for factors.
Attributes table#
Covariates for each group. |
|
Covariate names for each group where they could be inferred from the input. |
|
Between-group correlation for each factor. |
|
Inferred lengthscales for each factor. |
|
Inferred variance scales (smoothness) for each factor. |
|
Factor names. |
|
Ordering of factors by explained variance (highest to lowest). |
|
Number of unguided factors. |
|
Number of guided factors. |
|
Number of informed factors. |
|
Total number of factors. |
|
Time-warped covariates for each group, if dynamic time warping was enabled. |
|
Time-warped covariates for each group, if dynamic time warping was enabled. |
|
Covariates for each group. |
|
Covariate names for each group where they could be inferred from the input. |
|
Between-group correlation for each factor. |
|
Inferred lengthscales for each factor. |
|
Inferred variance scales (smoothness) for each factor. |
Methods table#
|
Annotation matrices for each view. |
|
Get all latent functions. |
|
Get the factor matrices Z for each group. |
|
The perturbation effect matrix \(\mat\beta\). |
|
The posterior inclusion probabilities \(p\). |
Get the results of significance testing of annotations against factors. |
|
|
The posterior probabilities \(\theta\) that the value is sampled from the foreground distribution. |
|
The posterior probabilities \(\theta\) that the value is sampled from the foreground distribution. |
|
Get all latent functions. |
|
Get the weight matrices W for each view. |
Attributes#
- MofaFlex.factor_covariates#
Covariates for each group.
Important
This property is only available when using the
GaussianProcessprior.
- MofaFlex.factor_covariates_names#
Covariate names for each group where they could be inferred from the input.
Important
This property is only available when using the
GaussianProcessprior.
- MofaFlex.factor_gp_group_correlation#
Between-group correlation for each factor.
Important
This property is only available when using the
GaussianProcessprior.
- MofaFlex.factor_gp_lengthscale#
Inferred lengthscales for each factor.
Important
This property is only available when using the
GaussianProcessprior.
- MofaFlex.factor_gp_scale#
Inferred variance scales (smoothness) for each factor.
Important
This property is only available when using the
GaussianProcessprior.
- MofaFlex.factor_names#
Factor names.
- MofaFlex.factor_order#
Ordering of factors by explained variance (highest to lowest).
- MofaFlex.n_factors#
Number of unguided factors.
- MofaFlex.n_guided_factors#
Number of guided factors.
- MofaFlex.n_informed_factors#
Number of informed factors.
Important
This property is only available when using the
InformedHorseshoeprior.
- MofaFlex.n_total_factors#
Total number of factors.
- MofaFlex.warped_factor_covariates#
Time-warped covariates for each group, if dynamic time warping was enabled.
Important
This property is only available when using the
GaussianProcessprior.
- MofaFlex.warped_weight_covariates#
Time-warped covariates for each group, if dynamic time warping was enabled.
Important
This property is only available when using the
GaussianProcessprior.
- MofaFlex.weight_covariates#
Covariates for each group.
Important
This property is only available when using the
GaussianProcessprior.
- MofaFlex.weight_covariates_names#
Covariate names for each group where they could be inferred from the input.
Important
This property is only available when using the
GaussianProcessprior.
- MofaFlex.weight_gp_group_correlation#
Between-group correlation for each factor.
Important
This property is only available when using the
GaussianProcessprior.
- MofaFlex.weight_gp_lengthscale#
Inferred lengthscales for each factor.
Important
This property is only available when using the
GaussianProcessprior.
- MofaFlex.weight_gp_scale#
Inferred variance scales (smoothness) for each factor.
Important
This property is only available when using the
GaussianProcessprior.
Methods#
- MofaFlex.get_annotations(ordered=False)#
Annotation matrices for each view.
- Parameters:
ordered (
bool(default:False)) – Whether to return the factors ordered by explained variance (highest to lowest).- Return type:
Important
This method is only available when using the
InformedHorseshoeprior.
- MofaFlex.get_factor_gps(moment='mean', x=None, batch_size=None, ordered=False)#
Get all latent functions.
- Parameters:
moment (
Literal['mean','std'] (default:'mean')) – Which moment of the posterior distribution to return.x (
Mapping[str,ndarray|Tensor] |None(default:None)) – Covariate values for each group. IfNone, will return latent function values at covariate coordinates used for training.batch_size (
int|None(default:None)) – Minibatch size. Only has an effect ifxis notNone. Defaults to the minibatch size used for training.ordered (
bool(default:False)) – Whether to return the factors ordered by explained variance (highest to lowest).
- Return type:
Important
This method is only available when using the
GaussianProcessprior.
- MofaFlex.get_factors(moment='mean', ordered=False, sparse_type='mix')#
Get the factor matrices Z for each group.
- Parameters:
moment (
Literal['mean','std'] (default:'mean')) – Which moment of the posterior distribution to return.ordered (
bool(default:False)) – Whether to return the factors ordered by explained variance (highest to lowest).sparse_type (
Literal['raw','mix','thresh'] (default:'mix')) –How to handle sparsity when using the spike and slab prior.
raw: Do nothing, return inferred values for all entries.
mix: Return the corresponding moment of a mixture distribution of two Normal distributions: One centered at 0 and the other centered at the inferred non-sparse value. The mixture is weighted by the inferred sparsity probability.
thresh: Set all values with a sparsity probablity > 0.5 to 0.
Important
This argument is only available when using the
GSFAprior.
- Return type:
- MofaFlex.get_perturbation_effects(ordered=False)#
The perturbation effect matrix \(\mat\beta\).
- Parameters:
ordered (
bool(default:False)) – Whether to return the factors ordered by explained variance (highest to lowest).- Return type:
Important
This method is only available when using the
GSFAprior.
- MofaFlex.get_posterior_inclusion_probabilities(ordered=False)#
The posterior inclusion probabilities \(p\).
- Parameters:
ordered (
bool(default:False)) – Whether to return the factors ordered by explained variance (highest to lowest).- Return type:
Important
This method is only available when using the
GSFAprior.
- MofaFlex.get_significant_annotations() Mapping[str, DataFrame]#
Get the results of significance testing of annotations against factors.
The significance testing is an implementation of PCGSE [FLM15]. While originally intended to assign annotations to uninformed factors, here it is used as a diagnostic plot to find factors that are mismatched to their annotations.
- Returns:
PCGSE results for each view or
Noneif the model does not have prior annotations.
Important
This method is only available when using the
InformedHorseshoeprior.
- MofaFlex.get_sparse_factor_probabilities(ordered=False)#
The posterior probabilities \(\theta\) that the value is sampled from the foreground distribution.
- Parameters:
ordered (
bool(default:False)) – Whether to return the factors ordered by explained variance (highest to lowest).- Return type:
Important
This method is only available when using the
SpikeSlabprior.
- MofaFlex.get_sparse_weight_probabilities(ordered=False)#
The posterior probabilities \(\theta\) that the value is sampled from the foreground distribution.
- Parameters:
ordered (
bool(default:False)) – Whether to return the factors ordered by explained variance (highest to lowest).- Return type:
Important
This method is only available when using the
SpikeSlabprior.
- MofaFlex.get_weight_gps(moment='mean', x=None, batch_size=None, ordered=False)#
Get all latent functions.
- Parameters:
moment (
Literal['mean','std'] (default:'mean')) – Which moment of the posterior distribution to return.x (
Mapping[str,ndarray|Tensor] |None(default:None)) – Covariate values for each group. IfNone, will return latent function values at covariate coordinates used for training.batch_size (
int|None(default:None)) – Minibatch size. Only has an effect ifxis notNone. Defaults to the minibatch size used for training.ordered (
bool(default:False)) – Whether to return the factors ordered by explained variance (highest to lowest).
- Return type:
Important
This method is only available when using the
GaussianProcessprior.
- MofaFlex.get_weights(moment='mean', ordered=False, sparse_type='mix')#
Get the weight matrices W for each view.
- Parameters:
moment (
Literal['mean','std'] (default:'mean')) – Which moment of the posterior distribution to return.ordered (
bool(default:False)) – Whether to return the factors ordered by explained variance (highest to lowest).sparse_type (
Literal['raw','mix','thresh'] (default:'mix')) –How to handle sparsity when using the spike and slab prior.
raw: Do nothing, return inferred values for all entries.
mix: Return the corresponding moment of a mixture distribution of two Normal distributions: One centered at 0 and the other centered at the inferred non-sparse value. The mixture is weighted by the inferred sparsity probability. This is what MOFA does.
thresh: Set all values with a sparsity probablity > 0.5 to 0.
Important
This argument is only available when using the
SpikeSlabprior.
- Return type: