2025.4.6机器学习笔记:文献阅读
2025.4.6周报
- 题目信息
- 摘要
- Abstract
- 创新点
- 网络架构
- 实验
- 结论
- 不足以及展望
题目信息
- 题目: Physics-Informed Neural Network Surrogate Models for River Stage Prediction
- 期刊: Computing in Science & Engineering
- 作者: Maximilian Zoch, Edward Holmberg, Pujan Pokhrel, Ken Pathak, Steven Sloan, Kendall Niles, Jay Ratcliff, Maik Flanagin, Elias Ioup, Christian Guetl, Mahdi Abdelguerfi
- 发表时间: 2025
- 文章链接:https://arxiv.org/pdf/2503.16850
摘要
河流水位动态对农业、工业和城市基础设施至关重要,准确预测有助于灌溉、供水、排水规划和洪水风险评估等领域的决策制定,尤其在极端天气事件中,实时预测对洪水预报和应急响应至关重要。但传统水动力模型,如HEC - RAS虽能通过求解圣维南方程提供高精度的河流水位模拟,但计算成本高,需要大量参数校准和精细的时空数据,导致实时预报在快速演变的洪水场景中效果不尽人意。而纯数据驱动的深度学习模型,如DNN、RNN、LSTM,缺乏物理可解释性,在应用于动态、未知的河流条件时泛化能力较差。物理信息神经网络(PINN)将物理方程嵌入训练过程,能在数据稀缺环境中生成符合物理规律的解,在计算流体动力学等领域已证明有效,但在河流水位预测中的应用有限。基于以上背景,本文旨在开发基于PINN的模型,以降低计算成本并保持预测准确性,为更广泛的水动力建模框架研究奠定基础。
Abstract
This work investigates the feasibility of using Physics-Informed Neural Networks (PINNs) as surrogate models for river stage prediction, aiming to reduce computational cost while maintaining predictive accuracy. Our primary contribution demonstrates that PINNs can successfully approximate HEC-RAS numerical solutions when trained on a single river, achieving strong predictive accuracy with generally low relative errors, though some river segments exhibit higher deviations.By integrating the governing Saint-Venant equations into the learning process,the proposed PINN-based surrogate model enforces physical consistency and significantly improves computa-tional efficiency compared to HEC-RAS. We evaluate the model’s performance in terms of accuracy and computational speed,demonstrating that it closely approximates HEC-RAS predictions while enabling real-time inference.These results highlight the potential of PINNs as effective surrogate models for single-river hydrodynamics, offering a promising alternative for computationally efficient river stage forecasting. Future work will explore techniques to enhance PINN training stability and robustness across a more generalized multi-river model.
创新点
本论文首次将PINNs广泛应用于河流水位预测,此前PINNs多用于理想化流体模拟。此外,其结合Fourier特征编码与物理信息正则化,提升模型捕捉水流细微变化能力和物理规律。PINN替代模型在保持精度的同时显著降低计算成本,可实现实时预测,对洪水预报和应急响应具有重要意义。
网络架构
在介绍论文架构前,先来解释一下论文的前置知识
论文的物理约束为SVE(圣维南方程)
此外,作者还使用了傅里叶编码的技术。
在神经网络中,尤其是在处理物理系统的建模时,普通的神经网络存在一种“谱偏置”(spectral bias)
即倾向于学习低频信号,而对高频信号(如河流水位中的快速变化或细微波动)的捕捉能力较弱。
这种偏置会导致模型无法很好地拟合复杂、快速变化的物理现象。
神经网络容易忽略水位的小变化,只预测一个大趋势。为了解决这个问题,论文用了傅里叶特征编来提高模型学习空间和时间数据中小变化的能力。
论文的模型构造如下图所示:
模型将时空输入(x, t)映射到预测河段h(x, t)和流速u(x, t)。
输入层:编码河英里x和时间t使用傅立叶特征。
隐藏层:总共有6个全连接前馈神经网络,每层有512个隐藏层。
损失函数:损失结合了监督学习和物理约束两部分分别为:
L
=
L
HEC-RAS
+
λ
L
physics
\mathcal{L}=\mathcal{L}_{\text {HEC-RAS }}+\lambda \mathcal{L}_{\text {physics }}
L=LHEC-RAS +λLphysics
其中:
L
HEC-RAS
\mathcal{L}_{\text {HEC-RAS }}
LHEC-RAS 是衡量神经网络预测的水位 h(x,t) 和流速 u(x,t) 与 HEC-RAS 模拟结果的偏差。
L
HEC-RAS
=
1
N
∑
i
=
1
N
(
y
^
i
−
y
i
)
2
\mathcal{L}_{\text {HEC-RAS }}=\frac{1}{N} \sum_{i=1}^{N}\left(\hat{y}_{i}-y_{i}\right)^{2}
LHEC-RAS =N1∑i=1N(y^i−yi)2,
y
i
^
\hat{y_i}
yi^为预测值,
y
i
y_i
yi是 HEC-RAS 的真实值。
L
p
h
y
s
i
c
s
\mathcal{L}_{\mathrm{physics}}
Lphysics为物理约束部分,表达式为:
L
p
h
y
s
i
c
s
=
∥
∂
h
∂
t
+
∂
(
h
u
)
∂
x
∥
2
+
∥
∂
u
∂
t
+
u
∂
u
∂
x
+
g
∂
h
∂
x
∥
2
\mathcal{L}_{\mathrm{physics}}=\left\|\frac{\partial h}{\partial t}+\frac{\partial(h u)}{\partial x}\right\|^{2}+\left\|\frac{\partial u}{\partial t}+u \frac{\partial u}{\partial x}+g \frac{\partial h}{\partial x}\right\|^{2}
Lphysics=
∂t∂h+∂x∂(hu)
2+
∂t∂u+u∂x∂u+g∂x∂h
2
各参数的意义可以参考上图SVE中的参数解释,这里就不在赘述了。
输出层:预测h(水深)和u(流速)。
实验
本文围绕基于PINN的单河道模型开展研究,通过实验和数据分析,验证了该模型在河流水位预测中的有效性和高效性。
以下是对文章实验结果和数据分析结果的概述:
- 基准测试结果
在一维非恒定流分析中,HEC - RAS模拟耗时8317秒,而基于PINN的单河模型仅需82.9秒,PINN模型实现了100倍的提升。这是因为PINN模型可以使用GPU加速,可通过更强大或更多的GPU实现扩展。而HEC - RAS受CPU性能限制,缺乏GPU性能加持,在处理大型或复杂模拟时可扩展性有限。
这些结果表明,基于PINN的替代模型是传统数值求解器的可扩展且计算高效的替代方案,适用于实时河流水位预测。 - 单河模型评估结果
通过计算平均相对绝对误差(MRAE)评估模型准确性,其中 M R A E = 1 N ∑ i = 1 N ( ∣ y ^ i − y i ∣ ) 1 N ∑ i = 1 N y i M R A E=\frac{\frac{1}{N} \sum_{i=1}^{N}\left(\left|\hat{y}_{i}-y_{i}\right|\right)}{\frac{1}{N} \sum_{i=1}^{N} y_{i}} MRAE=N1∑i=1NyiN1∑i=1N(∣y^i−yi∣)。 y ^ \hat{y} y^为预测值,y为真实值。结果显示,在所有河流测站中,模型的MRAE较低,表明具有较强的预测准确性。多数测站误差率较低,但部分河流偏差略大。
消融实验结果如下图所示:
消融实验(Ablation Study) 是科学研究,尤其在机器学习、计算机视觉和深度学习领域中常用的一种分析方法
其旨在通过系统性地移除或修改模型中的某些组件,如网络层、模块、特征或超参数,来评估这些组件对模型整体性能的影响。
其核心目的是验证模型设计的有效性,揭示不同部分对结果的贡献程度,并帮助研究者理解模型的鲁棒性和可解释性。
在无傅里叶特征时,模型难以捕捉高频变化,对河流水位的近似分辨率较低。
启用傅里叶特征后,模型能更好地捕捉小尺度波动,但可能引入噪声。物理信息嵌入显著提高了全局一致性,确保模型符合已知的水动力原理。
代码如下:
import torch
import torch.nn as nn
import numpy as np
import matplotlib.pyplot as plt
# 设置随机种子,确保可重复性
torch.manual_seed(42)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# 1. 生成合成数据(模拟 HEC-RAS 输出)
def generate_synthetic_data(n_points=1000):
x = torch.linspace(0, 100, n_points).reshape(-1, 1) # 河道位置:0-100 英里
t = torch.linspace(0, 24, n_points).reshape(-1, 1) # 时间:0-24 小时
xt = torch.cat((x, t), dim=1).to(device) # 输入 [x, t]
# 假设水位和流速
h_true = 3 + 0.5 * torch.sin(0.1 * x) + 0.2 * torch.cos(0.5 * t) # 水位
u_true = 1 + 0.1 * torch.sin(0.2 * x) + 0.05 * torch.cos(0.3 * t) # 流速
return xt, h_true, u_true
# 2. 傅里叶特征编码
class FourierFeatures(nn.Module):
def __init__(self, input_dim, mapping_size=10, sigma=1.0):
"""初始化傅里叶特征编码层"""
super(FourierFeatures, self).__init__()
# B 是傅里叶基频矩阵,随机生成,形状为 [mapping_size, input_dim]
self.B = torch.randn(mapping_size, input_dim) * sigma # sigma 控制频率范围
self.B = self.B.to(device)
self.mapping_size = mapping_size
def forward(self, x):
"""将输入 x 映射到傅里叶特征空间"""
# x 的形状: [batch_size, input_dim]
# 计算 2πBx,形状: [batch_size, mapping_size]
projection = 2 * np.pi * torch.matmul(x, self.B.T)
# 返回 [cos(2πBx), sin(2πBx)],形状: [batch_size, 2 * mapping_size]
return torch.cat([torch.cos(projection), torch.sin(projection)], dim=-1)
# 3. PINN 模型
class PINN(nn.Module):
def __init__(self, input_dim=2, hidden_dim=512, layers=6, mapping_size=10):
super(PINN, self).__init__()
# 傅里叶特征编码层
self.fourier = FourierFeatures(input_dim, mapping_size, sigma=1.0)
encoded_dim = 2 * mapping_size # 输出维度是 2 * mapping_size
# 神经网络部分
layers_list = [nn.Linear(encoded_dim, hidden_dim), nn.ReLU()]
for _ in range(layers - 1):
# 残差连接:输入和输出维度相同
layers_list.append(nn.Linear(hidden_dim, hidden_dim))
layers_list.append(nn.ReLU())
layers_list.append(nn.Linear(hidden_dim, 2)) # 输出 h 和 u
self.net = nn.Sequential(*layers_list).to(device)
def forward(self, x):
x_encoded = self.fourier(x) # 傅里叶特征编码
out = self.net(x_encoded) # 神经网络预测
h = out[:, 0:1] # 水位
u = out[:, 1:2] # 流速
return h, u
# 4. 损失函数
def compute_loss(model, xt, h_true, u_true, lambda_physics=1.0):
xt.requires_grad_(True) # 启用梯度计算,用于物理损失
h_pred, u_pred = model(xt)
# 数据损失:预测值与真值的均方误差
loss_data = torch.mean((h_pred - h_true) ** 2) + torch.mean((u_pred - u_true) ** 2)
# 物理损失:Saint-Venant 方程残差
# 计算偏导数
h_t = torch.autograd.grad(h_pred, xt, grad_outputs=torch.ones_like(h_pred), create_graph=True)[0][:, 1:2] # ∂h/∂t
h_x = torch.autograd.grad(h_pred, xt, grad_outputs=torch.ones_like(h_pred), create_graph=True)[0][:, 0:1] # ∂h/∂x
u_t = torch.autograd.grad(u_pred, xt, grad_outputs=torch.ones_like(u_pred), create_graph=True)[0][:, 1:2] # ∂u/∂t
u_x = torch.autograd.grad(u_pred, xt, grad_outputs=torch.ones_like(u_pred), create_graph=True)[0][:, 0:1] # ∂u/∂x
# hu 的偏导数
hu = h_pred * u_pred
hu_x = torch.autograd.grad(hu, xt, grad_outputs=torch.ones_like(hu), create_graph=True)[0][:, 0:1] # ∂(hu)/∂x
# Saint-Venant 方程残差
g = 9.81 # 重力加速度
continuity = h_t + hu_x # 连续性方程:∂h/∂t + ∂(hu)/∂x = 0
momentum = u_t + u_pred * u_x + g * h_x # 动量方程
# 物理损失:残差的平方和
loss_physics = torch.mean(continuity ** 2) + torch.mean(momentum ** 2)
# 总损失
total_loss = loss_data + lambda_physics * loss_physics
return total_loss, loss_data, loss_physics
# 5. 训练函数
def train(model, xt, h_true, u_true, epochs=10000, lr=1e-3):
"""训练 PINN 模型"""
optimizer = torch.optim.Adam(model.parameters(), lr=lr)
scheduler = torch.optim.lr_scheduler.ExponentialLR(optimizer, gamma=0.99) # 学习率衰减
for epoch in range(epochs):
optimizer.zero_grad()
total_loss, loss_data, loss_physics = compute_loss(model, xt, h_true, u_true)
total_loss.backward()
optimizer.step()
if epoch % 1000 == 0:
print(f"Epoch {epoch}: Total Loss = {total_loss.item():.4f}, "
f"Data Loss = {loss_data.item():.4f}, Physics Loss = {loss_physics.item():.4f}")
if epoch % 5000 == 0:
scheduler.step()
# 6. 主程序
if __name__ == "__main__":
# 生成数据
xt, h_true, u_true = generate_synthetic_data(n_points=1000)
h_true, u_true = h_true.to(device), u_true.to(device)
# 初始化模型
model = PINN(input_dim=2, hidden_dim=512, layers=6, mapping_size=10)
# 训练
train(model, xt, h_true, u_true, epochs=10000)
# 测试预测
with torch.no_grad():
h_pred, u_pred = model(xt)
# 可视化结果
plt.figure(figsize=(12, 5))
plt.subplot(1, 2, 1)
plt.plot(xt[:, 0].cpu(), h_true.cpu(), label="True h")
plt.plot(xt[:, 0].cpu(), h_pred.cpu(), label="Predicted h", linestyle="--")
plt.xlabel("x (miles)")
plt.ylabel("Water Level (m)")
plt.legend()
plt.subplot(1, 2, 2)
plt.plot(xt[:, 0].cpu(), u_true.cpu(), label="True u")
plt.plot(xt[:, 0].cpu(), u_pred.cpu(), label="Predicted u", linestyle="--")
plt.xlabel("x (miles)")
plt.ylabel("Velocity (m/s)")
plt.legend()
plt.tight_layout()
plt.show()
结论
本文研究表明,PINN可作为河流水位预测的高效替代模型,相比HEC - RAS,在保持精度的同时大幅提升计算速度。多数河段预测的平均相对误差较低,Fourier特征编码能增强模型分辨率,但需物理信息正则化防止过拟合。
不足以及展望
对于这篇论文的不足,作者提到当前工作仅针对单河流模型,扩展到多河流系统时需进一步研究,未实现多河流通用。其主要聚焦一维非稳态流分析,对2D/3D复杂水流模拟能力待提升。
作者希望研究更多的编码和集成模型策略,将PINN框架扩展到多河流系统,实现通用化;还可以将模型扩展到2D/3D水动力模拟,以适应复杂河流和海岸系统;优化物理信息约束和数据驱动损失函数的权重,提高模型稳定性。