第28回:PINNsでは点配置で答えが変わるか — uniform・random・adaptive sampling

ChatGPTで作る有限要素プログラム入門 Season 3 第4回(通算第28回)

はじめに――同じPINNでも「どこで見るか」が違えば別のtraining problemになる

第27回では

\[ r_\theta(x) = -u_\theta''(x)-f(x) \tag{1} \]

をcollocation pointsで観測し,

\[ \mathcal L_N(\theta) = \sum_{i=1}^Nw_i|r_\theta(x_i)|^2 \tag{2} \]

を最小化しました.

今回はnetwork architecture,initial seed,optimizer,training budgetを固定し, collocation pointsだけを変えます.

第28回の問い
\[ \boxed{ \text{same PINN} + \text{same }N + \text{different point geometry} \Longrightarrow \text{different trained solution?} } \tag{3} \]

1.比較するのは四つのsampling strategy

1次元Poisson problem

\[ -u''=\pi^2\sin(\pi x), \qquad 0<x<1, \qquad u(0)=u(1)=0 \tag{4} \]

で,次を比較します.

strategy点配置狙い
uniform等間隔deterministic coverage
random一様乱数Monte Carlo sampling
residual-adaptivelarge residualへ追加exploitation
concentrated control狭い領域へ集中failure baseline

2.uniform samplingはcoverageを最優先する

\(N\) interior pointsを

\[ \boxed{ x_i = \frac{i}{N+1}, \qquad i=1,\ldots,N } \tag{5} \]

と置きます.

最大gapは

\[ \boxed{ h_X = \frac1{N+1}. } \tag{6} \]

1次元ではdomain全体を最も単純に均等coverするbaselineです.

3.random samplingは平均的には一様でもgapを作る

random samplingでは

\[ \boxed{ x_i \stackrel{\mathrm{iid}}{\sim} U(0,1) } \tag{7} \]

とします.

empirical measureはsample数を増やすとLebesgue measureへ近づきますが, 有限 \(N\) では大きなgapと非常に近いpoint pairが同時に現れ得ます.

従って

\[ \boxed{ \text{distribution is uniform} \not\Rightarrow \text{each realised point cloud is geometrically uniform}. } \tag{8} \]

4.random samplingではseedもgeometry parameterである

同じ \(N\) でもseedが違えば

\[ X_N^{(1)}, \quad X_N^{(2)}, \quad X_N^{(3)} \]

は別のgeometryです.

従ってrandom samplingを比較するときは

\[ \boxed{ \text{network seed} \quad\text{と}\quad \text{point seed} } \tag{9} \]

を別々に固定・記録します.

5.最大gapは「見ていない領域」の大きさを測る

sorted point set \[ 0<x_1<\cdots<x_N<1 \] に対して

\[ \boxed{ h_X = \max \{ x_1,\, x_2-x_1,\ldots, x_N-x_{N-1},\, 1-x_N \} } \tag{10} \]

を今回も使います.

\(h_X\) が大きいほど, PDE residualを直接観測していない長いintervalがあります.

6.gapの中にはsampled lossから見えないerrorを埋め込める

collocation pointsを含まないopen interval \[ I=(a,b) \] があるとします.

任意のnonzero \[ \psi\in C_c^\infty(I) \] を取り,

\[ \boxed{ \widetilde u = u^\ast+c\psi } \tag{11} \]

とします. \(\psi\) は全collocation pointsの近傍でzeroなので

\[ \boxed{ r_{\widetilde u}(x_i) = r_{u^\ast}(x_i) = 0. } \tag{12} \]

しかし \[ \widetilde u\ne u^\ast \] です.

つまりgapは単なるvisual defectではなく, finite observationsから完全に見えないperturbationを置ける領域です.

7.uniform samplingの強みは「最悪の穴」を制御できること

uniform pointsでは式 (6) により

\[ h_X=O(N^{-1}) \tag{13} \]

がdeterministically分かります.

一方random samplingではcoverageもrandom variableです.

これはrandom samplingが悪いという意味ではなく,

\[ \boxed{ \text{deterministic coverage guarantee} \quad\text{と}\quad \text{probabilistic coverage} } \tag{14} \]

を区別すべきだという意味です.

8.random resamplingには別の意味がある

random pointsをtraining開始時に一度だけ固定する方法と, epochごとにresampleする方法は別物です.

fixed random cloudでは

\[ \boxed{ \mathcal L_{X_N}(\theta) } \tag{15} \]

