======================================= The joint energy-force Gaussian process ======================================= A surrogate that fits energies and forces separately can predict a force field that is not the gradient of any energy. An oracle call in GPRidge never returns an energy alone: every call to the wrapped potential returns :math:`E(x)` and the Cartesian gradient :math:`\nabla E(x)` together (see :doc:`the surrogate loop <../surrogate_loop>`). The model that consumes those observations does not fit three independent models for the force components and a fourth for the energy. It fits one latent scalar function and treats every observed force component as a linear (differential) functional of that same function. This page derives the consequence of that choice: the energy-force covariance is fixed once the scalar kernel is fixed, and the resulting force field is conservative by construction, not by penalty. **Status:** implemented. This is the default model of ``gprn`` and ``gprd`` (class ``gpr::GaussianProcessRegression`` with the covariance ``gpr::SexpatCF``). The block identities are checked by a SymPy script under ``scripts/``, and the kernel convention by a scikit-learn comparison test; the last section lists both. One latent function, four covariance blocks ------------------------------------------- Let :math:`f` be the latent scalar process, :math:`f \sim \mathcal{GP}(0, k)`, and identify :math:`f(x) = E(x)`. Because differentiation is linear, :math:`f(x)` and :math:`-\partial_{x_a} f(x)` are jointly Gaussian for a differentiable kernel :math:`k`, and every covariance between an energy observation and a force component reduces to a covariance between :math:`f` and a partial derivative of :math:`f`. Writing :math:`K_{EE}` for the energy-energy block, :math:`K_{EF}` for energy-force, :math:`K_{FE}` for force-energy, and :math:`K_{FF}` for force-force, .. math:: K_{EE}(x,y) = k(x,y), \qquad K_{EF}(x,y) = -\nabla_y k(x,y), .. math:: K_{FE}(x,y) = -\nabla_x k(x,y), \qquad K_{FF}(x,y) = \nabla_x \nabla_y^\top k(x,y). Every block is a derivative of the **same** scalar function :math:`k(x,y)`; nothing about the force blocks introduces a new covariance structure. ``scripts/derive_symmetry_adapted_joint_gp.py`` checks this symbolically (function ``joint_energy_force_blocks``, theorem ``theorem_joint_blocks_are_invariant_and_equivariant``): differentiating one scalar kernel produces an energy block that is invariant under a relabeling of identical atoms and force blocks that transform equivariantly under the same relabeling, because both are literally partial derivatives of the one invariant scalar. The script goes one step further (theorem ``theorem_joint_tensor_is_one_feature_gram``) and shows the full block tensor is itself a Gram matrix. For a feature-map kernel :math:`k(x,y)=\phi(x)^\top\phi(y)`, stack the feature and its negated Jacobian into one factor, .. math:: \Phi(x) = \begin{pmatrix} \phi(x) \\ -J_\phi(x)^\top \end{pmatrix}, and the joint block tensor equals :math:`\Phi(x)\Phi(y)^\top` exactly. A Gram matrix is PSD for any feature map, so the joint energy-force covariance is PSD without any separate argument about differentiability or block symmetry: it is a Gram matrix because the construction is a Gram matrix. That is the sense in which ``derive_soft_geodesic_energy_force_gp.py`` and ``derive_symmetry_adapted_joint_gp.py`` both build every additive term as an explicit feature map rather than patching a differentiated kernel after the fact (see :doc:`the soft geodesic heat-kernel prior `). Curl-free by construction ------------------------- A GP posterior draw over :math:`f` is, for a smooth kernel, almost surely a smooth scalar function. If the model reports the force as :math:`F(x) = -\nabla f(x)` for that same :math:`f`, then .. math:: \nabla \times F = \nabla \times (-\nabla f) \equiv 0 identically, for every draw and for the posterior mean alike. The posterior mean energy :math:`\mu(x)` is a finite linear combination of the kernel :math:`k(x, x_i)` and of its derivatives with respect to the training geometries, and the posterior mean force is :math:`-\nabla\mu(x)`. That field has zero curl everywhere the kernel is twice differentiable, with no extra term added to enforce it. Contrast this with training three independent scalar GPs, one per Cartesian force component. Nothing in that construction ties :math:`F_x`, :math:`F_y`, :math:`F_z` back to a common potential; three independently-fitted, independently-noisy models will not generally satisfy :math:`\nabla \times F = 0`, so the resulting surrogate would not correspond to any potential energy surface. The joint energy-force GP avoids that failure mode structurally: differentiating one scalar function makes the zero-curl property automatic. No constraint gets imposed, checked, or projected out afterward. The production kernel: SexpatCF over inverse distances ------------------------------------------------------ The scalar kernel used in practice is ``gpr::SexpatCF``, a squared exponential evaluated not on raw Cartesian coordinates but on the inverse-distance descriptor :math:`\phi(x)` built by ``gpr::InverseDistanceDescriptor``. Each feature :math:`\phi_f(x)=1/r_{ab}(x)` belongs to one atom pair :math:`f=(a,b)` (moving-moving pairs first, then moving-frozen pairs), with :math:`r_{ab}` in Angstrom. Each pair carries a **pairtype** :math:`\mathrm{pt}(f)`: a C-H pair and a C-C pair are different pairtypes with independently fitted length scales :math:`\ell_{\mathrm{pt}}` (an ARD length scale per pairtype). With a positive ``--gp-pair-cutoff`` the feature is the inverse distance multiplied by a quintic switch that reaches zero at the cutoff (``gpr/auxiliary/PairCutoff.h``); the formulas below hold for either choice of :math:`\phi_f`. The kernel is .. math:: k(x,y) = \sigma^2 \exp\!\left( -\sum_{f} \frac{\big(\phi_f(x) - \phi_f(y)\big)^2} {\ell_{\mathrm{pt}(f)}^2} \right), where the sum runs over the atom-pair features :math:`f`, :math:`\sigma^2` is the signal variance (``magnSigma2``) and :math:`\ell_{\mathrm{pt}}` is the length scale of pairtype :math:`\mathrm{pt}` (``SexpatCF::lengthScale``, one entry per pairtype, or one shared entry). The features are in 1/Angstrom, so each :math:`\ell_{\mathrm{pt}}` is in 1/Angstrom. :math:`\sigma^2` has the units of the training targets squared: eV squared with ``--gp-no-output-norm true``, dimensionless in the default case, where the targets are standardized before the fit. The factor in the exponent follows the code. The squared distance accumulated in ``gpr/auxiliary/Distance.cpp`` is :math:`d^2(x,y)=2\sum_f(\phi_f(x)-\phi_f(y))^2/\ell_{\mathrm{pt}(f)}^2`, and ``SexpatCF::calculateCovarianceMatrix`` returns :math:`\sigma^2\exp(-d^2/2)`. Equivalently :math:`k` is the ordinary squared-exponential kernel :math:`\sigma^2\exp(-\tfrac12\sum_f(z_f(x)-z_f(y))^2/\ell^2)` on the scaled features :math:`z_f=\sqrt2\,\phi_f`. The test ``python/tests/test_sklearn_reference_gp.py`` checks this convention against an RBF kernel of scikit-learn on a diatomic. The hyperparameters are stored as logarithms, :math:`\theta_0=\log\sigma^2` and :math:`\theta_{1+\mathrm{pt}}=\log\ell_{\mathrm{pt}}` (a single :math:`\theta_1` when the length scale is shared). ``SexpatCF::buildSharedKernel`` takes the per-pairtype squared distance :math:`d_{\mathrm{pt}}=2\sum_{f\in\mathrm{pt}}(\phi_f(x)-\phi_f(y))^2` at unit length and evaluates :math:`\exp(\theta_0)\cdot\exp(-\tfrac12\sum_{\mathrm{pt}} \exp(-2\theta_{1+\mathrm{pt}})\,d_{\mathrm{pt}})`. A shorter :math:`\ell_{\mathrm{pt}}` lets the model resolve sharper curvature along the bond coordinate of one pairtype without over-smoothing the rest; that is the practical reason SexpatCF carries one length scale per pairtype rather than one global length scale. Because energy and force observations are always expressed in Cartesian coordinates, the code applies the derivative-block theorem above through the Jacobian of the descriptor map (``InverseDistanceDescriptor::computeWithJacobian``). For the feature built from the pair :math:`(a,b)`, .. math:: J(f, 3a+d) = -\frac{(x_a-x_b)_d}{r_{ab}^3}, \qquad J(f, 3b+d) = +\frac{(x_a-x_b)_d}{r_{ab}^3}, the derivative of :math:`1/r_{ab}` with respect to Cartesian component :math:`d` of atom :math:`a` or :math:`b`. For a moving-frozen pair only the column of the moving atom is nonzero. (The comment above ``computeWithJacobian`` in ``gpr/auxiliary/InverseDistanceDescriptor.h`` states the opposite signs; the implementation in ``InverseDistanceDescriptor.cpp`` and the derivative above agree with each other.) Composing a smooth Jacobian with a Gram-factor kernel preserves the Gram structure by the ordinary chain rule, so the block tensor built by ``ginput2=/=ginput3=/=ginput4`` and the ``calculateGradOfCovMatrixWithDerivatives*`` family is exactly :math:`K_{EE}, K_{EF}, K_{FE}, K_{FF}` as derived above, with :math:`x` replaced by :math:`\phi(x)` throughout. The inverse-distance choice also keeps the descriptor finite through linear (collinear) geometries, where a bond-angle chart would have a coordinate singularity. The features :math:`1/r_{ab}` and the entries of :math:`J` are finite whenever every pair distance is positive, and collinear geometries of distinct atoms satisfy that. The SymPy check ``theorem_linear_geometry_descriptor_is_regular`` in :doc:`the soft geodesic heat-kernel prior ` verifies the same statement for log pair distances, the descriptor of that page's regularity argument, not for :math:`1/r`. What the page does not establish -------------------------------- The identities are algebraic. They do not show that this kernel makes a search converge faster than another kernel, and they do not choose the hyperparameters; see :doc:`the surrogate loop <../surrogate_loop>` for the limits of a convergence claim and :doc:`Choose GP settings <../../howto/gp_settings>` for the settings that change the kernel. Checks ------ The covariance-block identities of the first sections are checked without finite differences in ``scripts/derive_symmetry_adapted_joint_gp.py``. The pixi task ``derive-symmetry-adapted-joint-gp`` runs it in the ``symbolic`` environment; any Python with SymPy runs it directly. The script prints ``ALL_CHECKS_PASS`` when every theorem holds and stops with an ``AssertionError`` naming the first check that fails. The kernel convention of the ``SexpatCF`` section is checked separately by ``python/tests/test_sklearn_reference_gp.py``. The script also checks that a molecular permutation-symmetry group layers on top of this construction (Reynolds-projecting the base kernel keeps every block PSD and the correct invariant/equivariant symmetry), and that projecting only an additive extra term without also projecting the base kernel is **not** sufficient to restore permutation symmetry of the composite (``theorem_partial_projection_leaves_composite_wrong``). That result matters directly for the additive geodesic term introduced in :doc:`the soft geodesic heat-kernel prior `. Related ------- - Explanation: :doc:`How GPRidge finds a saddle <../method>` places this kernel in the whole method; :doc:`the surrogate loop <../surrogate_loop>` describes the joint observations during a search; :doc:`the mathematics index ` lists the other theory pages. - How-to: :doc:`Choose GP settings <../../howto/gp_settings>` lists the flags and keys that set the kernel, the pair cutoff and the length scales. - Reference: :doc:`TOML configuration keys <../../reference/config_keys>` and :doc:`the command-line reference <../../reference/cli_reference>` define ``--gp-pair-cutoff`` and the other GP options.