第32回:点配置を誤差から変える — residual-adaptive sampling

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

はじめに――「residualが大きい場所へ点を置く」をそのまま信じない

第28回ではuniform・random・adaptive samplingを比較し, 第30・31回ではregularityやlayer geometryを先に知っている場合のgraded / anisotropic samplingを考えました.

今回はexact solutionの構造を事前に知らないとき, computed PINNから得られるresidualを使ってpoint cloudを更新します.

第32回の問い
\[ \boxed{ \text{residual} \longrightarrow \text{local indicator} \longrightarrow \text{mark} \longrightarrow \text{new points} } \tag{1} \]

というloopを,どこまで「誤差適応」と呼んでよいのか?

1.まず「真の誤差」と「residual」を分ける

Poisson problem

\[ -\Delta u=f \quad\text{in }\Omega, \qquad u=0 \quad\text{on }\partial\Omega \tag{2} \]

を考えます. PINN approximationを \(u_\theta\) とし,

\[ \boxed{ e_\theta = u_\theta-u } \tag{3} \]

をtrue errorとします.

strong residualは

\[ \boxed{ r_\theta = -\Delta u_\theta-f. } \tag{4} \]

exact solutionを知らない実問題では \(e_\theta\) は計算できませんが, \(r_\theta\) はautomatic differentiationから計算できます.

2.global residual normとenergy errorには明確な関係がある

conforming \(u_\theta\in H_0^1(\Omega)\) に対してweak residual functionalを

\[ \boxed{ \langle R_\theta,v\rangle = \int_\Omega \nabla u_\theta\cdot\nabla v\,dx - \int_\Omega fv\,dx } \tag{5} \]

とします.

exact solutionのweak equationを引けば

\[ \langle R_\theta,v\rangle = \int_\Omega \nabla e_\theta\cdot\nabla v\,dx. \]

従ってenergy inner productが定めるdual normでは

\[ \boxed{ \|R_\theta\|_{H^{-1},E} = |e_\theta|_{H^1(\Omega)}. } \tag{6} \]

3.strong \(L^2\) residualならglobal upper boundを作れる

\(u_\theta\) がstrong residualを持つだけsmoothなら

\[ -\Delta e_\theta = r_\theta. \]

Poincaré inequalityから

\[ \boxed{ |e_\theta|_{H^1} \le C_P \|r_\theta\|_{L^2}. } \tag{7} \]

つまりcontinuous residual normが小さいことには数学的意味があります.

4.しかしpointwise residualはlocal errorではない

式 (7) はglobal normの関係です.

一方

\[ \boxed{ |r_\theta(x)| \text{ large} \quad\not\Leftrightarrow\quad |\nabla e_\theta(x)| \text{ large}. } \tag{8} \]

Poisson operatorのinverseはnonlocalなので, ある場所のresidualはdomain全体のerrorへ影響します.

5.Green functionでnonlocalityを見る

形式的にGreen function \(G\) を使えば

\[ \boxed{ e_\theta(x) = \int_\Omega G(x,y) r_\theta(y)\,dy. } \tag{9} \]

従って「\(y\) でresidualが大きい」ことと 「\(y\) でsolution errorが大きい」ことは同じではありません.

residual-adaptive samplingは true local errorそのものではなく,computable defectを使うadaptive heuristic です.

6.manufactured solutionではoracle error mapを作れる

exact solution \(u^\ast\) が分かるnumerical experimentでは,

\[ \boxed{ g_{\rm err}(x) = |\nabla(u_\theta-u^\ast)(x)|^2 } \tag{10} \]

を計算できます.

これは実用algorithmには使えませんが,

\[ \boxed{ \text{residual-adaptive points} \quad\text{vs}\quad \text{oracle error-adaptive points} } \tag{11} \]

を比較するaudit benchmarkになります.

7.pointwise top-\(K\)からcellwise indicatorへ進む

第28回ではcandidate pointsの \[ |r_\theta(y_j)| \] が大きい順にpointを追加しました.

しかしsharp peakが一つあるとpointsが一点へcollapseしやすいため, 今回はdomainをcoarse cells

\[ \boxed{ \mathcal P = \{K\} } \tag{12} \]

へ分け,pointではなくregionをmarkします.

8.cellwise sampled residual indicator

cell \(K\) にcandidate points

\[ Y_K = \{y_{K,1},\ldots,y_{K,m_K}\} \]

を置き,

\[ \boxed{ \widehat\eta_K^2 = \frac{|K|}{m_K} \sum_{j=1}^{m_K} |r_\theta(y_{K,j})|^2 } \tag{13} \]

