# From Trees to Barcodes and Back Again: Theoretical and Statistical Perspectives
## 2 Mathematical Background
### The TNS: From Barcodes to Trees
#### 2.4.1 Bifurcation/Termination  
The branching process in the TNS algorithm is based on the concept of a _Galton-Watson tree_[25], which is a finite rooted tree recursively generated as follows. At each step, a number of offspring is independently sampled from a distribution. Since a geometric tree consists only of bifurcations, terminations, and continuations, the accepted values for the number of offspring are: zero (termination), one (continuation), and two (bifurcation). The Galton-Watson algorithm generates only a combinatorial tree, with no embedding in space, so we modify the traditional process to introduce a dependency of the tree growth on the embedding, so that the bifurcation/termination probabilities depend on the path distance of the growing tip from the root.  
The bifurcation/termination step of the growth process of a geometric tree with associated barcode \(B\) proceeds as follows. Each growing tip of the tree is assigned a bar \((b_{i},d_{i})\) sampled from the barcode \(B\) and a bifurcation angle \(a_{i}\). The growing tip first checks the probability to bifurcate, then the probability to terminate. If the growing tip does not bifurcate or terminate, then the branch continues to elongate. The probability to bifurcate depends on \(b_{i}\): as the distance from the root to the growing tip approaches \(b_{i}\), the probability to bifurcate increases exponentially until it attains a maximum of \(1\) at \(b_{i}\). Similarly, the probability to terminate depends exponentially on \(d_{i}\).  
The probabilities to bifurcate and terminate are sampled from an exponential distribution \(e^{-\lambda x}\), whose free parameter \(\lambda\) should be wisely chosen. A very steep exponential distribution (high value of \(\lambda\)) reduces the variance of the population of geometric trees synthesized based on the same barcode. On the other hand, a very low value of \(\lambda\) results in trees that are almost random, since the dependence on the input persistence barcode is decreased significantly. If we assume that growth takes place in discrete steps of size \(L\), the value of the parameter \(\lambda\) should be of the order of the step size \(L\), to ensure biologically appropriate variance [21]. Assuming \(L=1\) in some appropriate units, we usually select \(\lambda\approx 1\), so that the bifurcation and termination points are stochastically chosen but still strongly correlated with the input persistence barcodes.  
Contrary to other neuron synthesis algorithms [26] that sample the branching and termination probabilities from independent distributions, in the TNS, the correlation of these probabilities is captured in the structure of the barcode. When the growing tip bifurcates, the corresponding bar is removed from the input barcode to exclude re-sampling of the same conditional probability,thus recording the tree's growth history, which is essential for reproducing the branching structure. In the event of a termination, the growing tip is deactivated, and the bar that corresponds to this termination point is removed from the reference barcode.  
At a bifurcation, the directions of the two daughter branches created depend on the bifurcation angle \(a_{i}\). In this study, we focus primarily on the combinatorial type and the TMD type of the generated geometric tree, so we do not investigate the effect of bifurcation angles on the growth.