# Probability Density Estimation through Nonparametric Adaptive Partitioning and Stitching
## 2 Nonparametric Adaptive Partitioning and Stitching
### Stitching Process  
The stitching process involves two blocks taken from two different layers. At a particular point on the support for the \(PDF(x)\), there will be two options to choose from, the PDF on the left, denoted as \(PDF1(x)\), or the PDF on the right, denoted as \(PDF2(x)\). The left and right blocks are uniquely determined by where the point of interest at \(x\) divides the block. The stitch makes no distinction as to which layer the block is a member of.  
We define a variable \(u\) to monitor the linear proportion (i.e., fraction) of the probability contribution of a block relative to its _right_ side. Operationally, let \(u=0:\frac{1}{n-1}:1\) be an empirical cumulative distribution function (CDF) normalized such that \(u\) ranges from 0 to 1, where 0 and 1, respectively, represent the far most left and right sides of a block in terms of counting data points within it. Since every point in a block corresponds to a particular point on the x-axis, it is straightforward to construct two functions, called \(u_{1}(x_{k})\) and \(u_{2}(x_{k})\), for the purpose to represent the fraction of density contribution from the left and right blocks at location \(x_{k}\). As such, with the exception of the first and last blocks, a stitch is made by averaging the two available left and right block estimates for the PDF in terms of weights given by their complementary CDF and CDF, respectively. However,  
Figure 4: Stitching process: (**a**) A set of independent PDF estimates for different subsamples for all blocks in both layers 1 and 2 are shown before stitching. This example considers a trimodel Gaussian mixture distribution of the form: (\(p_{1}=0.33,\ p_{2}=0.33,\ p_{3}=1-p_{1}-p_{2}\), \(\mu_{1}=4,\ \mu_{2}=5\), \(\mu_{3}=6,\ \sigma_{1}=0.5,\ \sigma_{2}=0.25,\ \sigma_{3}=0.5\)). (**b**) After the stitching process is applied to the collection of PDF estimates for all blocks, the resultant density estimate is shown.  
the labeling of points by index \(k\) was done for conceptual purposes. We have estimates for any value of \(x\) as continuous functions. As such, we drop the index \(k\), and understand that we can provide the value of the function at any \(x\) by interpolation. Note that there are data-driven nonlinear relations between \(x\) and \(u_{1}(x)\) and between \(x\) and \(u_{2}(x)\).  
Starting at \(x=x_{L}\) and ending at \(x=x_{R}\), then for \(x_{L}\leq x\leq x_{R}\) the left block will trace \(u_{1}(x)\) from \(u_{1}(x_{L})\) to 1, while the right block will trace \(u_{2}(x)\) from 0 to \(u_{2}(x_{R})\). The interpolation is always in the mutually shared region where two estimates from \(PDF1\) and \(PDF2\) are available. The stitch formula is given as:  
\[PDF(x)=\frac{PDF1(x)(1-u_{1}(x))^{2}+PDF2(x)u_{2}(x)^{2}}{(1-u_{1}(x))^{2}+u_{ 2}(x)^{2}}. \tag{5}\]  
The PDF estimate becomes a weighted average of the two PDFs where the weight factors through the complementary CDF given by \(1-u_{1}(x)\) and the CDF given by \(u_{2}(x)\) are data-driven. Examples of the estimated CDF and complimentary CDF are shown in Figure 5. It is seen that as the point of interest moves along the \(x\)-axis, the weight factors change in a continuous way in terms of \((1-u_{1})^{2}\) and \(u_{2}^{2}\), which smooths out the two possible PDF estimates by a weighted mean given in Equation (5). A visual example of how the stitching process transforms the scaffold set of PDF estimates into a continuous function is given in Figure 5 where the end result is an interpolation between two estimated PDFs.  
No stitch is performed for the far left and far right blocks, which use \(PDF1(x)\) and \(PDF2(x)\), respectively. For internal blocks, the stitching procedure provides a smooth PDF estimate for all \(x\) as shown in Figure 4 that is piecewise differentiable across blocks.