Neural Fractional ODEs and SDEs๏ƒ

HPFRACC provides comprehensive frameworks for learning-based solution of fractional ODEs and SDEs with neural networks. This chapter consolidates both Neural fODE and Neural fSDE frameworks.

For complete API documentation, see Neural ODEs and SDEs API Reference.

Neural Fractional ODEs๏ƒ

The Neural fODE framework provides learning-based solution of fractional differential equations.

Quick Start๏ƒ

import hpfracc.ml.neural_ode as nfode
import torch

# Create a neural ODE model
model = nfode.NeuralODE(
    input_dim=2,
    hidden_dim=32,
    output_dim=1,
    num_layers=3,
    activation="tanh"
)

# Forward pass
x0 = torch.tensor([[1.0, 2.0], [3.0, 4.0]])  # Batch of initial conditions
t = torch.linspace(0, 1, 100)                # Time points
solution = model(x0, t)
print(f"Solution shape: {solution.shape}")  # (batch_size, time_steps, output_dim)

Fractional Neural ODE๏ƒ

Extend to fractional calculus with configurable fractional order:

# Fractional neural ODE
fode_model = nfode.NeuralFODE(
    input_dim=2,
    hidden_dim=32,
    output_dim=1,
    fractional_order=0.5,  # Fractional order ฮฑ
    num_layers=3,
    activation="tanh"
)

solution = fode_model(x0, t)

For detailed documentation, see Neural fODE Framework Guide.

Neural Fractional SDEs๏ƒ

Neural Fractional Stochastic Differential Equations (Neural fSDEs) combine neural networks with fractional calculus and stochastic dynamics.

Introduction๏ƒ

Neural fSDEs extend neural ODEs by incorporating: - Stochasticity: Random noise terms for modeling uncertainty - Memory effects: Fractional derivatives capture long-range temporal dependencies - Learnable dynamics: Neural networks parameterize drift and diffusion functions

Mathematical Foundation๏ƒ

A neural fractional SDE takes the form:

\[D_t^\alpha X(t) = f_\theta(t, X(t)) dt + g_\theta(t, X(t)) dW(t)\]

where: - \(\alpha \in (0, 2)\) is the fractional order - \(D_t^\alpha\) is the Caputo or Riemann-Liouville fractional derivative - \(f_\theta: \mathbb{R}^{d} \to \mathbb{R}^{d}\) is the learnable drift function (neural network) - \(g_\theta: \mathbb{R}^{d} \to \mathbb{R}^{d \times m}\) is the learnable diffusion function - \(W(t)\) is a Wiener process (or more general noise)

Note on Diffusion Functions: Currently supported diffusion types: - Scalar diffusion (additive noise): \(g_\theta(t, X(t)) = \sigma \in \mathbb{R}\) - Vector diffusion (diagonal multiplicative noise): \(g_\theta(t, X(t)) = \sigma(t, X(t)) \in \mathbb{R}^{d}\) - Matrix diffusion (full multiplicative noise): \(g_\theta: \mathbb{R}^{d} \to \mathbb{R}^{d \times d}\) - Not yet implemented

For matrix diffusion, consider using diagonal approximation or standard (non-fractional) SDE solvers first.

Basic Usage๏ƒ

import torch
from hpfracc.ml.neural_fsde import create_neural_fsde

# Create a simple neural fSDE
model = create_neural_fsde(
    input_dim=2,
    output_dim=2,
    hidden_dim=64,
    fractional_order=0.5,
    noise_type="additive"
)

# Forward pass
x0 = torch.randn(32, 2)
t = torch.linspace(0, 1, 50)
trajectory = model(x0, t, method="euler_maruyama", num_steps=50)

print(f"Trajectory shape: {trajectory.shape}")  # (32, 2)

Training Example๏ƒ

import torch.nn as nn

model = create_neural_fsde(input_dim=2, output_dim=2, fractional_order=0.5)
optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)
loss_fn = nn.MSELoss()

# Training loop
for epoch in range(100):
    optimizer.zero_grad()
    pred = model(x0, t)
    loss = loss_fn(pred, target)
    loss.backward()
    optimizer.step()

    if epoch % 10 == 0:
        print(f"Epoch {epoch}, Loss: {loss.item():.4f}")

Fractional Orders in SDEs๏ƒ

The fractional order \(\alpha\) controls memory effects:

  • \(\alpha \to 0\): Nearly instantaneous response (no memory)

  • \(\alpha = 0.5\): Subdiffusion (slower than normal diffusion)

  • \(\alpha = 1\): Standard first-order dynamics

  • \(\alpha = 1.5\): Superdiffusion (faster than normal)

  • \(\alpha \to 2\): Wave-like behavior

Drift and Diffusion Functions๏ƒ

Drift \(f_\theta\): Determines deterministic dynamics

# Custom drift network
drift_net = nn.Sequential(
    nn.Linear(3, 64),  # 2 features + time
    nn.Tanh(),
    nn.Linear(64, 2)
)

model = create_neural_fsde(
    input_dim=2,
    output_dim=2,
    drift_net=drift_net  # Use custom network
)

Diffusion \(g_\theta\): Controls stochastic noise magnitude

Stochastic Noise Modeling๏ƒ

Choose noise type based on problem:

from hpfracc.solvers import BrownianMotion, FractionalBrownianMotion

# Standard Brownian motion (independent increments)
brownian = BrownianMotion(scale=1.0)

# Fractional Brownian motion (correlated increments, Hurst H)
fbm = FractionalBrownianMotion(hurst=0.7, scale=1.0)

Adjoint Training Methods๏ƒ

Efficient gradient computation using adjoint methods:

model = create_neural_fsde(
    input_dim=2,
    output_dim=2,
    fractional_order=0.5,
    use_adjoint=True  # Enable adjoint method
)

See Neural Fractional SDE Guide for comprehensive documentation.

Summary๏ƒ

Neural Fractional ODEs and SDEs provide:

โœ… Learning-based Solving: Neural networks learn dynamics from data โœ… Fractional Memory: Long-range dependencies through fractional derivatives โœ… Stochasticity: Uncertainty modeling with noise terms โœ… Adjoint Training: Efficient gradient computation โœ… Multiple Solvers: Euler-Maruyama, Milstein, and more

Next Steps๏ƒ