============================================= Use the variational atomic inducing posterior ============================================= The atomic environment model writes the energy as a sum of atomic contributions. It fits them with the variational bound of Titsias (2009) on a small set of inducing environments, so only matrices of the inducing size are factored. This guide shows the C++ class on a toy descriptor, reads what it reports, and gives the command-line switch for the drivers. **Status:** implemented, opt-in, experimental. The default is off. The model has no validated production speedup claim, and no measured accuracy or speed number for it is recorded in the repository (``docs/atomic_environments.md``). It is reachable from the C++ API and from the ``gprn`` and ``gprd`` command lines. It has no TOML key, C function, Fortran entry point or Python name. See :doc:`Methods: approximations <../explanation/methods/approximations>` for the wider record of sparse and inducing methods. What it fits ------------ Let :math:`K` be the prior covariance of the observations, :math:`U` the covariance of the inducing variables and :math:`C` their cross covariance. The low-rank part is :math:`Q = C U^{-1} C^{T}`, and :math:`D` holds the noise variances of the energy and gradient rows. The negative variational bound is \\[ \tfrac12\left[ y\ :sup:`T`\(Q+D)\ :sup:`-1`\y + :math:`\log`|Q+D| + n:math:`\log` 2:math:`\pi` - \operatorname{tr}\\{D\ :sup:`-1`\(K-Q)\\} \right]. \\] The trace term charges the fit for the part of the prior that the inducing set cannot represent. The predictive variance keeps :math:`K-Q`, so a configuration away from every inducing environment keeps its prior uncertainty. The model keeps every energy and every moving-atom force component. A frozen atom adds to the energy sum and to the derivatives with respect to the atoms near it. Run the class on a toy descriptor --------------------------------- The class takes a descriptor as a function. It maps a position vector to the species, the descriptor values and the Jacobian of every atomic environment. The program uses a three-coordinate toy with four environments of two species, so it needs no SOAP library. It does four things. 1. It prepares the posterior on 12 observations of a smooth energy surface and 5 inducing environments. The 12 observations give 48 rows, the energy plus three gradient components each. 2. It compares the analytic gradient of the bound with central differences in all five parameters. The parameters are the log magnitude variance, the log length scale of each species, and the log energy and gradient noise variances. 3. It fits at those parameters and predicts at the training points. 4. It compares the predictive variance at a training geometry with that at a point far from the data. .. code:: cpp #include #include #include #include #include "gpr/ml/AtomicInducingPosterior.h" using gpr::AtomicEnvironments; using gpr::AtomicInducingPosterior; using gpr::Observation; using Vector = Eigen::VectorXd; using Matrix = Eigen::MatrixXd; static AtomicEnvironments descriptor(const Vector& x) { AtomicEnvironments result; result.atomic_numbers = {78, 78, 29, 78}; result.values.resize(4, 2); result.values << x(0), 0.5 * x(1) * x(1), x(1) + 0.2 * x(2), std::sin(x(0)), x(2), 0.2 * x(0) * x(1), -0.6, 0.9; result.jacobians.assign(4, Matrix::Zero(3, 2)); result.jacobians[0](0, 0) = 1.0; result.jacobians[0](1, 1) = x(1); result.jacobians[1](0, 1) = std::cos(x(0)); result.jacobians[1](1, 0) = 1.0; result.jacobians[1](2, 0) = 0.2; result.jacobians[2](0, 1) = 0.2 * x(1); result.jacobians[2](1, 1) = 0.2 * x(0); result.jacobians[2](2, 0) = 1.0; return result; } int main() { const Eigen::Index n = 12; Observation data; data.R.resize(n, 3); data.E.resize(1, n); data.G.resize(n, 3); for (Eigen::Index i = 0; i < n; ++i) { const double x = -0.4 + 0.063 * i; const double y = 0.3 * std::cos(0.7 * i); const double z = -0.2 + 0.093 * i; data.R.row(i) << x, y, z; data.E(0, i) = 7.0 + 0.3 * x * x + std::cos(y) + 0.4 * z * z + 0.2 * x * y * z; data.G.row(i) << 0.6 * x + 0.2 * y * z, -std::sin(y) + 0.2 * x * z, 0.8 * z + 0.2 * x * y; } AtomicInducingPosterior::Basis basis; basis.atomic_numbers = {78, 29, 78, 29, 78}; basis.values.resize(5, 2); basis.values << -0.5, 0.2, -0.7, 0.4, 0.4, -0.3, 0.5, -0.2, -0.6, 0.9; const double magnitude_variance = 1.3; const double energy_noise = 1e-4; const double gradient_noise = 1e-4; const double inducing_jitter = 1e-5; const double step = 1e-6; AtomicInducingPosterior model; model.prepare(data, descriptor, basis, inducing_jitter); const Vector theta = model.initialParameters( magnitude_variance, {{29, 0.75}, {78, 1.1}}, energy_noise, gradient_noise); const auto bound = model.evaluate(theta); double worst = 0.0; for (Eigen::Index k = 0; k < theta.size(); ++k) { Vector up = theta, down = theta; up(k) += step; down(k) -= step; const double numeric = (model.evaluate(up).value - model.evaluate(down).value) / (2.0 * step); worst = std::max(worst, std::abs(bound.gradient(k) - numeric) / std::abs(numeric)); } std::printf("bound %.4e, trace term %.4e\n", bound.value, bound.trace_penalty); std::printf("largest relative gradient difference %.1e\n", worst); if (!model.fit(theta)) return 1; std::printf("rows %ld, inducing environments %ld\n", static_cast(model.observationCount()), static_cast(model.inducingCount())); Observation train; train.R = data.R; model.calculatePotential(train); std::printf("largest training error: energy %.2e, gradient %.2e\n", (train.E - data.E).cwiseAbs().maxCoeff(), (train.G - data.G).cwiseAbs().maxCoeff()); Observation probe; probe.R.resize(2, 3); probe.R << data.R.row(3), 5.0, 5.0, 5.0; model.calculateVariance(probe); std::printf("energy variance near the data %.2e, far away %.2e\n", probe.E(0, 0), probe.E(0, 1)); if (worst > 1e-5) return 1; if (model.inducingCount() >= model.observationCount()) return 1; if (!(probe.E(0, 1) > probe.E(0, 0))) return 1; std::printf("atomic posterior checked\n"); return 0; } :: bound , trace term largest relative gradient difference rows 48, inducing environments 5 largest training error: energy , gradient energy variance near the data , far away atomic posterior checked Three points about the numbers. - The parameters here are not fitted. ``fit`` conditions at the parameters that it is given, and ``evaluate`` returns the bound and its exact gradient for an outer optimiser. The driver runs that optimiser. The training error is therefore a property of the chosen parameters and the toy descriptor, not of the method. - The trace term is nearly all of the bound at these parameters. It measures how much of the prior the five inducing environments leave out. - The variance grows away from the data because the posterior keeps :math:`K-Q`. With every observed environment as an inducing point, the derivative rows can still keep uncertainty outside the span of the energy inducing variables (``docs/atomic_environments.md``). Run it from the drivers ----------------------- The driver builds the descriptors with featomic (SOAP), selects the inducing environments and runs the same posterior. .. code:: bash gprn --potential lj --gp-nonperiodic true --gp-atomic-environments true \ --gp-observation-archive off reactant.con product.con The build option is ``use_featomic`` (default ``auto``). Without it, ``GaussianProcessRegression::setAtomicEnvironmentModel(true)`` throws ``std::invalid_argument`` (``tests/gpr/ml/AtomicEnvironmentModelTest.cpp``). The fit reports an error for any uncertainty mode but MAP, for noise fitting, for virtual observations, per-geometry extra noise or a robust likelihood, and for a chemistry-factorised hyperparameter fit. Observation archives keep the data, and the parameter seed format rejects atomic parameter exports. The inducing environments follow a rule with no tuning constant: a deterministic sample estimates the median positive descriptor distance of each species, half of it is the selection radius, and every environment farther than that from the chosen representatives becomes another representative. When to try it -------------- The paper campaign does not use it (``bench/baselines/h2h_classic_uma.py`` lists the flag in neither argument vector). To judge it on a system, follow the repository's own instruction: compare final force convergence, saddle identity, oracle calls and wall time against the full GP on the same systems and resources. Do not use it as a production default. For a side-by-side with the other approximations, see :doc:`Choose a solver by problem size `.