netmap.grn.inferrence.inferrence_model_wise_level

netmap.grn.inferrence.inferrence_model_wise_level(models, data_train_full_tensor, gene_names, xai_method='GradientShap', n_models=[10, 25, 50], background_type='zeros')[source]

Compute the GRN model-wise and save intermediate aggregates as layers.

Processes one complete model at a time (same order as inferrence_model_wise()), but additionally saves a snapshot of the mean attribution matrix at each model-count checkpoint listed in n_models. Snapshots after the first checkpoint are stored as named layers in the returned AnnData object so that downstream analysis can compare GRN stability across ensemble sizes.

Parameters:
  • models (list) – List of trained PyTorch autoencoder models. The forward_mu_only flag is set to True on each model internally.

  • data_train_full_tensor (torch.Tensor) – Expression tensor of shape (cells, genes) on CUDA.

  • gene_names (array-like) – Ordered gene names corresponding to columns of data_train_full_tensor.

  • xai_method (str) – Captum XAI method to use. One of 'GradientShap' (default), 'GuidedBackprop', 'Deconvolution'.

  • n_models (list of int) – Checkpoints (1-based model counts) at which the current running mean attribution matrix is saved as a layer. For example, [10, 25, 50] saves snapshots after models 10, 25, and 50 have been processed. The first checkpoint becomes grn_adata.X; subsequent checkpoints are stored as grn_adata.layers['aggregated_<n>']. Default [10, 25, 50].

  • background_type (str) – Baseline strategy for SHAP-style attribution. One of 'zeros' (default), 'randomize', 'data'.

Returns:

GRN object with shape (cells, genes^2) where X holds the mean attributions at the first checkpoint and each additional checkpoint is stored as a named layer. Returns None if no checkpoint in n_models was reached (e.g. fewer models were provided than the smallest value in n_models).

Return type:

anndata.AnnData or None