scHopfield.tools.compute_jacobian_elements

scHopfield.tools.compute_jacobian_elements(adata: AnnData, gene_pairs: list, spliced_key: str = 'Ms', degradation_key: str = 'gamma', cluster_key: str = 'cell_type', device: str = 'cpu', store_in_obs: bool = True, copy: bool = False) AnnData | None[source]

Compute specific Jacobian matrix elements (partial derivatives).

Computes df_i/dx_j for specified gene pairs, where f_i is the dynamics function for gene i and x_j is the expression of gene j.

Parameters:
  • adata (AnnData) – Annotated data object with fitted parameters

  • gene_pairs (list of tuples) – List of (gene_i, gene_j) pairs to compute df_i/dx_j. Example: [(‘GATA1’, ‘GATA2’), (‘FLI1’, ‘KLF1’)]

  • spliced_key (str, optional (default: 'Ms')) – Layer key for spliced counts

  • degradation_key (str, optional (default: 'gamma')) – Base key for degradation rates

  • cluster_key (str, optional (default: 'cell_type')) – Key in adata.obs for cluster labels

  • device (str, optional (default: 'cpu')) – Device for computation: ‘cpu’ or ‘cuda’

  • store_in_obs (bool, optional (default: True)) – Whether to store results in adata.obs with formatted names

  • copy (bool, optional (default: False)) – If True, return a copy instead of modifying in-place

Returns:

Returns adata if copy=True, otherwise None. Adds to adata.obs columns like: ‘jacobian_df_GATA1_dx_GATA2’: Partial derivative of GATA1 w.r.t. GATA2

Return type:

AnnData or None

Notes

The Jacobian element is: df_i/dx_j = W_ij * dsigmoid/dx_j - gamma_i * delta_ij where delta_ij is the Kronecker delta (1 if i==j, 0 otherwise).