という一つのfinite objectiveを最小化します.

resamplingでは各stepでmeasureが変わり, 期待値としてcontinuous lossを狙うstochastic optimisationになります.

9.adaptive samplingではpoint setがsolutionに依存する

residual-adaptive samplingではcurrent model \[ u_{\theta_k} \] からresidual \[ r_{\theta_k} \] を計算し,次のpoint setを決めます.

\[ \boxed{ X_{k+1} = \mathcal A(r_{\theta_k},X_k). } \tag{16} \]

従って

\[ \boxed{ \theta_k \longrightarrow r_{\theta_k} \longrightarrow X_{k+1} \longrightarrow \theta_{k+1} } \tag{17} \]

というcoupled dynamicsになります.

10.最も単純なresidual-adaptive rule

dense candidate pool \[ Y_M=\{y_1,\ldots,y_M\} \] でresidualを評価し,

\[ \boxed{ s_j = |r_{\theta_k}(y_j)| } \tag{18} \]

の大きいpointsを次のcollocation setへ追加します.

例えばtop-\(K\) ruleは

\[ \boxed{ X_{k+1} = X_k \cup \operatorname{TopK}_{y_j\in Y_M} |r_{\theta_k}(y_j)|. } \tag{19} \]

11.top-\(K\)だけだと一点集中に近づくことがある

residualに一つ鋭いpeakがあると, top-\(K\) pointsはその近傍へ集中します.

すると

\[ \boxed{ \text{residual exploitation} \uparrow \qquad \text{global coverage} \downarrow } \tag{20} \]

となり得ます.

第26回の一点集中と同じfailure mechanismが, adaptive method自身によって作られる可能性があります.

12.adaptive samplingにはexplorationを残す

一つの方法はsampling densityを

\[ \boxed{ d\nu_k = (1-\beta)\,dx + \beta\,d\rho_k, \qquad 0\le\beta<1 } \tag{21} \]

とすることです.

ここで \(\rho_k\) はresidual-based densityです. 一様成分 \[ (1-\beta)dx \] を残すことでdomain coverageを完全には捨てません.

13.residual-based densityの一例

例えば

\[ \boxed{ \rho_k(x) = \frac{ (\varepsilon+|r_{\theta_k}(x)|)^\gamma }{ \displaystyle \int_0^1 (\varepsilon+|r_{\theta_k}(s)|)^\gamma\,ds } } \tag{22} \]

とします.

\(\gamma\) が大きいほどpeakへ集中し, \(\varepsilon>0\) はzero-residual領域にもsampling probabilityを残します.

14.adaptive samplingはerror estimatorではない

large \[ |r_{\theta_k}(x)| \] は「その点でstrong residualが大きい」ことを意味します. しかし

\[ \boxed{ |r_{\theta_k}(x)| \text{ large} \quad\not\Leftrightarrow\quad |u_{\theta_k}(x)-u(x)| \text{ large}. } \tag{23} \]

特にPDE operator,regularity,stabilityによって residualからsolution errorへのmapは変わります.

従ってresidual-adaptive samplingを guaranteed a posteriori error estimatorと呼んではいけません.

15.adaptive candidate poolにもsampling errorがある

adaptive algorithmがresidual peakを探すために使う candidate pool \(Y_M\) も有限です.

もしtrue residual peakがcandidate pointsの間に隠れていれば,

\[ \boxed{ \max_{y_j\in Y_M}|r(y_j)| \ll \|r\|_{L^\infty} } \tag{24} \]

となり得ます.

adaptive samplingは「sampling problemを消す」のではなく, samplingを二段階にする方法です.

16.比較protocolを固定する

sampling methodだけを比較するため,

\[ \boxed{ \begin{aligned} &\text{same network},\\ &\text{same initial parameters},\\ &\text{same dtype},\\ &\text{same optimiser},\\ &\text{same total gradient steps},\\ &\text{same total collocation budget} \end{aligned} } \tag{25} \]

を基本とします.

adaptive methodだけpoint数を増やし続けるなら, 計算量の差も同時に報告します.

17.static budgetとcumulative budgetを区別する

adaptive samplingには二つの設計があります.

固定budget:

\[ \boxed{ |X_k|=N \quad \text{for all }k } \tag{26} \]

でpointsをreplaceする方法.

cumulative budget:

\[ \boxed{ X_{k+1}\supset X_k, \qquad |X_k|\uparrow } \tag{27} \]

でpointsを追加し続ける方法です.

