cascade.model.CASCADE

class cascade.model.CASCADE(vars, n_particles=4, n_covariates=0, n_layers=1, hidden_dim=16, latent_dim=16, dropout=0.2, beta=0.1, scaffold_mod='Edgewise', sparse_mod='L1', acyc_mod='SpecNorm', latent_mod='EmbLatent', lik_mod='NegBin', kernel_mod='RBF', scaffold_graph=None, latent_data=None, scaffold_kws=None, sparse_kws=None, acyc_kws=None, latent_kws=None, lik_kws=None, kernel_kws=None, random_state=0, log_dir='.', _net=None)[source]

Bases: object

Causality-Aware Single-Cell Adaptive Discover/Deduction/Design Engine

Parameters:
  • vars (Index | list[str]) – List of variables to model

  • n_particles (int) – Number of SVGD particles

  • n_covariates (int) – Dimension of covariates

  • n_layers (int) – Number of MLP layers in the structural equations

  • hidden_dim (int) – MLP hidden layer dimension in the structural equations

  • latent_dim (int) – Dimension of the latent variable (see notes below on how to specify latent_data depending on latent_mod)

  • dropout (float) – Dropout rate

  • beta (float) – KL weight of the latent variable

  • scaffold_mod (str) – Scaffold graph module, must be one of {“Edgewise”, “Bilinear”}

  • sparse_mod (str) – Sparse prior module, must be one of {“L1”, “ScaleFree”}

  • acyc_mod (str) – Acyclic prior module, must be one of {“TrExp”, “SpecNorm”, “LogDet”}

  • latent_mod (str) – Latent module, must be one of {“NilLatent”, “EmbLatent”, “GCNLatent”}

  • lik_mod (str) – Causal likelihood module, must be one of {“Normal”, “NegBin”}

  • kernel_mod (str) – SVGD kernel module, must be one of {“KroneckerDelta”, “RBF”}

  • scaffold_graph (TypeVar(SimpleGraph, Graph, DiGraph) | None) – Optional scaffold graph

  • latent_data (DataFrame | TypeVar(SimpleGraph, Graph, DiGraph) | None) – Optional latent data (see notes below on how to specify latent_data depending on latent_mod)

  • scaffold_kws (Mapping[str, Any] | None) – Keyword arguments to the scaffold graph module, see Edgewise or Bilinear for details

  • sparse_kws (Mapping[str, Any] | None) – Keyword arguments to the sparse prior module, see L1 or ScaleFree for details

  • acyc_kws (Mapping[str, Any] | None) – Keyword arguments to the acyclic prior module, see TrExp, SpecNorm, or LogDet for details

  • latent_kws (Mapping[str, Any] | None) – Keyword arguments to the latent module, see NilLatent, EmbLatent, or GCNLatent for details

  • lik_kws (Mapping[str, Any] | None) – Keyword arguments to the causal likelihood module, see Normal or NegBin for details

  • kernel_kws (Mapping[str, Any] | None) – Keyword arguments to the SVGD kernel module, see KroneckerDelta or RBF for details

  • random_state (RandomState | int | None) – Random state

  • log_dir (PathLike) – Directory to store tensorboard logs

  • _net (CausalNetwork | None) – Internal use ONLY

Note

The setting for latent_dim and latent_data follows rules below:

  • When latent_mod="NilLatent", latent_data must be None. The latent variable is always the standard normal distribution with dimension of latent_dim.

  • When latent_mod="EmbLatent", latent_data must be a DataFrame, where the index is the variable names and the columns are the embedding dimensions. latent_dim but must be larger than 0, but does not need to equal the dimension of latent_data, as the latent variable is encoded from the provided embedding with a linear transformation.

  • When latent_mod="GCNLatent", latent_data must be a Graph or DiGraph, where the nodes are the variable names and the edges are latent connections. latent_dim must be larger than 0. The latent variable is encoded from the provided graph with a graph convolutional network.

Methods

counterfactual

Counterfactual deduction for the outcome of alternative interventions for an observed dataset

design

Targeted intervention design with continuous optimization

design_brute_force

Intervention design with brute-force exhaustion

design_error_curve

Fit an error curve against design scores

diagnose

Model diagnosis

discover

Causal discovery

explain

Explain counterfactual outcome with individual components

export_causal_graph

Export learned causal graph

export_causal_map

Export the reshaped causal map indicating which input gene is in each reshaped position for each output gene, useful for interpreting the result of explain().

import_causal_graph

Import pruned causal graph

jacobian

Compute the Jacobian matrix of the model

load

Load model from file

save

Save model to file

tune

Fine-tune structural equations with fixed causal structure