Use the HS-SVD stable-basis solver¶
HS-SVD is the solver that the drivers and the C++ library use by default for the GP fit and the posterior. It replaces the Cholesky factor of the ill-conditioned covariance with a well-conditioned basis. This guide gives the switches for every interface, runs a comparison of HS-SVD with the Cholesky path on a deliberately ill-conditioned training set, and lists what the record measured for it, including the variants that did not pay off.
Status: on by default in gprn, gprd and the C++ library. The Python
Surrogate default is off. The C API keeps HS-SVD unless a caller selects
GPR_HSSVD_BACKEND_CHOLESKY (ABI 1.19). See Methods: numerics for the full record.
What it does¶
The Hilbert-Schmidt SVD of Fasshauer and McCourt writes the Gaussian kernel
through its Mercer eigenfunctions, \(K = A A^{T}\) with \(A = \Phi\,
\operatorname{diag}(\sqrt{\lambda})\). A thin SVD \(A = U S V^{T}\) gives the
stable basis \(\Psi = A V S^{-1}\), which is orthonormal at the training
nodes. The nearest orthonormal polar factor of those columns is computed
only in StableBasisND::factorize. The dual-kernel path and
factorizeGPCartesian keep the SVD factor. The derivative rows enter as extra rows of \(A\), so one SVD
conditions the whole energy and gradient system. With noise variance
\(s^2\), the solve and the log determinant are explicit:
\[ (K + s^2 I)-1y = \(\Psi\)\,operatorname{diag}\!left(frac{1}{S_i^2 + s^2}right):math:PsiTy
frac{1}{s^2}left(y - \(\Psi\) \(\Psi\)Tyright),
\]
Here \(r\) is the number of kept modes. The matrix \(K\) is never formed, so
no jitter rescue is needed. The production route is the dual form. It
eigendecomposes the \(n_{obs} \times n_{obs}\) kernel with Eigen’s self-adjoint
solver on the host in both linalg modes (driver eigen_selfadjoint), so the
host result does not depend on the BLAS or LAPACK build. In library mode,
cuSOLVER is used at one rank when a GPU is present, and ScaLAPACK pdsyev
runs from order 1 across ranks when unconstrained reductions are enabled.
Those drivers take different last bits (and so, on a band search, a different
number of oracle calls) from the host solver. It drops spectrum below a chop
tolerance of 1e-6. (Sources: gpr/ml/gp/StableBasis.h;
commits 34930aee1, b0e69c294, 2937db94f.)
Switches¶
Interface |
Switch |
|---|---|
CLI |
|
CLI |
|
TOML |
|
Python |
|
C++ |
|
C API |
|
Fortran |
|
R |
|
Julia |
|
Rust |
|
The defaults are --gp-hssvd-dual-chop-tol 1e-6, --gp-hssvd-dual-lapack-rrr true and --gp-hssvd-dual-randomized-sketch 0, which turns the sketch off.
The Python Surrogate default is off, so the high-level Python class does not
use HS-SVD unless .hssvd() is called. The paper campaign passes
--gp-hssvd false (bench/uma/canonical_argv). A one-time [hssvd] line on the
standard error reports the conditioning of the basis. It does not change the
result.
Compare it with the Cholesky path¶
The program builds two models for a two-atom system with identical kernel,
noise and jitter. One uses HS-SVD and one uses the Cholesky factor. The
training set holds six geometries that include a near-duplicate pair
(0.9 and 0.9000001), which is what raises the condition number of the raw
kernel. It then compares the posterior mean and variance on the training
data, between the data and far outside it. Far outside the data, the two terms
of the variance are nearly equal, so any cancellation shows up first there.
The program fails if any difference exceeds the tolerances of
HssvdCholeskyAgreement.MeanAndVarianceAgreeAcrossDistances: 1e-6 inside the
data and 1e-5 outside it, or if a variance is negative.
#include <algorithm>
#include <cmath>
#include <cstdio>
#include "gpr/ml/GaussianProcessRegression.h"
static gpr::AtomsConfiguration twoAtomConfig()
{
gpr::AtomsConfiguration cfg;
const gpr::Index_t n_atoms = 2;
cfg.positions.resize(1, 3 * n_atoms);
cfg.positions << 0.0, 0.0, 0.0, 0.9, 0.0, 0.0;
cfg.is_frozen.resize(1, n_atoms);
cfg.is_frozen.setConstant(0);
cfg.id.resize(1, n_atoms);
cfg.id << 0, 1;
cfg.atomicNrs.resize(1, n_atoms);
cfg.atomicNrs.setConstant(1);
cfg.type.resize(1, n_atoms);
cfg.type.setZero();
cfg.atoms_mov.resize(n_atoms);
cfg.atoms_mov.type.resize(1, n_atoms);
cfg.atoms_mov.type.setZero();
cfg.atoms_mov.positions.resize(1, 3 * n_atoms);
cfg.atoms_mov.positions = cfg.positions;
cfg.pairtype.resize(1, 1);
cfg.pairtype(0, 0) = 0;
cfg.n_pt = 1;
return cfg;
}
static gpr::Observation trainingSet()
{
const int n = 6;
const double r[n] = {0.80, 0.90, 0.9000001, 1.00, 1.15, 1.30};
gpr::Observation obs;
obs.R.resize(n, 6);
obs.E.resize(n, 1);
obs.G.resize(n, 6);
obs.G.setZero();
for (int i = 0; i < n; ++i) {
obs.R.row(i) << 0.0, 0.0, 0.0, r[i], 0.0, 0.0;
const double d = r[i] - 1.0;
obs.E(i, 0) = 0.5 * d * d;
obs.G(i, 3) = d;
}
return obs;
}
static void configure(gpr::GaussianProcessRegression& gp,
const gpr::Observation& obs, gpr::AtomsConfiguration& cfg,
bool hssvd)
{
gpr::InputParameters params;
params.gp_sigma2.value = 1e-4;
params.sigma2.value = 1e-4;
params.jitter_sigma2.value = 1e-10;
params.magnSigma2.value = 1.0;
params.constSigma2.value = 1.0;
params.report_level.value = 0;
gp.initialize(params, cfg);
gp.setHssvdBackend(hssvd);
if (hssvd) gp.setHssvdDualLapackRrr(true);
gp.setHyperparameters(obs, cfg, false, false, false);
gpr::GPRSetup setup;
setup.sigma2 = 1e-4;
setup.jitter_sigma2 = 1e-10;
gp.setParameters(setup);
gp.getLikGaussian().setSigma2(1e-4);
gp.getConstantCovarianceFunction().setConstSigma2(1.0);
gp.getSexpAtCovarianceFunction().getLengthScaleRef().resize(1, cfg.n_pt);
gp.getSexpAtCovarianceFunction().getLengthScaleRef().setConstant(1.0);
gp.getSexpAtCovarianceFunction().setMagnSigma2(1.0);
gp.getSexpAtCovarianceFunction().setConfInfo(cfg);
gp.updateModelWithFullData(const_cast<gpr::Observation&>(obs));
}
static void answerAt(gpr::GaussianProcessRegression& gp, double r, double& mean, double& var)
{
gpr::EigenMatrix q(1, 6);
q << 0.0, 0.0, 0.0, r, 0.0, 0.0;
gpr::Observation qm, qv;
qm.R = q; gp.calculatePotentialDispatched(qm);
qv.R = q; gp.calculateVarianceDispatched(qv);
mean = qm.E(0, 0); var = qv.E(0, 0);
}
int main()
{
const gpr::Observation obs = trainingSet();
gpr::AtomsConfiguration cfg_a = twoAtomConfig(), cfg_b = twoAtomConfig();
gpr::GaussianProcessRegression gp_hssvd, gp_chol;
configure(gp_hssvd, obs, cfg_a, true);
configure(gp_chol, obs, cfg_b, false);
const double basis_condition = gp_hssvd.hssvdBasisConditionNumberForTesting();
std::printf("condition number of the stable basis %.6f\n", basis_condition);
if (std::abs(basis_condition - 1.0) > 1e-8) return 1;
struct Point {
double r;
const char* where;
double tolerance;
};
const Point points[] = {{0.90, "at a training point", 1e-6},
{1.05, "between training points", 1e-6},
{2.50, "far outside the data", 1e-5}};
for (const Point& p: points) {
double mean_a, var_a, mean_b, var_b;
answerAt(gp_hssvd, p.r, mean_a, var_a);
answerAt(gp_chol, p.r, mean_b, var_b);
std::printf("%-24s mean difference %.1e, variance difference %.1e\n",
p.where, std::abs(mean_a - mean_b), std::abs(var_a - var_b));
if (std::abs(mean_a - mean_b) > p.tolerance) return 1;
if (std::abs(var_a - var_b) > p.tolerance) return 1;
if (var_a < 0.0 || var_b < 0.0) return 1;
}
std::printf("hssvd and cholesky agree\n");
return 0;
}
condition number of the stable basis 1.000000
at a training point mean difference <s>, variance difference <s>
between training points mean difference <s>, variance difference <s>
far outside the data mean difference <s>, variance difference <s>
hssvd and cholesky agree
The stable basis has condition number 1, as it does by construction. The two
solvers agree to far better than the tolerances. The mean differs most far
outside the data, by about 3e-7. The program calls
hssvdBasisConditionNumberForTesting, a hook that the test suite uses. On
this fixture the Cholesky path with a jitter of 1e-10 is adequate. The test
asserts agreement, not which side is right.
What the record measured¶
Each number has its source next to it.
Measure |
Value |
Source |
|---|---|---|
Conditioning, 1D prototype |
cond(K) 6.4e13 to cond(Psi) 1.000 |
commit |
Conditioning, 2D, 108 gradient observations |
cond(K_full) 3.8e13 to cond(Psi) 1.000 |
commit |
Conditioning, 01_hcn, 100 observations |
cond(C) 1.2e6 to cond(Psi) 1.000000, rank 40 of 2925 |
commit |
Agreement with a direct LDLT solve at sigma2 1e-4 |
alpha 2.0e-9, log determinant 7.3e-10, mean 1.4e-10, variance 5.8e-10 |
commit |
Cost of the primal eigendecomposition |
30 percent of the converged np=1 NEB wall on Baker 01_hcn |
commit |
Fixed bug: variance short of dense |
up to 0.77 percent at likelihood variance 1e-4, 47.5 percent at 1e-6, at jitter 1e-6 |
|
Mode count at the chop tolerance |
rank about 40 of 215 holds 99.9 percent of the kernel energy |
commit |
The d016 search (PET-MAD-S, 14 atoms, one rank, MAP, mean of three trials)
reaches the endpoint -7.18349 eV after 12 outer iterations with an internal
wall time of 4.916 s (standard deviation 0.013 s), of which 2.183 s (44.4
percent) goes to hyperparameter optimisation and 2.691 s (54.7 percent) to
the oracle (docs/orgmode/explanation/performance.org). No head-to-head
wall time of HS-SVD against the dense Cholesky on the same search is recorded
in the documents or commit messages, so this page gives none. The reason to
use it is the conditioning, not a speed gain.
Variants that did not pay off¶
All of these are on develop, opt-in or default off, and none is recommended. Methods: numerics has the full list.
Mode pruning (
mode_prune_rtol, default 0). Magnitude pruning keeps almost all 2925 modes, because the tail over the maximum is 9.6e-6 against a threshold of 1e-13. The rank collapse comes from correlation between the columns of \(\Phi\), not from the size of the eigenvalues (commit85e5255e5). Measured, not adopted.Randomised dual sketch (
--gp-hssvd-dual-randomized-sketch N). The speed-up is about \(n_{obs}/l\): 0.65 times at 96 observations and 13.6 times at 2000 (85e5255e5). That is neutral in the NEB regime. A cachegrind run at \(n=25\) put it at 218509283 instructions against 60287128 for the baseline (benchmark ledger). Measured, not adopted.Theta-skip and the HS-SVD append (
--theta-shift-skip-auto). On d016 the GP optimisation went from 3.5 s to 14.0 s, and the skip never fired: 15 full factorisations and no appends (commite43efef3e). Measured, not adopted.The cut-and-revert series. A dozen screened ideas on the d016 fixture failed the parity envelope or the wall guard. For example,
hssvd_translation_rayleigh_scaletook 14 outer iterations against a maximum of 12 and 9.191 s of wall (benchmark ledger).
Use it¶
Leave it on. To compare against Cholesky, pass --gp-hssvd false to the
driver, or call setHssvdBackend(false) before the fit, as the program above
does. To change what it keeps, change the chop tolerance, not the mode
pruning.