{'fraction_non_alphanumeric': 0.03169248524124462, 'fraction_numerical': 0.0062142127924009055, 'mean_word_length': 4.562962962962963, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Local Gaussian Regression

Locally weighted regression was created as a nonparametric learning method that is computationally efficient, can learn from very large amounts of data and add data incrementally. An interesting feature of locally weighted regression is that it can work with spatially varying length scales, a beneficial property, for instance, in control problems. However, it does not provide a generative model for function values and requires training and test data to be generated identically, independently. Gaussian (process) regression, on the other hand, provides a fully generative model without significant formal requirements on the distribution of training data, but has much higher computational cost and usually works with one global scale per input dimension. Using a localising function basis and approximate inference techniques, we take Gaussian (process) regression to increasingly localised properties and toward the same computational complexity class as locally weighted regression.


Introduction
Besides expressivity and sample efficiency, computational cost is a crucial design criterion for machine learning algorithms in real-time settings, such as control problems. An example is the problem of building a model for robot dynamics: The sensors in a robot's limbs can produce thousands of datapoints per second, quickly amassing a local coverage of the input domain. In such settings, fast local learning and generalization can be more important than a globally optimized model. A learning method should rapidly produce a good model from the large number N of datapoints, using a comparably small number M of parameters.
Locally weighted regression (LWR) [1] makes use of the popular and well-studied idea of local learning [2] to address the task of compressing large amounts of data into a small number of parameters. In the spirit of a Taylor expansion, the idea of LWR is that simple models with few parameters may locally be precise, while it may be difficult to find good nonlinear features to capture the entire function globally -lots of good local models may form a good global one.
The key to LWRs low computational cost (linear, O(N M )) is that each local model is trained independently. The resulting speed has made LWR popular in robot learning. The downside is that LWR requires several tuning parameters, whose optimal values can be highly data dependent. This is at least partly a result of the strongly localized training strategy, which does not allow models to 'coordinate', or to benefit from other local models in their vicinity.
Here, we explore a probabilistic alternative to LWR that alleviates the need for parameter tuning, but retains potential for fast training. An initial candidate could be the mixture of experts model (ME) [3]. Indeed, it has been argued [1], that LWR can be thought of as a mixture of experts model in which experts are trained independently of each other. The advantage of ME is that it comes with a full generative model [4,5] allowing for principled learning of parameters and expert allocations, while LWR does not (see Figure 1). However, in this work we emulate LWRs assumption that the data is a continous function as opposed to a mixture of linear models, for instance. When the underlying data is not assumed to be generated by a mixture model, utilizing ME to fit the data makes inference (unneccesarily) complicated. Hence, we are interested in a probabilistic model that captures the best of both worlds without making the mixture assumption: A generative model that has the ability to localize computations to speed up learning.
Our proposed solution is local Gaussian regression (LGR), a linear regression model that explicitly encodes localisation. Starting from the well-known probabilistic, Gaussian formulation of least-squares generalized linear regression, we first re-interpret the well known radial basis feature functions as localisers of constant feature functions. This allows us to introduce more expressive features, capturing the idea of local models within the Gaussian regression framework. In its exact form, this model has the cubic cost in M typical of  graph for locally weighted regression (LWR) (right). LWR assumes a fixed contribution of each local model to each observation. So a V-structure only exists within each m-plate, making inference cheaper. In ME, contributions of experts to each observations are normalized, coupling all the experts and making it necessary to update responsibilities in the e-step in a global manner. In local Gaussian regression, the contribution of each model to observations is uncertain (similar to ME), so the model is more densely connected than LWR. However, LWR is not a generative model for the data: It treats training and test data in different ways.
Gaussian models, arising because observations induce correlation between all local models in the posterior. To decouple the local models, we propose a variational approximation that gives essentially linear cost in the number of models M . The core of this work revolves around fitting the model parameters using maximum likelihood (Section 3.1). As a final note, we show how the novel feature function representation allows us to readily extend our probabilistic model to a local nonparametric formulation (Section 4).
Previous work on probabilistic formulations of local regression [6,7] has been focussed on bottom-up constructions, trying to find generative models for one local model at a time. To our knowledge, this is the first top-down approach, starting from a globally optimal training procedure, to find approximations giving a localized regression algorithm similar in spirit to LWR.

Background
Both LWR and Gaussian regression have been studied extensively before, so we only give brief introductions here. Generalized linear regression maps weights w ∈ R F to the nonlinear function f ∶ R D R via F feature functions φ i (x) ∶ R D R: Using the feature matrix Φ ∈ R N ×F whose elements are Φ nf = φ f (x n ), the function values at N locations x n ∈ R D , subsumed in the matrix X ∈ R N ×D , are f (X) = Φw.
Locally weighted regression (LWR) trains M local regression models. We will assume each local model has K local feature functions ξ mk (x), so that the m-th model's prediction at x is gives a linear model around c m . The models are localized by a nonnegative, symmetric and integrable weighting η m (x), typically the radial basis function with center c m and length scale λ or positive definite metric Λ. In LWR, each local model is trained independently of the others, by minimizing a quadratic loss over the N observations (y n , x n ). At test time, local predictions (2) are combined into a joint prediction at input x as a normalised weighted sum with the features An important observation is that the objective (5) cannot be interpreted as least-squares estimation of the linear model Φ from Eq. (6). Eq. (5) is effectively training n , but that model differs from the one in Equation (6). Thus, LWR can not be cast probabilistically as one generative model for training and test data simultaneously. The factor graph in Figure 1, right, shows this broken symmetry.
Training LWR is linear in N and M , and cubic in K, since it involves a least-squares problem in the K weights w m . But this low cost profile also means absence of mixing terms between the M models, thus no 'coordination' between the local models. One problem this causes is that model-specific hyperparameters are not sufficiently identified and tend to over-fit. To pick one example among the hyperparameters: when learning the length scale parameters λ m , there is no sense of global improvement. Each local model focusses only on fitting data points within a λ m -neighborhood around c m . So the optimal choice is actually λ 0, which gives a useless regression model. To counteract this behaviour, implementations of LWR use regularisation of λ, but of course this introduces free parameters, whose best values are not obvious. Most works in LWR address this problem via leave-one-out cross-validation, which works well if the data is sparse. But when the data is dense, like in robotics, the kernel tends to shrink to only 'activate' points close by the left-out data point.
Gaussian regression [8, §2] is a probabilistic framework for inference on the weights w given the features φ. Using a Gaussian prior p(w) = N (w; µ 0 , Σ 0 ) and a Gaussian likelihood the posterior distribution is itself Gaussian: The mean of this Gaussian posterior is identical with the Σ-regularised least-squares estimator for w, so it could alternatively be derived as the minimiser of the loss function But the probabilistic interpretation of Equation (8) has additional value over (11) because it is a generative model for all (training and test) data points y, which can be used to learn hyperparameters of the feature functions. The prediction for f ( As is widely known, this framework can be extended to the nonparametric case by a limit which replaces all in- . The corresponding priors are Gaussian processes. This generalisation will only play a role in Section 4 of this paper, but the direct connection between Gaussian regression and the elegant theory of Gaussian processes is often cited in favour of this framework. Its main downside, relative to LWR, is computational cost: Calculating the posterior (12) requires solving the least-squares problem for all F parameters w jointly, by inverting the Gram matrix (Σ −1 0 + βΦ ⊺ Φ). In the general case, this inversion requires Ø(F 3 ) operations. The point of the construction in the following sections is to use approximations to lower the computation cost of this operation such that the resulting algorithm is comparable in cost to LWR, while retaining the probabilistic interpretation, and the modelling robustness of the full Gaussian model.
The Gaussian regression framework puts virtually no limit on the choice of basis functions φ, even allowing discontinuous and unbounded functions, but the radial basis function (RBF, aka. Gaussian, squareexponential) features from Equation (3), φ i (x) = η i (x), (for F = M ) enjoy particular popularity for various reasons, including algebraic conveniences and the fact that their associated reproducing kernel Hilbert space lies dense in the space of continuous functions [9]. A downside of this covariance function is that it uses one global length scale for the entire input domain. There are some special kernels of locally varying regularity [10], and mixture descriptions offer a more discretely varying model class [11]. Both, however, require computationally demanding training.

Local Parametric Gaussian Regression
In Gaussian regression with RBF features as described above, without changing anything, the features φ m (x) = η m (x) can be interpreted as M constant function models ξ m (x) = 1, localised by the RBF function, . This representation extends to more elaborate local models ξ(x). For example ξ(x) = x gives a local weighted regression with linear local models. Extending to M local models consisting of K parameters each, feature function φ n mk combines the k th component of the local model ξ km (x n ), localised by the m-th weighting function η m (x) For these features, treating mk as the index set of a vector with M K elements, the results from Equations (8) and (12) apply, giving a localised linear Gaussian regression algorithm.
The choice of local parametric model is essentially arbitrary. But regular features are an obvious choice. A scalar polynomial model of order K − 1 arises from ξ km (x n ) = (x n − c m ) k−1 . Local linear regression in a Kdimensional input space takes the form ξ km (x n ) = x nk − c m . We will adopt this latter model in the remainder, because it is also the most widely used model in LWR. An illustration of LWR regression and the proposed local Gaussian regression is given in Figure 2.
Since it will become necessary to prune out unnecessary parts of the model, we adopt the classic idea of automatic relevance determination [12, 13] using a factorizing prior A m = diag(α m1 , . . . , α mK ).
So every component k of each local model m has its own precision, and can thus be pruned out by setting α mk ∞. Section 3.1 assumes a fixed number M of local models with fixed centers c m . Thus the parameters are θ = {β, {α mk }, {λ mk }}. We propose an approximation for estimating these parameters. Section 3.2 then describes placing the local models incrementally to adapt M and c m .

Learning in Local Bayesian Linear Regression
Exact inference in Gaussian regression with localised feature functions comes with the cubic cost of its nonlocal origins. However, because of the localised feature functions, correlation between far away local models is approximately 0, hence inference is approximately independent between local models. In this section we aim to make use of this "almost independence" to derive a localised approximate inference scheme of low cost, similar in spirit to LWR. To arrive at this localised learning algorithm we first introduce a latent variable f nm for each local model m and data point x n , similar to probabilistic backfitting [14]. Intuitively, the f form approximate targets, one for each local model, against which the local regression parameters fit (see also Figure 1, middle).
This modified model motivates a factorizing variational bound constructed in Section 3.1.1, rendering the the local models computationally independent, which allows for fast approximate inference in the local Gaussian model. Hyperparameters will be learnt by approximate maximum likelihood (3.1.2), i.e. iterating between constructing a bound q(z θ) on the posterior over variables z given current parameter estimates θ and optimising q with respect to θ.

Variational Bound
The complete data likelihood of the modified model is (c.f. Figure 1, left). Our Gaussian model involves the latent variables w and f , the precision β and the model parameters λ m , c m . We treat w and f as probabilistic variables and estimate θ = {β, λ, c}. On w, f , we construct a variational bound q(w, f ) imposing factorisation q(w, f ) = q(w)q(f ). The variational free energy is a lower bound on the log evidence for the observations y: This bound is maximized by the q(w, f ) minimizing the relative entropy D KL [q(w, f ) p(w, f y, θ)], the distribution for which log q(w) = E f [log p(y f , w)p(w, f )] and log q(f ) = E w [log p(y f , w)p(w, f )]. It is relatively straightforward to show (e.g. [15]) that these distributions are Gaussian in both w and f .The approximation on w is where The posterior update equations for the weights are local: each of the local models updates its parameters independently. This comes at the cost of having to update the belief over the variables f nm , which achieves a coupling between the local models. The Gaussian variational bound on f is where µ f n ∈ R M and using B = diag (β f 1 , . . . , β f M ). These updates can be performed in O(M K). Inspecting Equations (23) and (20), one can see that the optimal assignment of all µ w actually amounts to a joint linear problem of size M K × M K, which could also be solved as a linear program. However, this would come at additional computational cost.

Optimizing Hyperparameters
We set the model parameters , {α mk }} to maximize the expected complete log likelihood under the variational bound, Setting the gradient of this expression to zero leads to the following update equations for the variances The gradient with respect to the scales of each local model is completely localized We use gradient ascent to optimize the length scales λ mk . All necessary equations are of low cost and, with the exception of the variance 1 βy , all hyper-parameter updates are solved independently for each local model, similar to LWR. In contrast to LWR, however, these local updates do not cause a shrinking in the length scales: In LWR, both inputs and outputs are weighted by the localizing function, thus reducing the length scale improves the fit. The localization of Equation (13) only affects the influence of regression model m, but the targets still need to be fit accordingly. Shrinking of local models only happens if it actually improves the fit against the unweighted targets f nm .

Prediction
Prediction at a test point x * arise from marginalizing over both w and f , using and where which is linear in M and K.

Incremental Adding of Local Models
Up to here, the number M and locations c of local models were fixed. An extension analogous to the incremental learning of the relevance vector machine [16] can be used to iteratively add local models at new, greedily selected locations c M +1 . The resulting algorithm starts with one local model, and per iteration adds one local model in the variational step. Conversely, existing local models for which all components α mk ∞ are pruned out. This works well in practice, with the caveat that the number local models M can grow fast initially before the pruning becomes effective. Thus we check for each selected location c M +1 whether any of the existing local models c 1∶M produces a localizing weight η m (c M +1 ) ≥ w gen , where w gen is a parameter between 0 and 1 and regulates how many parameters are added. An overview of the final algorithm is given in 1.
Replacing the finitely many local features ξ m with infinitely many features results in the local nonparametric model with covariance function κ m (x,  So computing the posterior covariance Σ mr xx ′ requires one inversion of an N ×N matrix. It remains to be seen to what extend variational bounds on the parametric forms presented in the previous sections can be transported to a local nonparametric Gaussian regression framework.

Experiments
We evaluate and compare to mixture of experts and locally weighted projection regression (LWPR) -an extension of LWR suitable for regression in high dimensional space [17] -on two data sets. The first is data drawn from the "cross function" in Figure 3, often used to demonstrate locally weighted learning. For the second comparison we learn inverse dynamics of a SARCOS anthropomorphic robot arm with seven degrees of freedom [8].
In order to compare to mixture of experts we assume linear expert models. A prior of the form N (w m ; 0, A −1 m ) on each experts regression parameters and normalized gaussian kernels for the mixture components are used in our implementation to make it as comparable as possible. To compute the posterior in the e-step a mean field approximation is employed.
In both experiments, LWPR performed multiple cycles through the data sets. Both the local Gaussian regression and the mixture of experts implementation are executed based on Algorithm 1 and are allowed an additional 1000 iterations to reach convergence.

Data from the 'Cross Function'
We used 2, 000 uniformly distributed training inputs, with zero mean Gaussian noise of variance (0.2) 2 . The test set is a regular grid of 1641 edges without noise and is used to evaluate how well the underlying function is captured. The initial length scale was set to λ m = 0.3, ∀m, and we ran each method with and without lengthscale learning (LSL) for w gen = 0.1, 0.2, . . . , 1.0. All results presented here are results averaged over 5 randomly seeded runs. Table 1 presents the top performance achieved by each method, including what the optimal setting for w gen was and how many local models were used. In both settings (with or without LSL) LGR outperforms both LWPR and ME in terms of accuracy as well as number of local models used. To understand the role of parameter w gen better, we also summarize the normalized mean squared error as a function of parameter w gen for all 3 methods in Figure 4 with (right) and without (left) LSL. The key message of this graph is that the parameter w gen does not affect the performance of LGR greatly. While accuracy slightly improves with increasing w gen it is not dramatic. Thus for LGR w gen can be thought of as a trade-off parameter, for smaller w gen the algorithm has to consider less potential local models, for a slight performance decrease. For LWPR and ME this relationship to w gen is not that clear. Furthermore, although LGR has to consider more local models for larger w gen (up to 2000 for w gen = 1), we only see a slight increase in the number of local models in the final model, indicating that the pruning mechanism works very well.  Finally, we show representative results of the shape of learned local models for LWPR, LGR and ME In Figure 3, nicely illustrating the key difference between the three methods: In LWPR local models don't know of each other and thus aim to find the best linear approximation to the function. In both ME and LGR, the local models know of each other and collaborate to fit the function.

Inverse Dynamics Learning Task
The SARCOS data contains 44, 484 training data points and 4, 449 test data points. The 21 input variables represent joint positions, velocities and accelerations for the 7 joints. The task is to predict the 7 joint torques. In Table 2 we show the predictive performance of LWPR, ME and LGR when trained with lengthscale learning and with w gen = 0.3.
LGR outperforms LWPR and ME in terms of accuracy for almost all joints.However, the true advantage of LGR lies in the fact the number of hand tuned parameters is reduced to setting the learning rate for the gradient descent updates and setting the parameter w gen .

Conclusion
We have taken a top-down approach to developing a probabilistic localised regression algorithm: We start with the generative model of Gaussian generalized linear regression, which amounts to a fully connected graph and thus has cubic inference cost. To break down the computational cost of inference, we first introduce the idea of localised feature functions as local models, which can be extended to local nonparametric models. In as second step, we argue that because of the localisation these local models are approximately independent . We exploit that fact through a variational approximation that reduced computational complexity to local computations. Empirical evaluation suggests that LGR successfully addresses the problem of fitting hyperparameters inherent in locally weighted regression. A final step left for future work is to re-formulate our algorithm into an incremental version that can deal with a continuous stream of incoming data.