alphaFeedback

WorksMathematics

Neural ODE’s - Theory and Application: From Residual Networks to Continuous-Depth Dynamics

AI contributions
  • Claude Opus · multiple versions
View details

Abstract

This paper explores Neural Ordinary Differential Equations (Neural ODE’s) and then applies them to a real-world example of bacteria growth. We solve the population Initial Value Problem analytically using Bernoulli form and then compare it to the dynamics learned by a neural network. We demonstrate that Neural ODE’s can accurately reconstruct continuous, dynamic systems from discrete data.

Los Altos Hills, CA

Introduction

Residual Networks

In 2015, Residual Networks were introduced by Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun.1 ResNets allowed for the training neural networks using discrete layers, a process identical to Euler’s Method for solving ODE’s.

Then, in 2018, Chen et al. proposed Neural ODE’s, which took the limit of ResNet layers as step size approached zero. Essentially, this work parameterized the derivative of a hidden state in the neural network, further allowing for continuous-time modeling.2

Residual Networks and Neural ODE networks

Figure 1. Residual Networks define a discrete sequence of transformations whereas Neural ODE networks learn the dynamics of a vector field to continuously transform its state (Chen et al.).

We will apply ODE techniques, like Bernoulli forms to solve initial value problems, to the field of Machine Learning and Mathematical Biology.

Background Knowledge

The Research Question

Now that we know Neural ODE’s attempt to learn continuous dynamics, it would not be wrong to question the relevance of this. In comparison to ResNets, Neural Networks define the rate of change of output rather than just the output. This means that the Network is learning a vector field rather than a static map. Furthermore, when trying to make a prediction to calculate the next data point y(t1)y(t_1) from initial input y(t0)y(t_0), we must solve an Initial Value Problem given by

y(t1)=y(t0)+∫t0t1f(y(t),t,θ)dty(t_1) = y(t_0) + \int_{t_0}^{t_1} f(y(t),t,\theta)\mathrm{d}t

where ff is a Neural Network parameterized by θ\theta.1

However, instead of solving this equation analytically, Neural Networks computationally solve the ODE using numerical integration methods. Specifically, they use methods like Euler’s Method or Runge Kutta to approximate integration.2

This brings us to the research question: How can we continuously predict successive data points with a Neural ODE, and how accurate will it be?

Chapter 2

Summary of ODE Techniques

Bernoulli Differential Equations

A key to answering the focus question lies in the Bernoulli form. To recap, a non-linear, first-order ODE can be classified as a Bernoulli ODE if it is given in the form

dydx+P(t)y=Q(t)yn.\frac{dy}{dx} + P(t)y = Q(t)y^n.

The reason that this is so special is that Bernoulli ODE’s can be solved relatively simply. The steps to solve Bernoulli ODE’s are as follows:

  1. Divide by yny^n:

y−ndydx+P(x)y1−n=Q(x)y^{-n}\frac{dy}{dx} + P(x)y^{1-n} = Q(x)
  1. Define variable substitution, let

z=y1−nz = y^{1-n}

then

dzdx=dzdy⋅dydx⇒dzdx=(1−n)y−n⋅dydx\begin{aligned} \frac{dz}{dx} = \frac{dz}{dy}\cdot\frac{dy}{dx} \\ &\Rightarrow\frac{dz}{dx} = (1-n)y^{-n}\cdot\frac{dy}{dx} \end{aligned}
  1. Multiply the ODE:

(1−n)y−ndydx+(1−n)P(x)y1−n=(1−n)Q(x)(1-n)y^{-n}\frac{dy}{dx} + (1-n)P(x)y^{1-n} = (1-n)Q(x)
  1. Make substitution:

dzdx+(1−n)P(x)z=(1−n)Q(x)\frac{dz}{dx} + (1-n)P(x)z = (1-n)Q(x)
  1. Solve for z(x)z(x) using integrating factor μ(x)=e∫(1−nP(x)) dx\mu(x) = e^{\int(1-nP(x))\,dx}

  1. Substitute back for z=y1−nz = y^{1-n} and find implicit/explicit solutions

This is the algorithm for analytically solving Bernoulli ODE’s. However, in the example next, we will show how Neural ODE’s can forego this process using a training phase.

Example and Model Derivation

Bacteria Population

In Mathematical Biology, states of systems like population size are tracked over time. Here are some field concepts that will be helpful to know:

  • Vector Field: A map that assigns some direction and magnitude at every point in the space

    • This is what the Neural ODE will learn

  • Carrying Capacity (KK): The maximum population size that an environment can sustain with limited resources

  • Intrinsic Growth Rate (rr): How fast the population grows given unlimited resources

In simple population models with unlimited resources, exponential growth occurs. However, since resources are finite in the real world, we must model population using a logistic model given by:

dydt=ry(1−yK)\frac{dy}{dt}=ry\left(1-\frac{y}{K}\right)

