# Heterogeneous Treatment Effect with Trained Kernels of the Nadaraya-Watson Regression
## 4 The TNW-CATE Description
In this case, arbitrary batches of pairs \((\mathbf{x},\mathbf{x}_{i})\) and pairs \((\mathbf{z},\mathbf{z}_{i})\) can be fed to the single network. This implies that we can construct testing neural networks consisting of \(c\) and \(t\) trained subnetworks in order to estimate \(\tilde{y}\) and \(\tilde{h}\) corresponding to \(\mathbf{z}\) and \(\mathbf{x}\), respectively, under condition \(\mathbf{z}=\mathbf{x}\). Figures 4 and 5 show the trained neural networks for estimating \(\tilde{y}\) and \(\tilde{h}\), respectively. It is important to point out that the testing networks are not trained. Sets of \(c\) pairs \((\mathbf{x},\mathbf{x}_{1}),\ldots,(\mathbf{x},\mathbf{x}_{c})\) and \(t\) pairs \((\mathbf{z},\mathbf{z}_{1}),\ldots,(\mathbf{z},\mathbf{z}_{t})\) are fed to the subnetworks of the control and treatment networks, respectively. The whole examples for testing taking into account the outcomes are  
\[\mathbf{a}_{i}^{(r)} =\left(\mathbf{x}_{1}^{(r)},\ldots,\mathbf{x}_{n}^{(r)}, \mathbf{x}_{i,j}y_{1}^{(r)},\ldots,y_{n}^{(r)},y_{i}\right),\]0  
and  
\[\mathbf{a}_{i}^{(r)} =\left(\mathbf{x}_{1}^{(r)},\ldots,\mathbf{x}_{n}^{(r)}, \mathbf{x}_{i,j}y_{1}^{(r)},\ldots,y_{n}^{(r)},y_{i}\right),\]1  
\[\mathbf{a}_{i}^{(r)} =\left(\mathbf{x}_{1}^{(r)},\ldots,\mathbf{x}_{n}^{(r)}, \mathbf{x}_{i,j}y_{1}^{(r)},\ldots,y_{n}^{(r)},y_{i}\right),\]2 The trained neural network for computing \(\tilde{y}\) in accordance with the Nadaraya–Watson regression. In sum, the networks implement the Nadaraya-Watson regressions:  
\[\mathbf{a}_{i}^{(r)} =\left(\mathbf{x}_{1}^{(r)},\ldots,\mathbf{x}_{n}^{(r)}, \mathbf{x}_{i,j}y_{1}^{(r)},\ldots,y_{n}^{(r)},y_{i}\right),\]3 \[\mathbf{a}_{i}^{(r)} =\left(\mathbf{x}_{1}^{(r)},\ldots,\mathbf{x}_{n}^{(r)}, \mathbf{x}_{i,j}y_{1}^{(r)},\ldots,y_{n}^{(r)},y_{i}\right),\]4  
Finally, CATE \(\tau(\mathbf{x})\) or \(\tau(\mathbf{z})\) is estimated as \(\tau(\mathbf{x})=\tau(\mathbf{z})=\tilde{h}-\tilde{y}\). The phases of the neural network training and testing are schematically shown as Algorithms 1 and 2, respectively. ```
0: Datasets \(\mathcal{C}\) of \(c\) controls and \(\mathcal{T}\) of \(t\) treatments, numbers \(N\) and \(M\) of generated subsets of \(\mathcal{C}\) and \(\mathcal{T}\), numbers of examples in generated subsets \(n\) and \(m\)
0: The trained weight sharing neural network implementing the Nadaraya-Watson regressions for control and treatment data
1:for\(i=1\), \(i\leq c\)do
2:for\(r=1\), \(r\leq N\)do
3: Generate subset \(\mathcal{C}_{i,r}\subset\mathcal{C}\backslash(\mathbf{x}_{i},y_{i})\) (see (10))
4: Form example \(\mathbf{a}_{i}^{(r)}\) (see (11))
5:endfor
6:endfor
7:for\(j=1\), \(j\leq t\)do
8:for\(s=1\), \(s\leq M\)do
9: Generate subset \(\mathcal{T}_{j,s}\subset\mathcal{T}\backslash(\mathbf{z}_{j},h_{j})\) (see (12))
10: Form example \(\mathbf{b}_{j}^{(s)}\) (see (13))
11:endfor
12:endfor
13: Train the weight sharing neural network with the loss function given in (18) on the set of pairs \((\mathbf{a}_{i}^{(r)},\mathbf{b}_{j}^{(s)})\)

\[\mathbf{a}_{i}^{(r)} =\left(\mathbf{x}_{1}^{(r)},\ldots,\mathbf{x}_{n}^{(r)}, \mathbf{x}_{i,j}y_{1}^{(r)},\ldots,y_{n}^{(r)},y_{i}\right),\]5 The trained neural network for computing \(\tilde{h}\) in accordance with the Nadaraya–Watson regression. ```
0: Trained neural control and treatment networks implementing the Nadaraya-Watson regressions; datasets \(\mathcal{C}\) and \(\mathcal{T}\); testing example \(\mathbf{x}=\mathbf{z}\)
0: CATE \(\tau(\mathbf{x})\)
1: Form the testing example \(\mathbf{a}(\mathbf{x})\) in accordance with (19)
2: Form the testing example \(\mathbf{b}(\mathbf{z})\) in accordance with (20)
3: Feed \(\mathbf{a}(\mathbf{x})\) to the control network and \(\mathbf{b}(\mathbf{z})\) to the treatment network and obtain the corresponding predictions \(\tilde{y}\) and \(\tilde{h}\)
4:\(\tau(\mathbf{x})=\tilde{h}-\tilde{y}\)
```

**Algorithm 2** The algorithm implementing TNW-CATE in the testing phase.