scHopfield.tools.compute_jacobians

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

Compute Jacobian matrices and eigenvalues for all cells.

For each cell, computes the Jacobian matrix of the Hopfield dynamics: J = W * diag(dsigmoid/dx) - diag(gamma) where W is the interaction matrix, dsigmoid/dx is the derivative of the sigmoid activation, and gamma is the degradation rate.

Eigenvalues are stored in adata.obsm[‘jacobian_eigenvalues’]. Eigenvectors can optionally be computed but are stored temporarily and should be saved to disk using save_jacobians() to avoid memory issues.

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

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

  • degradation_key (str, optional (default: 'gamma')) – Base key for degradation rates (cluster-specific rates used if available)

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

  • compute_eigenvectors (bool, optional (default: False)) – Whether to compute eigenvectors (requires more memory and time)

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

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

Returns:

Returns adata if copy=True, otherwise modifies in place and returns None. Adds to adata.obsm: - ‘jacobian_eigenvalues’: Complex eigenvalues array of shape (n_cells, n_genes) If compute_eigenvectors=True, temporarily stores in adata.uns[‘jacobian_eigenvectors_temp’]

Return type:

Optional[AnnData]