とします.

これは

\[ \int_K|r_\theta|^2dx \]

のsampled approximationであって, まだguaranteed error estimatorではありません.

9.global sampled indicator

cell contributionsを足して

\[ \boxed{ \widehat\eta^2 = \sum_{K\in\mathcal P} \widehat\eta_K^2. } \tag{14} \]

candidate quadratureが十分なら

\[ \widehat\eta \approx \|r_\theta\|_{L^2(\Omega)} \]

を狙えます.

training lossとは独立なcandidate setで作るのが重要です.

10.Dörfler型markingをsamplingへ借りる

\(0<\vartheta\le1\) を選び, marked cells \(\mathcal M\subset\mathcal P\) が

\[ \boxed{ \sum_{K\in\mathcal M} \widehat\eta_K^2 \ge \vartheta \sum_{K\in\mathcal P} \widehat\eta_K^2 } \tag{15} \]

を満たすようにします.

実装では \(\widehat\eta_K^2\) を大きい順にsortし, thresholdを超えるまでcellsを追加します.

11.これはFEMのDörfler markingと同じ定理ではない

adaptive FEMではreliable / efficient estimatorとmesh refinement theoryを組み合わせて convergenceを証明する枠組みがあります.

ここで使う \[ \widehat\eta_K \] はsampled strong residualなので,

\[ \boxed{ \text{Dörfler-like selection rule} \neq \text{AFEM convergence theorem}. } \tag{16} \]

借りているのは「総indicator massの一定割合をmarkする」というselection mechanismです.

12.top-\(K\) point selectionよりregion markingが安全な理由

一つのresidual peakの周囲にcandidate pointsが密なら, pointwise top-\(K\) はほぼ同じ場所を何度も選びます.

cellwise markingなら

\[ \boxed{ \text{peak magnitude} \quad+\quad \text{region measure} } \tag{17} \]

をindicatorに含められます.

それでもcollapseを完全には防げないので,次にcoverage constraintを加えます.

13.coverage safeguardを別に置く

current training setを \(X_k\) とし, cell \(K\) 内のpoint countを