When population yy is small, the term (1−yK)≈1\left(1-\frac{y}{K}\right)\approx1 and the growth of yy is exponential. However, as population yy approaches carrying capacity KK, the term approaches 00, thus stopping growth of yy.

Problem Setup and Solution

Suppose we aim to find the population function y(t)y(t) given the following parameters:

  • r=0.5r = 0.5 (growth rate per hour)

  • K=10K = 10 (carrying capacity of 10 bacteria units)

  • y0=0.1y_0 = 0.1 (initial bacteria unit population)

Therefore, we can model the initial value problem as such

dydt=ry(1−yK)⇒dydt=ry−rKy2\begin{aligned} \frac{dy}{dt} = ry\left(1-\frac{y}{K}\right) \\ &\Rightarrow\frac{dy}{dt} = ry-\frac{r}{K}y^2 \end{aligned}

Compared to the Bernoulli form, we can identify P(t)=−rP(t)=-r, Q(t)=−rKQ(t)=-\frac{r}{K}, and n=2n=2.

Let’s now follow the steps to solve Bernoulli ODE's:

Define variable substitution, let

z=y1−n⇒z=y−1z=y^{1-n}\Rightarrow z=y^{-1}

then

dzdt=−y−2dydt\frac{dz}{dt}=-y^{-2}\frac{dy}{dt}

Now multiply the ODE by −y−2-y^{-2} and substitute:

−y−2dydt+ry−1=rK-y^{-2}\frac{dy}{dt}+ry^{-1}=\frac{r}{K}
z′+rz=rKz' + rz = \frac{r}{K}

This is now a linear, first-order ODE! To solve this linear equation, we calculate the Integrating Factor, μ(t)\mu(t):

μ(t)=e∫r dt=ert\mu(t) = e^{\int r\,dt} = e^{rt}

Now multiply the entire linear equation by erte^{rt}:

ertz′+rertz=rKerte^{rt}z' + re^{rt}z = \frac{r}{K}e^{rt}

We recognize the left side as the derivative of the product (ertz)(e^{rt}z):

ddt[ertz]=rKert\frac{d}{dt}[e^{rt}z] = \frac{r}{K}e^{rt}

Now integrate both sides:

∫ddt[ertz]=∫rKert dt\int\frac{d}{dt}[e^{rt}z] = \int\frac{r}{K}e^{rt}\,dt
ertz=rK(1rert)+Certz⇒1Kert+C\begin{aligned} e^{rt}z = \frac{r}{K}\left(\frac{1}{r}e^{rt}\right) + Ce^{rt}z \\ &\Rightarrow\frac{1}{K}e^{rt} + C \end{aligned}

Solving for zz:

z=1K+Ce−rtz = \frac{1}{K} + Ce^{-rt}

Now we can substitute back for yy:

y(t)=11K+Ce−rt⇒y(t)=K1+CKe−rt\begin{aligned} y(t) = \frac{1}{\frac{1}{K} + Ce^{-rt}} \\ &\Rightarrow y(t) = \frac{K}{1 + CKe^{-rt}} \end{aligned}

Finally, let’s apply our initial conditions y(0)=0.1y(0) = 0.1, knowing that K=10K = 10 and r=0.5r = 0.5:

y(0)=K1+CK(1)⇒y(0)=K1+CKy(0) = \frac{K}{1 + CK(1)} \Rightarrow y(0) = \frac{K}{1 + CK}

Solving for the arbitrary constant term A=CKA = CK:

A=K−y0y0=10−0.10.1=99A = \frac{K-y_0}{y_0} = \frac{10-0.1}{0.1} = 99

Substituting AA back into the general solution gives the specific solution:

y(t)=101+99e−0.5ty(t) = \frac{10}{1 + 99e^{-0.5t}}
Sigmoid Function representing Bacteria Growth

Figure 3.1. Sigmoid Function representing Bacteria Growth

And finally, we have constructed our logistic population growth model with a particular solution. This solution and graph will be the benchmark that the Neural ODE will be trained against.

Chapter 4

Predictions

Neural ODE Construction and Limitations

Using our derived model y(t)=101+99e−0.5ty(t) = \frac{10}{1+99e^{-0.5t}}, we predict the population at time t=10t = 10 hours:

y(10)=101+99e−0.5(10)=101+99e−5y(10) = \frac{10}{1+99e^{-0.5(10)}} = \frac{10}{1+99e^{-5}}
y(10)≈101+99(0.0067)≈101+0.663≈6.01y(10) \approx\frac{10}{1+99(0.0067)} \approx\frac{10}{1+0.663} \approx6.01

After 10 hours, the bacteria population will be about 6.01 units. Note: The model assumes that rr and KK are constant, but in reality, carrying capacity often fluctuates with the environment. We also assumed that the population is large enough to be treated as continuous, which would not hold for small populations (like discrete individuals). Additionally, Neural ODE’s are often computationally expensive, so the limitations of using these networks include the capabilities of computer hardware.