この二つを同じ「adaptive sampling」として精度だけ比較すると公平ではありません.

18.uniform point generator

def uniform_points(N, device):
    x = torch.linspace(
        0.0, 1.0, N + 2,
        device=device
    )[1:-1]

    return x[:, None]

19.random point generator

def random_points(N, device, generator=None):
    x = torch.rand(
        (N, 1),
        device=device,
        generator=generator
    )

    x, _ = torch.sort(
        x,
        dim=0
    )

    return x

point seedはnetwork initialization seedとは別に保存します.

20.candidate-pool adaptive sampling

def adaptive_candidates(M, device):
    y = torch.linspace(
        0.0, 1.0, M + 2,
        device=device
    )[1:-1]

    return y[:, None]


def topk_residual_points(model, y, K):
    r = pde_residual(
        model,
        y
    ).detach().abs().flatten()

    idx = torch.topk(
        r,
        k=K
    ).indices

    x_new = y[idx]

    x_new, _ = torch.sort(
        x_new,
        dim=0
    )

    return x_new

実装上,pde_residual はautomatic differentiationを使うので, 候補点生成とresidual評価のgrad contextは分けて扱います.

21.coverage-preserving adaptive rule

例えばtotal budget \(N\) のうち

\[ \boxed{ N_{\rm base} + N_{\rm adapt} = N } \tag{28} \]

として,

  • \(N_{\rm base}\):uniform baseline points,
  • \(N_{\rm adapt}\):large-residual points,

に分けます.

これならadaptive concentrationが起きても baseline coverageを完全には失いません.

22.sampling geometryも各epochで監査する

point setが更新されるたび

\[ \boxed{ h_X, \qquad q_X, \qquad \rho_X=\frac{h_X}{q_X} } \tag{29} \]

を記録します.

adaptive residualが下がっているのに

\[ h_X\uparrow \]

なら,training setが局所化しすぎている可能性があります.

23.評価用pointsはtrainingから完全に独立させる

全sampling strategyを同じreference quadratureで評価します.

\[ \boxed{ \begin{aligned} R_{\rm ref} &= \|r_\theta\|_{L^2},\\ E_{L^2} &= \|u_\theta-u^\ast\|_{L^2},\\ E_{H^1} &= |u_\theta-u^\ast|_{H^1}. \end{aligned} } \tag{30} \]

training loss \[ \mathcal L_N \] はperformance metricではなく, optimizerが見ていたobjectiveとして別列に残します.

24.何をtableに記録するか

各runで少なくとも

categoryrecord
samplingmethod, \(N\), seed, \(h_X\), \(q_X\)
trainingfinal \(\mathcal L_N\), steps, optimiser
reference residual\(R_{\rm ref}\)
solution error\(E_{L^2},E_{H^1}\)
adaptivenumber of updates, base/adaptive split

25.uniformがadaptiveより良い場合もある

solutionとresidualがsmoothで, uniform pointsが既に十分denseなら, adaptive samplingが大きな改善を与えないことがあります.

それどころかadaptive concentrationによってcoverageが悪化すれば,

\[ \boxed{ \text{adaptive} \not\Rightarrow \text{more accurate}. } \tag{31} \]

adaptive methodはproblem structureを利用する追加mechanismであって, automatic superiorityではありません.

26.randomがuniformより良い場合も悪い場合もある

random pointsはfixed gridのaliasing patternを避けやすい一方, finite sampleではunlucky gapを作れます.

従って一つのrandom seedだけから

\[ \boxed{ \text{random is better} \quad\text{or}\quad \text{uniform is better} } \tag{32} \]

と結論してはいけません.

27.一点集中をcontrol experimentとして残す

第26回と同様に

\[ \boxed{ x_i = x_0+\varepsilon\xi_i, \qquad \varepsilon\ll1 } \tag{33} \]

というconcentrated point setもcontrolとして残します.

PINNsではこの場合

\[ \mathcal L_N \] がほぼ \(x_0\) 近傍のresidualしか見なくなります.

これにより

\[ \boxed{ \text{small training loss} + \text{large reference residual} } \tag{34} \]

というfailureを意図的に作れます.

28.adaptive samplingも一点集中controlと同じgeometryへ近づき得る

adaptive methodで

\[ q_X\to0, \qquad h_X\not\to0 \]

となれば, 大量のpointsが同じresidual peakへ集まり, 他のdomainを見なくなっています.

したがって

\[ \boxed{ \text{adaptive residual reduction} + \text{geometry audit} } \tag{35} \]

