Universal ODEs represent a powerful hybrid modeling paradigm that seamlessly combines the interpretability of mechanistic models with the flexibility of neural networks. This approach allows researchers to encode known biochemical mechanisms while using neural networks to capture unknown dynamics, model uncertainties, or missing regulatory components that traditional models might overlook.
The core concept of Universal ODEs is to augment a traditional mechanistic ODE system with a neural network component:dtdy=f(y,t,θ)+α⋅Gate(y)⋅NN(y,t,ϕ)where:
f(y,t,θ) represents the known mechanistic component with parameters θ
NN(y,t,ϕ) is a neural network with parameters ϕ that learns unknown dynamics
α is a scaling factor that controls the neural network contribution magnitude
Gate(y) is a smooth gating function that determines when and which parts of the neural network are active
This formulation provides several research advantages:
Mechanistic foundation: Preserves interpretable biochemical knowledge in the model structure
Data-driven discovery: Neural networks identify missing mechanisms or regulatory effects
The gate function is a sigmoid-activated linear transformation that controls neural network activation based on species concentrations. Its primary purpose is to prevent unphysical dynamics by suppressing corrections when species are absent (avoiding creation from nothing) while allowing the corrective network to focus on meaningful rate adjustments when species are present.Gate(y)=σ(Wg⋅y+bg)
import optaximport jax.numpy as jnpimport sympy as spimport matplotlib.pyplot as pltimport catalax as ctximport catalax.neural as cnnimport warningswarnings.filterwarnings("ignore")
For this tutorial, we’ll use competitive substrate inhibition as our test system, where the neural network will discover the missing inhibition term:
Copy
Ask AI
# Create true system with substrate inhibitionmodel = ctx.Model(name="Universal ODE Example")model.add_species(s0="Substrate")# True equation includes inhibition term (Ki)model.add_ode("s0", "-v_max * s0 / ( K_m + s0 * ( 1 + s0 / K_i ) )")# Set realistic parameter valuesmodel.parameters["v_max"].value = 7.0model.parameters["K_m"].value = 200.0model.parameters["K_i"].value = 137.0
Generate experimental data with multiple initial conditions to provide comprehensive training coverage:
Copy
Ask AI
# Create dataset with multiple initial conditionsdataset = ctx.Dataset.from_model(model)# Add diverse initial conditions spanning the concentration rangefor conc in [10.0, 50.0, 100.0, 200.0, 400.0]: dataset.add_initial(s0=conc)# Simulate the true systemconfig = ctx.SimulationConfig(t1=200, nsteps=10)simulated = model.simulate(dataset, config)
This incomplete model will show systematic deviations from the true data, particularly at high substrate concentrations where inhibition effects become significant.
Create a Universal ODE that combines the fitted mechanistic model with a neural network corrective term:
Copy
Ask AI
# Define Universal ODE with small neural networkuniversal_ode = cnn.UniversalODE.from_model( model=fitted_model, # Base mechanistic model width_size=3, # Small network to prevent overfitting depth=1, # Single hidden layer use_final_bias=True, # Allow baseline corrections weight_scale=1e-8, # Small initial weights final_activation=lambda x: x, # Linear output for rate corrections)
Architecture considerations for research:
Small networks (width=3, depth=1) prevent overfitting and encourage discovery of simple corrective terms
Linear final activation ensures rate corrections remain physically interpretable
Small weight initialization allows mechanistic components to dominate initially
Design a multi-phase training strategy that progressively integrates neural and mechanistic components:
Copy
Ask AI
strategy = cnn.Strategy()# Phase 1: Train only neural network componentstrategy.add_step( lr=1e-2, # Higher learning rate for exploration steps=1000, # Limited steps to prevent overfitting batch_size=2, # Small batches for detailed gradient information length=0.1, # Short trajectories for initial learning loss=optax.log_cosh, # Robust loss function train=cnn.Modes.MLP, # Train only neural network)# Phase 2: Joint training of neural and mechanistic componentsstrategy.add_step( lr=1e-3, # Reduced learning rate for refinement steps=2000, # More steps for convergence batch_size=2, loss=optax.log_cosh, train=cnn.Modes.BOTH, # Train both components)# Phase 3: Fine-tuningstrategy.add_step( lr=1e-4, # Very small learning rate for precision steps=5000, # Extended training for convergence batch_size=2, loss=optax.log_cosh, train=cnn.Modes.BOTH,)
Scientific rationale for training phases:
MLP-only phase: Allows neural network to identify systematic errors without interfering with mechanistic parameters
Joint training: Enables fine-tuning of both components for optimal integration
Extended fine-tuning: Ensures convergence and stability of the hybrid model
Universal ODEs provide unique analysis capabilities for understanding what the neural network learned:
Copy
Ask AI
# Plot neural network corrections across the input spacetrained.plot_corrections_over_input( simulated, show=True, figsize=(10, 4),)
This visualization reveals the magnitude and direction of neural network corrections as a function of substrate concentration, providing insights into:
Where the mechanistic model fails (regions with large corrections)
How the corrections scale with concentration (functional form insights)
For quantitative analysis, extract the raw corrective terms:
Copy
Ask AI
# Get corrective terms and corresponding statescorrections, states = trained.corrective_term(simulated)# Analyze correction patternsprint(f"Correction range: {corrections.min():.3f} to {corrections.max():.3f}")print(f"Mean absolute correction: {jnp.abs(corrections).mean():.3f}")
The neural network corrections, while effective, remain black boxes. Symbolic regression can convert these corrections into interpretable mathematical expressions, enabling:
Mechanistic insight: Understanding what regulatory mechanisms the neural network discovered
Model validation: Checking if discovered terms align with known biochemical principles
Hypothesis generation: Suggesting new experimental directions based on discovered relationships
# Extract the best symbolic expressioneq = model_sr.get_best()sympy_eq = eq.sympy_format# Process equation for interpretabilityfree_numbers = sympy_eq.atoms() - sympy_eq.atoms(sp.Symbol) - sympy_eq.atoms(sp.Integer)number_map = {f"k{i+1}": abs(float(num)) for i, num in enumerate(free_numbers)}inv_number_map = {v: k for k, v in number_map.items()}# Create symbolic version with parameter namessymbolic_term = sympy_eq.subs(inv_number_map)print(f"Discovered corrective term: {symbolic_term}")
# Create enhanced mechanistic model with discovered termenhanced_model = fitted_model.model_copy(deep=True)enhanced_model.reset()# Set optimized mechanistic parametersfor i, parameter in enumerate(enhanced_model.parameters.values()): parameter.value = float(trained.parameters[i])# Add discovered symbolic correction to the original equationnew_equation = fitted_model.odes["s0"].equation + symbolic_termenhanced_model.add_ode("s0", new_equation)# Initialize symbolic regression parametersfor name, value in number_map.items(): enhanced_model.parameters[name].initial_value = value# Final optimization of the enhanced modelresult, final_model = ctx.optimize( model=enhanced_model, dataset=simulated, objective_fun=optax.l2_loss, method="leastsq",)
Mechanistic plausibility: Ensure discovered terms align with biochemical principles
Cross-validation: Test on independent datasets when available
Symbolic validation: Convert neural corrections to symbolic forms for interpretability
Universal ODEs represent a powerful paradigm for biochemical modeling that bridges the gap between mechanistic understanding and data-driven discovery. By combining interpretable mechanistic models with flexible neural networks, researchers can:
Preserve scientific knowledge while discovering new regulatory mechanisms
Generate testable hypotheses through symbolic regression of neural corrections
Improve model accuracy without sacrificing interpretability
Guide experimental design based on discovered model inadequacies
This hybrid approach enables a new form of scientific modeling where computational discovery complements experimental investigation, accelerating our understanding of complex biochemical systems while maintaining the interpretability essential for scientific progress.