With this in mind, let’s find the end result after training a Neural ODE with 1000 iterations. See Appendix § 10 for code files.

Conclusion

As you can see, at t=10t = 10 hours, the Neural ODE path runs through (10,6)(10, 6), which we predicted with our analytical Bernoulli solution.

Output of neuralode.py

Figure 2. Output of neuralode.py

By treating the Neural ODE as a learned vector field of an ODE, we successfully modeled the Logistic Growth of a bacteria population with limited resources. Both the Neural ODE and the Bernoulli Differential Equation techniques yielded a sigmoid curve that stabilized once carrying capacity was hit.

An Invitation for Further Exploration

Suppose the carrying capacity KK was not constant, but a periodic function that changed with the seasons. Let

K(t)=10+2sin⁡(t).K(t) = 10 + 2\sin(t).

How would the solution to the Bernoulli Equation change, and would Neural ODE’s be a superior method to solving this new equation?

Code Files

Neural ODE code file page 1

Figure A.1. Neural ODE Code File Page 1

Neural ODE code file page 2
# Generate "True" training data
true_model = LogisticGrowth(r=0.5, K=10.0)
# We compute true data using the analytical solution (Bernoulli result)
true_y = true_model.analytical_solution(y0, t)

# Now train with 1000 iterations
func = ODEFunc()
optimizer = optim.Adam(func.parameters(), lr=0.01)
n_iters = 1000

print("Training Neural ODE on Logistic Growth...")

for i in range(n_iters):
    optimizer.zero_grad()

    # Forward Pass: Integrate NN using RK4
    pred_y = rk4_solve(func, y0, t)

    # Compute Loss (MSE)
    loss = torch.mean((pred_y - true_y)**2)

    loss.backward()
    optimizer.step()

    if i % 100 == 0:
        print(f"Iter {i:04d} | Loss {loss.item():.6f}")

print("Training Complete!")

# Visualize the data
t_np = t.detach().numpy().flatten()
true_y_np = true_y.detach().numpy().flatten()
pred_y_np = pred_y.detach().numpy().flatten()

plt.figure(figsize=(10, 6))
plt.title("Neural ODE Learning Logistic Growth (Bernoulli Example)")

# Plot True Data (The Analytical Solution)
plt.plot(t_np, true_y_np, 'g-', label='Analytical Solution (Bernoulli)', linewidth=4, alpha=0.4)

# Plot Neural ODE Prediction
plt.plot(t_np, pred_y_np, 'k--', label='Neural ODE (Learned)', linewidth=2)

# Plot Carrying Capacity line
plt.axhline(y=10.0, color='r', linestyle=':', label='Carrying Capacity K=10')

plt.xlabel("Time")
plt.ylabel("Population")
plt.legend()
plt.grid(True, alpha=0.3)
plt.show()

# Verification: Predict outside training range (Extrapolation)
print("\nVerifying 'Carrying Capacity' behavior...")
last_val = pred_y_np[-1]
print(f"Final Population at t={t_max}: {last_val:.4f} (Should be close to K=10.0)")

Figure A.2. Neural ODE Code File Page 2

Image not extracted

References

  1. [1]Chen, Ricky T. Q., Yulia Rubanova, Jesse Bettencourt, and David Duvenaud. Neural Ordinary Differential Equations, 2019. arXiv: 1806.07366 [cs.LG]. https://arxiv.org/abs/1806.07366.
  2. [2]He, Kaiming, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep Residual Learning for Image Recognition, 2015. arXiv: 1512.03385 [cs.CV]. https://arxiv.org/abs/1512.03385.
  3. [3]Valperga, Ricardo, and Miltos Kofinas. “DS - Dynamical Systems and Neural ODEs,” 2023. https://uvadlc-notebooks.readthedocs.io/en/latest/tutorial_notebooks/DL2/Dynamical_systems/dynamical_systems_neural_odes.html.
  4. [4]Zeltkevic, Michael. “Runge-Kutta Methods,” 1998. https://web.mit.edu/10.001/Web/Course_Notes/Differential_Equations_Notes/node5.html.

Paper details

vlnc:W_4zxbdf4c
v1 · latestHistory (1)

published · Fresh — published within the last 30 days

Usage

views · 10

downloads · 2

A view counts once per browser per day, a download each time the PDF is requested.

CC BY 4.0
  • Mathematics
  • Differential Equations and Numerical Methods

Claude Opus (multiple versions) · View statement →

Chegini, S. (2026). Neural ODE’s - Theory and Application: From Residual Networks to Continuous-Depth Dynamics. Valency, vlnc:W_4zxbdf4c, v1. https://hub.valency.io/works/W_4zxbdf4c

Looking for related papers…
Contents