scHopfield.dynamics.ODESolver
- class scHopfield.dynamics.ODESolver(W: ndarray, bias_vector: ndarray, gamma: ndarray, threshold: ndarray, exponent: ndarray, x_min: float = 0.0, x_max: ndarray | None = None, fixed_indices: ndarray | None = None, fixed_values: ndarray | None = None)[source]
ODE solver for Hopfield network dynamics.
Solves: dx/dt = W * sigmoid(x) - gamma * x + I
With constraints to ensure expression values remain non-negative and bounded to prevent divergence. Supports fixing certain genes at constant values (e.g., for knockout/overexpression simulations).
- __init__(W: ndarray, bias_vector: ndarray, gamma: ndarray, threshold: ndarray, exponent: ndarray, x_min: float = 0.0, x_max: ndarray | None = None, fixed_indices: ndarray | None = None, fixed_values: ndarray | None = None)[source]
Initialize ODE solver.
- Parameters:
W (np.ndarray) – Interaction matrix
I (np.ndarray) – External input
gamma (np.ndarray) – Degradation rates
threshold (np.ndarray) – Sigmoid threshold parameters
exponent (np.ndarray) – Sigmoid exponent parameters
x_min (float, optional (default: 0.0)) – Minimum expression value (non-negative constraint)
x_max (np.ndarray, optional) – Maximum expression values per gene. If None, no upper bound.
fixed_indices (np.ndarray, optional) – Indices of genes to keep fixed (e.g., perturbed genes)
fixed_values (np.ndarray, optional) – Values to fix the genes at (must match length of fixed_indices)
Methods
__init__(W, bias_vector, gamma, threshold, ...)Initialize ODE solver.
dynamics(x, t)Compute dx/dt with soft boundary enforcement.
dynamics_batch(X, t)Compute dx/dt for a batch of states (n_cells, n_genes).
dynamics_ivp(t, x)Compute dx/dt for solve_ivp (arguments reversed).
set_fixed_genes(fixed_indices, fixed_values)Set genes to be held fixed during simulation.
solve(x0, t_span[, method, clip_each_step])Solve ODE from initial condition x0.