をセットで行います.

29.FEMのadaptive refinementとの共通点と違い

FEM adaptive mesh refinementでは

\[ \boxed{ \text{solve} \to \text{estimate} \to \text{mark} \to \text{refine} } \tag{36} \]

というloopを使います.

PINNsのadaptive samplingも

\[ \boxed{ \text{train} \to \text{sample residual} \to \text{select points} \to \text{retrain} } \tag{37} \]

という似た形です.

しかしFEMのrefinementではmesh connectivityとtrial space自体が変わるのに対し, PINN samplingでは主にtraining measureが変わります. 両者を同一視してはいけません.

30.将来はanisotropic adaptive samplingへ進む

2次元ではresidualの大きさだけでなくdirectionalityがあります.

例えばlayerが \[ x=x_0 \] に沿って細いなら,

\[ \boxed{ h_\perp \ll h_\parallel } \tag{38} \]

というanisotropic point placementが自然です.

第31回では 点を増やす場所だけでなく,どの方向に細かくするか を扱います.

31.AIがsampling comparisonで間違えやすい点

mistake何が壊れるか
random seedを記録しないgeometryを再現できない
adaptiveだけpoint budgetを増やすsampling strategyと計算量を混同する
training lossだけで比較各methodが別measureを見ている可能性を無視する
large residualをlarge true errorと同一視stability mapを無視する
top-\(K\) adaptiveを無条件に使うpointsが一つのpeakへcollapseする
candidate poolをtruthとみなすcandidate間のpeakを見落とす
FEM adaptivityとPINN samplingを同じと説明trial-space refinementとmeasure updateを混同する

32.sampling-strategy audit prompt

Audit prompt
このPINN sampling comparisonを数学的に監査してください.
(1) uniform・random・adaptiveでnetworkとoptimiser条件を揃えているか,
(2) point countだけでなくpoint coordinatesとweightsを保存しているか,
(3) random samplingではpoint seedとnetwork seedを分離しているか,
(4) \(h_X\) と \(q_X\) を使ってcoverage / clusteringを記録しているか,
(5) training lossとindependent reference residualを区別しているか,
(6) adaptive methodのcandidate pool自体のresolutionを記録しているか,
(7) residual-adaptive samplingをguaranteed error estimatorと呼んでいないか,
(8) top-\(K\) selectionによるpoint concentrationを監査しているか,
(9) exploration用のuniform baselineを残すか,その理由を説明しているか,
(10) adaptive methodのstatic / cumulative budgetを区別しているか,
(11) random methodは複数seedでvariationを報告しているか,
(12) 最終比較を同じreference quadratureで行っているか
を順に確認してください.

33.第28回の結論

PINNsでは

\[ \boxed{ \mathcal L_N(\theta) = \int |r_\theta|^2\,d\mu_N } \tag{39} \]

なので, sampling strategyは単なるdata-loaderの選択ではありません.

uniform,random,adaptiveはそれぞれ

\[ \boxed{ \begin{aligned} \text{uniform}&:\ \text{coverageを直接制御},\\ \text{random}&:\ \text{sampling measureを確率的に近似},\\ \text{adaptive}&:\ \text{current residualへmeasureを集中} \end{aligned} } \tag{40} \]

という異なる設計です.

そしてadaptive samplingでも, coverageを失えば

\[ \boxed{ \text{many points} \not\Rightarrow \text{much information}. } \tag{41} \]

第26回の一点集中は例外的なtoy problemではなく, adaptive concentrationの極限としても現れ得ます.

Season 3 第4回の原則
PINNsで点を適応的に増やすなら,residualだけでなくcoverageも同時に適応させる.

次回はboundary samplingを独立に取り出し, 第29回:境界点は何点必要か — interior lossとboundary loss へ進みます.

参考文献・関連ページ

  1. M. Raissi, P. Perdikaris and G. E. Karniadakis, “Physics-informed neural networks: A deep learning framework for solving forward and inverse problems involving nonlinear partial differential equations”, Journal of Computational Physics 378 (2019), 686–707.
  2. 第26回:Deep Ritzでは点をどこに置くか — quadratureとsampling geometry
  3. 第27回:PINNsを作る — strong residualを点で最小化する
  4. 第23回:有限要素解の誤差を保証する — equilibrated fluxとhypercircle
  5. 関連する先行ノート:残差点の配置を変えると何が起きるか
  6. 関連する先行ノート:どの幾何的量が誤差を支配するか

ページの先頭へ