這份 Python code 的目的是希望「將抽象的物理告知神經網路(PINN)結構與求導公式,轉化為直觀的幾何影像」,讓學生能夠「親眼看見」物理定律是如何約束神經網路的。
這份 Python code 的具體教學目的如下:
傳統神經網路通常用來分類圖片(輸入像素)。這份 Python 展現了 Ch3中第1與第2章的核心定義:PINN 的輸入是物理空間與時間座標(x,t),輸出是一個連續的物理場(溫度 u)。
-輸出的左圖:希望讓大家看見,神經網路在被餵入不同的(x,t)連續網格後,會像繪圖軟體一樣,將原本隨機的函數結構渲染成一張「時空溫度分佈圖」。
很多學生學完鏈鎖律或微積分公式後,依然無法想像它在計算機裡代表什麼。
-輸出的右圖:這份 code 在前向傳播的同時,利用鏈鎖律手動算出了網路對輸入時間的一階導數( $\mathrm{u}{\mathrm{t}}$ )和對空間的二階導數( $\mathrm{u}{\mathrm{xx}}$ ),進而拼湊出熱傳導方程的殘差場$\left(\mathrm{u}{\mathrm{t}}-\alpha \mathrm{u}{\mathrm{xx}}\right) ~ 。$ -當圖形畫出來時,學生會發現即使「左圖的預測溫度」看起來很平滑順眼,但「右圖的物理殘差」卻漏洞百出(有很多深紅或深藍的區域)。這呼應課本第5.3節的警告:「微小的數值誤差可能櫽藏巨大的導數誤差」。
神經網路在還沒開始訓練(隨機初始化)之前,它根本不懂什麼是熱傳導定律。
-視覺化目的:右圖那些五顏六色(遠離0)的區域,正是神經網路違反物理定律的證據。這能讓學生在進入更複雜的優化演算法(第9章)之前,先在腦海中建立一個終極目標:「我們之後做的事情,就是透過調整權重,把右圖所有不符合物理的紅藍色區域,全部『尉平』變成代表 0 的白色!」
This Python code aims to transform abstract Physics-Informed Neural Network(PINN) architectures and derivative formulas into intuitive geometric visualizations,allowing students to "witness firsthand"how physical laws constrain a neural network.
The specific pedagogical objectives of this Python code are as follows:
Traditional neural networks are typically used to classify images(where inputs are pixels).This Python script demonstrates the core definitions from Chapters 1 and 2 of Chapter 3:the inputs to a PINN are physical spatial and temporal coordinates(x,t),and the output is a continuous physical field temperature(u).
-The left output plot:This is designed to show everyone that when the neural network is fed a continuous grid of different(x,t)coordinates,it acts like graphic design software which rendering an initially random functional structure into a vivid"spatiotemporal temperature distribution map."
Many students learn the chain rule or calculus formulas but still cannot visualize what they actually represent inside a computer.
-The right output plot:During the forward pass,this code utilizes the chain rule to manually calculate the network's first derivative with respect to time $\left(\mathrm{u}{\mathrm{t}}\right)$ and second derivative with respect to space $\left(\mathrm{u}{\mathrm{xx}}\right)$ .It then pieces them together to form the residual field of the heat equation $\left(\mathrm{u}{\mathrm{t}}-\alpha \mathrm{u}{\mathrm{xx}}\right)$ . -When the graph is rendered:Students will discover that even if the"predicted temperature on the left"looks smooth and plausible,the"physical residual on the right"is riddled with flaws(showing many deep red or deep blue regions).This echoes the warning in Section 5.3 of the textbook:"Minor numerical errors can harbor massive derivative errors."