1
Instructor:
Welcome to BME 603/606�
Computational Methods for�Biological Modeling & Simulation
Assistant Professor of Biomedical Engineering�Affiliate, Data Science Institute�Affiliate, Biophysics Graduate Program�Affiliate, Center for Genomic Science Innovation�Affiliate, Wisconsin Institute for Translational Neuroengineering �University of Wisconsin-Madison
DHANANJAY ‘Jay’ BHASKAR
Course Website: https://bio-modeling-uw-madison-f26.github.io/
2
BME 603/606: Computational Methods for Biological Modeling & Simulation
Announcements / Reflection
3
BME 603/606: Computational Methods for Biological Modeling & Simulation
Ordinary differential equations
Two-compartment oral absorption model:
With ka = 1.2 hr⁻¹ and ke = 0.15 hr⁻¹ over 24 hr.
• This is an Initial Value Problem (IVP)
� • General form: y'(t) = f(t, y), y(0) = y0 where y = [A, C]ᵀ
Closed forms exist for linear systems
Numerical solvers needed for nonlinear ODEs
4
BME 603/606: Computational Methods for Biological Modeling & Simulation
Forward Euler method
Discretize [a, b] into N steps of size h = (b-a)/N, with tᵢ = a + i·h
Taylor expansion to first order gives the update rule:
(explicit: right-hand side evaluated at the current step)
5
BME 603/606: Computational Methods for Biological Modeling & Simulation
Python implementation
import numpy as np
ka, ke = 1.2, 0.15; F_dose = 500.0
# ODE: y = [A, C], dy/dt = f(t, y)
def f(t, y):
A, C = y
return np.array([-ka*A, ka*A - ke*C])
T = 24.0; N = 2400 # h = 0.01 hr (stable: h << 2/ka ~ 1.67)
t = np.linspace(0, T, N+1)
h = t[1] - t[0]
y = np.zeros((N+1, 2)); y[0] = [F_dose, 0.0]
for i in range(N):
y[i+1] = y[i] + h * f(t[i], y[i]) # explicit update
6
BME 603/606: Computational Methods for Biological Modeling & Simulation
Backward Euler method
Evaluate the right-hand side at the NEXT time step:
(implicit: yᵢ₊₁ appears on both sides - must solve at each step)
Solving for yᵢ₊₁:
• Linear f: rearrange to solve a linear system at each step� • Nonlinear f: use Newton iteration at each step
Advantages over Forward Euler:
• Unconditionally stable: stable for any h (linear problems)� • Essential for stiff problems (Forward Euler needs tiny h)
7
BME 603/606: Computational Methods for Biological Modeling & Simulation
Backward Euler method
For y′ = J·y, Backward Euler becomes yᵢ₊₁ = (I − h·J)⁻¹ yᵢ
ka, ke = 1.2, 0.15; F_dose = 500.0
J = np.array([[-ka, 0.0],
[ ka, -ke ]]) # Jacobian of y' = J*y
# (I - h*J) y_{i+1} = y_i
T = 24.0; N = 240 # h = 0.1 hr
t = np.linspace(0, T, N+1)
h = t[1] - t[0]
M = np.eye(2) - h * J # factor once (J is constant)
y = np.zeros((N+1, 2)); y[0] = [F_dose, 0.0]
for i in range(N):
y[i+1] = np.linalg.solve(M, y[i])
8
BME 603/606: Computational Methods for Biological Modeling & Simulation
Runge-Kutta Methods
Classical RK4 (4th-order):
k_1 = h * f(t_i, y_i)
k_2 = h * f(t_i + h/2, y_i + k_1/2)
k_3 = h * f(t_i + h/2, y_i + k_2/2)
k_4 = h * f(t_i + h, y_i + k_3)
y_{i+1} = y_i + (1/6)(k_1 + 2k_2 + 2k_3 + k_4)
• Global error: O(h⁴) - much more accurate than Euler for same h� • Explicit and single-step
• Cost: 4 function evaluations per step
9
BME 603/606: Computational Methods for Biological Modeling & Simulation
Python: scipy.integrate.solve_ivp
from scipy.integrate import solve_ivp
import numpy as np
ka, ke = 1.2, 0.15; F_dose = 500.0
def f(t, y):
A, C = y
return [-ka*A, ka*A - ke*C]
sol = solve_ivp(f,
t_span = (0, 24), # integration interval
y0 = [F_dose, 0.0], # initial condition
method = 'RK45', # 4(5)-th order adaptive RK
t_eval = np.linspace(0, 24, 500), # output time points
rtol = 1e-6, atol = 1e-8, # tolerances
)
10
BME 603/606: Computational Methods for Biological Modeling & Simulation
Direct graph representation
Directed graph G = (V, E)
Adjacency matrix A (n × n, n = |V|)
11
BME 603/606: Computational Methods for Biological Modeling & Simulation
Example
1
2
3
4
j (source node)
A
1
2
3
4
1
0
0
0
1
2
1
0
0
0
3
1
0
0
0
4
0
1
1
0
i (dest.)
12
BME 603/606: Computational Methods for Biological Modeling & Simulation
Degree
�
13
BME 603/606: Computational Methods for Biological Modeling & Simulation
Node importance
Not all nodes in a network are equally important.
Examples:
14
BME 603/606: Computational Methods for Biological Modeling & Simulation
Node importance
Why not just use degree?
PageRank provides a recursive, globally-informed importance score.
15
BME 603/606: Computational Methods for Biological Modeling & Simulation
The Random Surfer Model
Original motivation: ranking web pages (Page & Brin, 1998).
Model definition
PageRank = stationary distribution
16
BME 603/606: Computational Methods for Biological Modeling & Simulation
PageRank: Mathematical formulation
The PageRank of node i is the sum of contributions from all nodes j that link to i:
Matrix form
Define the column-stochastic transition matrix M:
Then the PageRank vector r satisfies the fixed-point eqn:
17
BME 603/606: Computational Methods for Biological Modeling & Simulation
PageRank: Mathematical formulation
r is the principal eigenvector of M with eigenvalue λ = 1.
Each column of M sums to 1 → therefore, M is a (column-)stochastic matrix.
Markov chain interpretation
18
BME 603/606: Computational Methods for Biological Modeling & Simulation
Building the transition matrix
Problem: dangling nodes
We must handle dangling nodes before computing PageRank.
19
BME 603/606: Computational Methods for Biological Modeling & Simulation
Handling dangling nodes
Dangling nodes violate column-stochasticity.
Fix: redistribute dangling-node rank uniformly
For each dangling node j, replace its zero column with 1/n:
�
The fix assigns them a small, uniform baseline PageRank contribution
Let d ∈ {0,1}n be the dangling-node indicator. Then:
�
20
BME 603/606: Computational Methods for Biological Modeling & Simulation
Google matrix
Remaining problems with pure random walk
Solution: teleportation with damping factor α
Construct the Google matrix:
The full PageRank equation becomes:
The original paper used: α = 0.85 (still used today)
21
BME 603/606: Computational Methods for Biological Modeling & Simulation
PageRank as an eigenvalue problem
The PageRank vector r is the solution to:
r is the dominant eigenvector of the Google matrix G (eigenvalue λ₁ = 1)
Perron–Frobenius theorem
22
BME 603/606: Computational Methods for Biological Modeling & Simulation
Power iteration algorithm
1. Initialize:�
4. Return r(k+1) as the PageRank vector
23
BME 603/606: Computational Methods for Biological Modeling & Simulation
Python Implementation
def pagerank(A, alpha=0.85, tol=1e-6, max_iter=100):
"""PageRank via power iteration."""
n = A.shape[0]
# Build column-stochastic matrix; handle dangling nodes
d = A.sum(axis=0) # out-degrees
dangling = (d == 0)
d[dangling] = 1 # avoid divide-by-zero
M = A / d[np.newaxis, :] # normalize columns
M[:, dangling] = 1.0 / n # uniform teleport for dangling
# Power iteration
r = np.ones(n) / n # uniform initialization
for _ in range(max_iter):
r_new = alpha * M @ r + (1 - alpha) / n
if np.linalg.norm(r_new - r, 1) < tol:
return r_new
r = r_new
return r # return after max_iter
24
BME 603/606: Computational Methods for Biological Modeling & Simulation
Application: disease-gene prioritization
Motivation
Method: network propagation (Vanunu et al., 2010)
Initialize a score vector from the seed set S:
Propagate scores through the network iteratively:
Rank all genes/proteins by the converged score.
Vanunu et al., PLoS Comput Biol. 2010�Pham et al., Comput Struct Biotechnol J. 2025
25
BME 603/606: Computational Methods for Biological Modeling & Simulation
In-Class Exercises
Please ask Colin to mark you for completion before end of class.
Course Website: https://bio-modeling-uw-madison-f26.github.io/