## 2 Materials and Methods
### A New Approach: Continued Fractions with Splines
A good choice of the regression model for each \(g_{i}(\mathbf{x})\) is a spline since they are well-established. For reasons stated in the next section, the exception is the first term \(g_{0}(\mathbf{x})\), which is a linear model. We use an additive model to work with multivariate data where each term is a spline along a dimension. That is, given \(m\) predictor variables, we have that  
\[g_{i}(\mathbf{x})=\sum_{j=1}^{m}f_{j}(x_{j}) \tag{7}\]  
for each term \(g_{i}(\mathbf{x})\), \(i>0\), where each function \(f_{j}\) is a cubic spline along variable \(j\), that is, \(f_{j}\) is a piecewise polynomial of degree 3 and is a function of variable \(j\). We implement the splines with a penalized cubic B-spline basis, that is, \(f_{j}(\mathbf{x})=\sum_{i=1}^{k}\beta_{k}B_{k}(x_{j})\), where each \(B_{i}(x)\) is one of \(k\) cubic B-spline basis functions along dimension \(j\) and corresponds to one of \(k\) knots. We use the following loss function \(L(\mathbf{B}(\mathbf{x},\mathbf{y},\boldsymbol{\beta}))\), i.e.,  
\[L(\mathbf{B}(\mathbf{x},\mathbf{y},\boldsymbol{\beta}))=\|\mathbf{y}-\mathbf{ B}\boldsymbol{\beta}\|^{2}+\lambda\sum_{j=0}^{m}\boldsymbol{\beta}^{T} \mathbf{P}_{j}\boldsymbol{\beta} \tag{8}\]  
where \(\mathbf{B}\) is the matrix of cubic B-spline basis functions for all variables, \(\boldsymbol{\beta}\) is the vector of all of the weights, and \(\mathbf{P}_{j}\) is the associated second derivative smoothing penalty matrix for the basis for the spline \(f_{j}\). This is standard for spline models [16]. The pseudocode for this approach is shown in Algorithm 1. ```
Input: Training data \(\mathcal{D}=\{(\mathbf{x_{1}},f(\mathbf{x_{1}}),...,(\mathbf{x_{n}},f(\mathbf{x_{n} }))\}\) and parameters \(\lambda\), \(k\), norm, and max_depth /* Let \(n\) be the number of samples; \(m\) be the number of variables */ /* \(\mathbf{X}\in\mathbb{R}^{n\times m}\) be data matrix and \(\mathbf{y}\in\mathbb{R}^{n}\) be the vector of targets. */
1 knot_indices = {} \(\mathbf{y^{(0)}}\leftarrow\mathbf{y}\)/norm for\(i\gets 0,1,...,\text{max\_depth}\)do
2 if\(i=0\)then
3 /* \(g_{0}\) is a linear model parameterized by fi, and is fit with least squares. */
4 if\(\leftarrow\text{argmin}_{\mathbf{f}}\|\mathbf{y^{(0)}}-\mathbf{Xfi}\|^{2}\)
5 else /* \(g_{i}\) be an additive spline model as given in equation (7), parameterized by fi. For each predictor variable, the knots are at the samples indexed by the first \(k\) indices in knot_indices */
6 for\(j\gets 1,2,...,m\)do
7\(f_{j}\leftarrow\text{new SplineModel()}\)
8 for each index \(p\) in knot_indices do
9\(f_{j}\leftarrow\text{AssignKnotAt(\mathbf{X}[p][j])}\)
10
11 end for
12
13 end for
14\(g_{i}=\sum_{j=1}^{m}f_{j}(x_{j})\) /* Construct the splines, and fit with regularized least squares */
15\(\mathbf{B}\leftarrow\text{BSplineBasisMatrix($g_{i}$.knots}$)\) \(\mathbf{P}_{j}\leftarrow\text{BSplinePenaltyMatrix($f_{j}$: for each $f_{j}$ in $g_{i}$)}\)
16\(\mathbf{fi}\leftarrow\text{argmin}_{\mathbf{f}}\|\mathbf{y^{(i)}}-\mathbf{Bfi}\|^ {2}+\lambda\sum_{j=1}^{m}\mathbf{fi}^{T}\mathbf{P}_{j}\mathbf{fi}\)
17 end for /* Compute \(\mathbf{ffi}_{i}\), the vector of residuals of the \(i\)th model, and then compute the targets and knot locations for the next depth. */
18\(\mathbf{ffi}_{i}\leftarrow\mathbf{y^{(i)}}-g_{i}(\mathbf{X})\)
19\(C_{i}\leftarrow|\min_{\mathbf{x}}\mathbf{ffi}_{i}|\) \(\mathbf{y^{(i+1)}}\leftarrow(\mathbf{ffi}_{i}+C_{i})^{-1}\)
20 knot_indices \(\leftarrow\) SelectKnots(\(\mathbf{ffi}_{i}\))
21 end for
22 The estimate for \(f(\mathbf{x})\) at \(max\_depth\) is: \[\approx\text{norm}\,\cdot\left[g_{0}(\mathbf{x})-C_{0}+\frac{\text{max\_depth }}{\text{K}}\frac{1}{g_{i}(\mathbf{x})-C_{i}}\right]\]
```  
**Algorithm 1**Iterative CFR using additive spline models with adaptive knot selection