pymor.algorithms.ml.vkoga.regressor

Classes

VKOGARegressor

Scikit-learn-style regressor using the VKOGASurrogate.

VKOGASurrogate

Surrogate for the weak greedy error used when training the VKOGARegressor.

class pymor.algorithms.ml.vkoga.regressor.VKOGARegressor(kernel=None, criterion='fp', max_centers=20, tol=1e-06, reg=1e-12)[source]

Bases: BaseRegressor

Scikit-learn-style regressor using the VKOGASurrogate.

The regressor uses the weak_greedy in its fit-method to select centers according to the given criterion.

The algorithm is described in [WH13] and [SH21].

Parameters:
  • kernel – Kernel to use in the regressor. The kernel is assumed to have a scalar-valued output. For vector-valued outputs, the interpolant uses vector-valued coefficients, i.e., the prediction is computed as a linear combination of kernel evaluations with vector-valued weights. The interface of the kernel needs to follow the scikit-learn interface and in particular a __call__-method for (vectorized) evaluation of the kernel and a diag-method for computing the diagonal of the kernel matrix are required. For convenience, a Gaussian kernel is provided in pymor.algorithms.ml.vkoga.kernels. If kernel=None is passed, a Gaussian kernel will be initialized by default.

  • criterion – Selection criterion for the greedy algorithm. Possible values are 'fp', 'f' and 'p'.

  • max_centers – Maximum number of selected centers in the greedy algorithm.

  • tol – Tolerance for the weak greedy algorithm.

  • reg – Regularization parameter for the kernel interpolation.

extend(X, Y)[source]

Incrementally extend the VKOGA surrogate with new training data.

New data points are added to the surrogate’s training set. A greedy step is then performed to decide whether any of the new points should be selected as centers.

Parameters:
  • X – New training inputs.

  • Y – New training targets.

fit(X, Y)[source]

Fit VKOGA surrogate using pyMOR’s weak greedy algorithm.

Parameters:
  • X – Training inputs.

  • Y – Training targets.

Returns:

The trained regressor.

predict(X)[source]

Predict the target for the input X.

Parameters:

X – Input for which to compute the prediction.

Returns:

Prediction obtained by the VKOGASurrogate.

class pymor.algorithms.ml.vkoga.regressor.VKOGASurrogate(kernel, X_train, F_train, criterion='fp', reg=1e-12)[source]

Bases: WeakGreedySurrogate

Surrogate for the weak greedy error used when training the VKOGARegressor.

Not intended to be used directly.

evaluate(mus, return_all_values=False)[source]

Evaluate the surrogate for given parameters.

Parameters:
  • mus – List of parameters for which to estimate the approximation error. When parallelization is used, mus can be a RemoteObject.

  • return_all_values – See below.

Returns:

  • If return_all_values is True, an NumPy array of the estimated errors.

  • If return_all_values is False, the maximum estimated error as first

  • return value and the corresponding parameter as second return value.

extend(mu)[source]

Extends the kernel interpolant by adding a new center and updating all quantities.

Incrementally add a new center \(\mu\) with corresponding function value from the training data. This function updates

  • the selected centers (self._centers)

  • the indices of the selected centers in the training set (self._centers_idx)

  • the (squared) power function evaluations on the training set (self._power2)

  • the Newton basis evaluations on the training set (self._V)

  • the residual \(f - s_f\) at the training points (self.res)

  • the coefficients in the Newton basis (self._z).

In the following derivation we leave out the regularization term for simplicity and restrict ourselves to scalar kernels. Let \(K_n\) denote the full kernel matrix for the current set of selected centers \(X_n\). Since \(K_n\) is a kernel matrix, it is in particular positive-definite, so it has a Cholesky decomposition, i.e. \(K_n=L_nL_n^\top\). Evaluating the Newton basis at the selected centers yields a lower-triangular matrix that equals \(L_n\). Rather than tracking \(L_n\) explicitly, the coefficients of the kernel interpolant are recovered from the Newton-basis coefficients by a single triangular solve at prediction time (see predict).

Updating the coefficients of the kernel interpolant: Let \(c_n\in\mathbb{R}^n\) denote the coefficients associated to the kernel interpolant for the first \(n\) selected centers (\(X_n\)), i.e.

\[K_n c_n = f_n,\]

where \(f_n\in\mathbb{R}^n\) corresponds to the vector of target values at the selected centers. The kernel interpolant is then given as

\[s_f^n(x) := \sum\limits_{i=1}^{n} (c_n)_i k(x, x_i),\]

where \(X_n=\{x_1,\dots,x_n\}\subset\mathbb{R}^d\) is the set containing the \(n\) selected centers. When adding \(\mu\) as new center, i.e. \(X_{n+1}=X_n\cup \{\mu\}\), the updated kernel coefficients \(c_{n+1}\in\mathbb{R}^{n+1}\) are recovered from the Newton-basis coefficients \(z_1,\ldots,z_{n+1}\) by solving

\[L_{n+1}^\top c_{n+1} = \begin{bmatrix} z_1 & \cdots & z_{n+1} \end{bmatrix}^\top.\]

The new Newton-basis coefficient \(z_{n+1}\in\mathbb{R}\) is computed via the residual \(r_n\) and the power function \(P_n\) for the centers \(X_n\) evaluated at \(\mu\) (the definitions of these quantities are given below):

\[\begin{aligned} z_{n+1} = \frac{r_n(\mu)}{P_n(\mu)}. \end{aligned}\]

The residual \(r_n=f-s_f^n\) is defined as the difference between the target function \(f\) and the current kernel interpolant \(s_f^n\) and can be updated via the following recursion:

\[\begin{aligned} r_n(x) = r_{n-1}(x) - z_n V_n(x) \end{aligned}\]

with initial residual \(r_0 = f\). Here, \(V_n\) denotes the Newton basis for

\[\begin{aligned} V(X_n) := \mathrm{span}\{k(\,\cdot\,,x_1), \dots, k(\,\cdot\,,x_n)\}. \end{aligned}\]

The first Newton basis is given as

\[\begin{aligned} V_{1}(x)= \frac{k(x, x_1)}{\sqrt{k(x_1, x_1)}}. \end{aligned}\]

The subsequent Newton basis functions are computed via the Gram-Schmidt algorithm as

\[\begin{aligned} V_{n+1}(x) = \frac{k(x, \mu) - \sum_{j=1}^n V_j(x) V_j(\mu)}{P_n(\mu)}. \end{aligned}\]

Regarding the power function (measuring for \(x\in\mathbb{R}^d\) how well the current subspace can represent \(k(\,\cdot\,,x)\), i.e. the projection error in the reproducing kernel Hilbert space): The initial squared power function is given as

\[\begin{aligned} P_0^2(x) = k(x, x) \end{aligned}\]

and the incremental update of the squared power function \(P_n^2\) can be computed by

\[\begin{aligned} P_n^2(x) = P_{n-1}^2(x) - V_n(x)^2. \end{aligned}\]

We are going to track this quantity evaluated at all training points during the iterations of the greedy algorithm.

Parameters:

mu – Index of parameter (center) in the training set to add.

extend_training_data(X_new, F_new)[source]

Add new training points and update all internal quantities.

Parameters:
  • X_new – New training inputs.

  • F_new – New training targets.

predict(X)[source]