\[ \boxed{ n_K(X_k) = \#(X_k\cap K) } \tag{18} \]

とします.

最低coverageとして

\[ \boxed{ n_K(X_k) \ge n_{\min} \qquad \forall K\in\mathcal P } \tag{19} \]

を要求します.

14.base pointsを消さない設計が最も単純

total training setを

\[ \boxed{ X_k = X_{\rm base} \cup X_{{\rm adapt},k} } \tag{20} \]

とし, \(X_{\rm base}\) はuniform / geometry-aware pointsとして固定します.

adaptive pointsだけを入れ替えれば

\[ \boxed{ \text{global exploration} + \text{local exploitation} } \tag{21} \]

を分離できます.

15.adaptive loopを五段階にする

今回の基本loopは

\[ \boxed{ \text{TRAIN} \to \text{AUDIT} \to \text{MARK} \to \text{RESAMPLE} \to \text{RETRAIN} } \tag{22} \]

です.

ここでAUDITはtraining lossではなく, 独立candidate / reference setで行います.

16.TRAIN――point setを一度freezeして最適化する

adaptive pointsを毎gradient step変えると, optimizerが追うobjective自体が毎回変化します.

そこで一つのadaptation stageでは

\[ \boxed{ X_k \text{ fixed} } \tag{23} \]

として一定stepだけtrainingし, その後にpointsを更新します.

sampling dynamicsとparameter optimisation dynamicsを分離するためです.

17.AUDIT――candidate setはtraining setと分ける

各cellにcandidate points \(Y_K\) を置き, 式 (13) の \[ \widehat\eta_K \] を計算します.

さらに別のreference set \(Z_{\rm ref}\) で

\[ \boxed{ R_{\rm ref} = \left( \int_\Omega |r_\theta|^2dx \right)^{1/2} } \tag{24} \]

を高精度quadratureで近似します.

18.MARK――residual massの一定割合を選ぶ

\(\vartheta=0.5\) なら,

\[ \sum_{K\in\mathcal M} \widehat\eta_K^2 \ge 0.5 \widehat\eta^2 \]

となるcellsをmarkします.

ただし \(\vartheta=0.5\) はillustrative choiceであり, problem-independentな最適値ではありません.

19.RESAMPLE――marked regionへ新しいpointsを入れる

marked cell \(K\) への追加point数を

\[ \boxed{ m_K^{\rm new} \propto \widehat\eta_K^p, \qquad p>0 } \tag{25} \]

とする一つの方法があります.

\(p\) が大きいほどlarge indicatorへ集中します.

過度の集中を避けるため \[ m_K^{\rm new} \le m_{\max} \] のcapを置く設計も有効です.

20.RETRAIN――同じnetworkをwarm startするか,resetするか

adaptive sampling後は二つの比較ができます.

\[ \boxed{ \begin{aligned} \text{warm start} &:\ \theta_{k+1}^{(0)}=\theta_k,\\ \text{restart} &:\ \theta_{k+1}^{(0)}=\theta_{\rm init}. \end{aligned} } \tag{26} \]

warm startは実用的ですが, point placementの効果とoptimisation historyが混ざります.

method comparisonでは両者を区別して記録します.

21.fixed budget adaptationもできる

total number of adaptive pointsを \[ N_{\rm adapt} \] に固定し, indicatorに応じてpointsをredistributeすれば

\[ \boxed{ |X_k| = N_{\rm base} + N_{\rm adapt} } \tag{27} \]

を全stageで保てます.

これなら「精度が上がったのは単にpoint数が増えたから」という混同を避けられます.

22.cumulative adaptationでは計算量も増える

一方

\[ \boxed{ X_{k+1} \supset X_k } \tag{28} \]

としてpointsを追加し続ける方法では, training costも増えます.

したがってaccuracy vs iterationだけでなく

\[ \boxed{ \text{accuracy} \quad\text{vs}\quad \text{number of residual evaluations} } \tag{29} \]

も報告します.

23.density-based updateとしても書ける

cell markingの代わりにcontinuous sampling densityを更新する方法もあります.

例えばuniform base density \(q_0=1/|\Omega|\) として

\[ \boxed{ q_{k+1}(x) = (1-\beta)q_0 + \beta \frac{ (\delta+|r_{\theta_k}(x)|)^p }{ \displaystyle \int_\Omega (\delta+|r_{\theta_k}(y)|)^pdy } } \tag{30} \]

とします.

\[ 0\le\beta<1, \qquad \delta>0 \]

によりcoverage floorを残します.

24.equal weightsならobjectiveもadaptiveに変わる

\(q_{k+1}\) からsampleしてequal weightsを使うと, 期待lossは

\[ \boxed{ \mathbb E_{q_{k+1}} |r_\theta(X)|^2 = \int_\Omega |r_\theta(x)|^2 q_{k+1}(x)\,dx. } \tag{31} \]

従ってpoint distributionだけでなく training norm自体がstageごとに変わります.

25.same continuous residualを保つならimportance correction

targetを

\[ \frac1{|\Omega|} \int_\Omega|r_\theta|^2dx \]

に固定したいなら, sample density \(q_{k+1}\) に対して

\[ \boxed{ w_{k+1}(x) = \frac{ 1/|\Omega| }{ q_{k+1}(x) } } \tag{32} \]

を使います.

\(\beta<1\) なら \[ q_{k+1}(x) \ge \frac{1-\beta}{|\Omega|} \] なのでimportance weightsの爆発を抑えるfloorにもなります.

26.residual-adaptiveとregularity-awareは競合しない

第30回ではcorner exponent, 第31回ではboundary-layer directionを使ってpoint geometryを先に設計しました.

そのbase densityを \(q_{\rm geom}\) とすれば

\[ \boxed{ q_{k+1} = (1-\beta)q_{\rm geom} + \beta q_{\rm res,k} } \tag{33} \]

とできます.

つまり

\[ \boxed{ \text{known geometry / regularity} + \text{computed residual} } \tag{34} \]

を組み合わせる方が自然です.

27.scalar residualだけではanisotropic directionは分からない

\[ |r_\theta(x)| \] はscalarです.

large residual regionは教えても,

\[ \boxed{ \text{どの方向へpointsを詰めるべきか} } \tag{35} \]

までは一般には教えません.

layer direction,diffusion tensor,known operator metric,gradient / Hessian structureなど, 方向情報を別に使う必要があります.

28.candidate pool自体をadaptiveにしすぎない

indicatorを測るcandidate setまでcurrent residualへ集中させると, unseen regionが永久にunseenのままになる可能性があります.

従ってAUDIT用candidate setは少なくとも一部を

\[ \boxed{ \text{fixed global coverage} } \tag{36} \]

として残します.

training pointsとaudit pointsの役割を分けることが重要です.

29.sampling biasを検出する三つのloss

各adaptation stageで

\[ \boxed{ \begin{aligned} L_{\rm train} &= \text{current training-set loss},\\ L_{\rm cand} &= \text{candidate-set residual loss},\\ L_{\rm ref} &= \text{independent high-accuracy reference loss} \end{aligned} } \tag{37} \]

を分けます.

もし

\[ L_{\rm train} \ll L_{\rm ref} \]

ならpoint cloudがtraining objectiveをoverfitしている可能性があります.

30.manufactured solutionではoracle errorも並べる

exact solutionが分かるtestでは

\[ \boxed{ E_{\rm true} = |u_\theta-u^\ast|_{H^1} } \tag{38} \]

も記録します.

さらにcellwise true error

\[ \boxed{ e_K^2 = \int_K |\nabla(u_\theta-u^\ast)|^2dx } \tag{39} \]

を作り,

\[ \boxed{ \{\widehat\eta_K\} \quad\text{と}\quad \{e_K\} } \tag{40} \]

のrankingがどの程度一致するかを見ると, residual markingがtrue local errorの良いproxyか監査できます.

31.indicator rankingを見る

単にglobal correlationだけでなく, top marked cellsのoverlap

\[ \boxed{ \mathcal O_m = \frac{ |\operatorname{Top}_m(\widehat\eta) \cap \operatorname{Top}_m(e)| }{ m } } \tag{41} \]

を使うと, adaptive decisionとして同じregionsを選んでいるか分かります.

これはmanufactured test専用のdiagnosticです.

32.guaranteed estimatorとresidual proxyを区別する

第23回ではequilibrated fluxを使って

\[ \boxed{ |u-u_\theta|_{H^1} \le \eta_{\rm eq} } \tag{42} \]

のようなguaranteed boundを作る考え方を扱いました.

例えばequilibrated \[ \boldsymbol\sigma \in H(\operatorname{div};\Omega) \] があり \[ \nabla\cdot\boldsymbol\sigma=-f \] なら,Poissonでは

\[ \boxed{ \eta_{{\rm eq},K} = \|\boldsymbol\sigma-\nabla u_\theta\|_{L^2(K)} } \tag{43} \]

をlocal contributionとして使えます.

33.certificate-adaptive samplingという次の段階

residual-adaptive samplingはcheapですが, local errorとの対応はheuristicです.

一方certified fluxを構成できるなら

\[ \boxed{ \text{sampled residual} \longrightarrow \text{equilibrated / certified defect} \longrightarrow \text{point placement} } \tag{44} \]

という強いadaptive loopも考えられます.

ただしflux reconstruction自体に追加計算が必要です.

34.この話は次回のmixed neural formulationへつながる

もしnetworkが \[ u_\theta \] だけでなくflux \[ \boldsymbol q_\theta \] も出力すれば,

\[ \boxed{ \boldsymbol q_\theta \approx \nabla u } \tag{45} \]

と

\[ \boxed{ \nabla\cdot\boldsymbol q_\theta \approx -f } \tag{46} \]

を別々に監査できます.

これは次回の mixed formulationとflux conservation へ自然につながります.

35.Dörfler型markingをコード化する

def dorfler_mark(indicator_sq, theta):
    values, idx = torch.sort(
        indicator_sq,
        descending=True
    )

    target = theta * torch.sum(values)
    cumulative = torch.cumsum(values, dim=0)

    m = int(
        torch.searchsorted(
            cumulative,
            target
        ).item()
    ) + 1

    return idx[:m]

ここで indicator_sq は \[ \widehat\eta_K^2 \] の配列です.

36.cellwise residual indicatorをコード化する

def cell_residual_indicator(
    model,
    candidate_points,
    cell_ids,
    cell_measures,
    n_cells
):
    r = pde_residual(
        model,
        candidate_points
    ).detach().flatten()

    eta2 = torch.zeros(
        n_cells,
        dtype=r.dtype,
        device=r.device
    )

    counts = torch.zeros(
        n_cells,
        dtype=r.dtype,
        device=r.device
    )

    eta2.scatter_add_(
        0,
        cell_ids,
        r ** 2
    )

    counts.scatter_add_(
        0,
        cell_ids,
        torch.ones_like(r)
    )

    eta2 = (
        cell_measures
        * eta2
        / torch.clamp(counts, min=1.0)
    )

    return eta2

candidate pointsが存在しないcellを作らないことが前提です.

37.adaptive controllerの骨格

for stage in range(n_stages):

    train_on_fixed_points(
        model,
        train_points,
        n_steps
    )

    eta2 = cell_residual_indicator(
        model,
        audit_points,
        audit_cell_ids,
        cell_measures,
        n_cells
    )

    marked = dorfler_mark(
        eta2,
        theta=0.5
    )

    new_adapt_points = sample_marked_cells(
        marked,
        adaptive_budget
    )

    train_points = merge_with_base_points(
        base_points,
        new_adapt_points
    )

    report_independent_audit(
        model,
        reference_points
    )

実際にはrandom seeds,importance weights,boundary points,optimizer stateも保存します.

38.stopping criterionはtraining lossだけにしない

adaptive loopを止める候補は

\[ \boxed{ R_{\rm ref} \le \text{tolerance} } \tag{47} \]

だけでなく,

  • independent residualが改善しない,
  • 追加pointsに対するerror reductionが飽和した,
  • geometry indicatorが悪化している,
  • certified upper boundが目標を下回った,

などです.

training lossだけを停止判定に使うとsampling overfitを見逃します.

39.AIがresidual-adaptive samplingで間違えやすい点

mistake何が壊れるか
pointwise residualをlocal true errorと呼ぶelliptic inverseのnonlocalityを無視する
top-\(K\) pointsだけを追加する一つのpeakへcollapseしやすい
candidate setもadaptive peakへ集中unseen regionを永続的に見落とす
equal weightsのままdensityを変えるtraining norm自体が変わる
Dörfler-like markingをAFEM theoremと呼ぶreliability / efficiency theoryを飛ばす
adaptiveだけpoint budgetを増やすsampling designとcostを混同する
scalar residualからanisotropic directionまで決める方向情報を作り出してしまう
sampled residual proxyをguaranteed estimatorと呼ぶcertificationとheuristicを混同する

40.residual-adaptive audit prompt

Audit prompt
このPINN residual-adaptive sampling implementationを数学的に監査してください.
(1) true error,weak residual,strong residualを区別しているか,
(2) global residual boundとpointwise local errorを混同していないか,
(3) local indicatorがcandidate quadrature approximationであることを明示しているか,
(4) Dörfler-like markingをAFEMのconvergence theoremと同一視していないか,
(5) base pointsまたはminimum cell coverageを残しているか,
(6) training points,candidate points,reference pointsを分離しているか,
(7) adaptive densityを変えるときequal weightsとimportance weightsを区別しているか,
(8) fixed-budgetとcumulative-budget experimentsを区別しているか,
(9) warm startとrestartでoptimisation historyの影響を区別しているか,
(10) manufactured testではresidual rankingとtrue-error rankingを比較しているか,
(11) anisotropic directionをscalar residualだけから推定していないか,
(12) sampled residual proxyとguaranteed equilibrated estimatorを区別しているか
を順に確認してください.

41.第32回の結論

residual-adaptive samplingは

\[ \boxed{ \text{computed defect} \longrightarrow \text{new observation geometry} } \tag{48} \]

というfeedback mechanismです.

ただし

\[ \boxed{ \text{local residual} \neq \text{local true error} } \tag{49} \]

なので, 単純なpeak chasingではなく

\[ \boxed{ \text{residual marking} + \text{coverage safeguard} + \text{independent audit} } \tag{50} \]

として設計する必要があります.

さらにregularityやlayer directionが分かる場合には

\[ \boxed{ \text{geometry-aware base sampling} + \text{residual correction} } \tag{51} \]

とする方が自然です.

Season 3 第8回の原則
誤差を直接見られないならresidualを使う. ただしresidualを誤差と呼ばず,coverageと独立監査を必ず残す.

次回はresidualをscalar quantityとして見るだけでなくfluxを未知量として持ち, 第33回:保存則をニューラルPDEへ入れる — mixed formulationとflux へ進みます.

参考文献・関連ページ

  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. W. Dörfler, “A convergent adaptive algorithm for Poisson's equation”, SIAM Journal on Numerical Analysis 33 (1996), 1106–1124.
  3. S. C. Brenner and L. R. Scott, The Mathematical Theory of Finite Element Methods, 3rd ed., Springer, 2008.
  4. 第23回:有限要素解の誤差を保証する — equilibrated fluxとhypercircle
  5. 第28回:PINNsでは点配置で答えが変わるか — uniform・random・adaptive sampling
  6. 第30回:角特異性をPINNsは捉えられるか — regularityとgraded sampling
  7. 第31回:boundary layerでは点をどこに置くか — anisotropic sampling

ページの先頭へ