# Meshfree Variational-Physics-Informed Neural Networks (MF-VPINN): An Adaptive Training Strategy
## 2 Problem Formulation
### Loss Function  
In this section, we derive the loss function used to train the neural network. It has to be computable, and its minimizer has to be an approximate solution of Problem (1). We highlight that, when a standard PINN is used, the loss function can be seen as a discrete cost penalizing the residual of (1) directly. In this context, instead, the loss function penalizes the variational residuals of (4) as in standard VPINNs. This is the key difference that differentiates the VPINNs (and its extension proposed in this manuscript) from the other generalizations of the original PINN introduced in Section 1.  
Let us consider a quadrature rule of order \(q\geq 2\) on each triangle \(T_{j}\in\hat{\mathcal{T}},j=1,\ldots,N_{\hat{p}}\), uniquely identified by a set of nodes and weights \(\{(\tilde{\xi}_{\ell}^{j},\tilde{\omega}_{\ell}^{j}):\ell\in I^{T_{j}}\}\). The nodes and weights of a composite quadrature formula of order \(q\) on \(\hat{P}\) can be obtained as  
\[\{(\tilde{\xi}_{\ell},\tilde{\omega}_{\ell}):\ell\in I^{\hat{P}}\}=\bigcup_{j= 1}^{N_{\hat{p}}}\{(\tilde{\xi}_{\ell}^{j},\tilde{\omega}_{\ell}^{j}):\ell\in I ^{T_{j}}\}.\]  
Then, the corresponding quadrature rule of order \(q\) of an arbitrary patch \(P_{i}\) is defined as  
\[\bigg{\{}(\tilde{\xi}_{\ell}^{i},\omega_{\ell}^{i}):\ell\in I^{\hat{P}}| \xi_{\ell}^{i}=M_{i}(\tilde{\xi}_{\ell}),\omega_{\ell}^{i}=\tilde{\omega}_{ \ell}\frac{\text{area}(P_{i})}{\text{area}(\tilde{P})}\bigg{\}}. \tag{9}\]  
Using the quadrature rule in (9), it is possible to define an approximate restriction on each patch of the forms \(a\) and \(F\) as follows:  
\[a_{h}^{i}(w,v)=\sum_{\ell\in I^{\hat{P}}}[\mu\
abla w\cdot\
abla v+\mathbf{\beta} \cdot\
abla w\,v+\sigma wv](\tilde{\xi}_{\ell}^{i})\,\omega_{\ell}^{i}\approx a _{P_{i}}(w,v)\,, \tag{10}\]  
\[F_{h}^{i}(v)=\sum_{\ell\in I^{\hat{P}}}[fv](\tilde{\xi}_{\ell}^{i})\,\omega_{ \ell}^{i}\approx F_{P_{i}}(v)\,, \tag{11}\]  
where \(a_{P_{i}}(w,v)\) and \(F_{P_{i}}(v)\) are defined as in (2) and (3) but restricting the supports of the integrals to \(P_{i}\). We remark that, since it is not possible to compute integrals involving a neural network exactly, we can only use the forms \(a_{h}^{i}\) and \(F_{h}^{i}\) in the loss function. Exploiting the linearity of \(a(w,v)\) and \(F(v)\) with respect to \(v\) to consider only the basis \(\{\varphi_{i}\}_{\tilde{i}=1}^{n_{\text{patches}}}\) of \(V_{h}\) as set of test functions, we approximate Problem (8) as follows: Find \(u^{\mathcal{N}\mathcal{N}}\in\mathcal{V}^{\mathcal{N}\mathcal{N}}\) such that  
\[a_{h}^{i}(u^{\mathcal{N}\mathcal{N}},\varphi_{i})=F_{h}^{i}(\varphi_{i})\qquad \forall i=1,\ldots,n_{\text{patches}}\,. \tag{12}\]  
Then, in order to cast Problem (12) into an optimization problem, we define the residuals  
\[r_{h,i}(w)=F_{h}^{i}(\varphi_{i})-a_{h}^{i}(w,\varphi_{i})\,,\qquad i=1,\ldots,n_{\text{patches}} \tag{13}\]  
and the loss function  
\[R_{h}^{2}(w;\mathcal{P})=\frac{1}{n_{\text{patches}}}\sum_{i=1}^{n_{\text{ patches}}}\gamma_{i}r_{h,i}^{2}(w)\,, \tag{14}\]  
where \(\gamma_{i}\) are suitable positive scaling coefficients. In this work, we use \(\gamma_{i}=\text{area}(P_{i})^{-1}\) to give the same importance to each patch. Note that this is equivalent to normalizing the quadrature rules involved in (10) and (11); this way, each residual \(r_{h,i}\) can be regarded as a linear combination of the MF-VPINN value and derivatives independent of the size of the support of the patch \(P_{i}\). We also highlight that the loss function depends on the choice of \(\mathcal{M}\) since all the used test functions are generated starting from the corresponding mappings \(M_{i}\in\mathcal{M}\). We are now interested in a practical procedure to obtain a set \(\widetilde{\mathcal{P}}\) such that the approximate solution computed minimizing \(R_{h}^{2}(\cdot;\widetilde{\mathcal{P}})\) is as accurate as possible with \(\widetilde{\mathcal{P}}\) being as small as possible.