Pair-type inverse-distance squared-exponential primitive. More...
#include <gpr/covariance_functions/SexpatCF.h>
Classes | |
| struct | CrossBlockGeometry |
| struct | PriorState |
| Every prior the kernel places on its magnitude and length scales. More... | |
Public Types | |
| using | AlphaKPairInfo = Sexpat::AlphaKPairInfo |
| using | PreparedAlphaK = Sexpat::PreparedAlphaK |
| using | HessianPrecision = Sexpat::HessianPrecision |
| using | ExpDistArray |
| Calculates covariances between the derivatives. | |
| using | SharedDerivatives = Derivatives<std::vector<FieldMatrixd>> |
| Evaluate gradient of covariance function with respect to both input variables x1 and x2 (in different dimensions). | |
Public Member Functions | |
| SexpatCF () | |
| virtual | ~SexpatCF () |
| void | setHessianPrecision (HessianPrecision precision) noexcept |
| HessianPrecision | hessianPrecision () const noexcept |
| void | setUseLongDoubleHessian (bool enabled) noexcept |
| bool | useLongDoubleHessian () const noexcept |
| bool | meanHessianVector (const Coord &training, const Eigen::VectorXd &weights, const Eigen::VectorXd &position, const Eigen::VectorXd &direction, Eigen::VectorXd &action) const |
| double | calculateLogPrior () |
| Evaluate the log prior density of the parameters. | |
| FieldMatrixd | calculateLogPriorGradient () |
| Evaluate the gradient of the log prior density of the parameters with respect to parameters. | |
| void | calculateCovarianceMatrix (const Coord &x1, Coord &x2, FieldMatrixd &C) |
| Evaluate covariance matrix between two input vectors. | |
| void | correlationDistances (const Coord &left, const Coord &right, const AtomsConfiguration &configuration, FieldMatrixd &distances) const |
| void | calculateTrainingCovarianceMatrix (const Coord &x, FieldMatrixd &C) |
| Evaluate the prior variance for each training input. | |
| void | calculateGradOfCovMatrix (const Coord &x1, Coord &x2, std::vector< FieldMatrixd > &DKff) |
| Evaluate gradient of covariance function with respect to the parameters. | |
| void | calculateGradOfCovMatrixWithDerivatives (const Coord &x1, Coord &x2, FieldMatrixIdx &dims, std::vector< FieldMatrixd > &DKff) |
| Evaluate gradient of covariance function, of which has been taken partial derivative with respect to x1, with respect to parameters. | |
| void | calculateGradOfCovMatrixWithDerivatives2 (const Coord &x1, Coord &x2, FieldMatrixIdx &dims1, FieldMatrixIdx &dims2, std::vector< FieldMatrixd > &DKff) |
| Evaluate gradient of covariance function, of which has been taken partial derivatives with respect to both input variables x1 and x2 with respect to parameters. | |
| void | calculateDirectionalCovarianceMatrix (const Coord &x1, Coord &x2, const Eigen::VectorXd &direction, FieldMatrixd &first, FieldMatrixd &second) |
| Evaluate the directional first and second derivatives of the covariance matrix along a parameter-space direction. | |
| void | calculateDirectionalCovarianceMatrixWithDerivatives (const Coord &x1, Coord &x2, FieldMatrixIdx &dims, const Eigen::VectorXd &direction, FieldMatrixd &first, FieldMatrixd &second) |
| Evaluate directional first and second derivatives of the derivative-vs-value covariance block. | |
| void | calculateDirectionalCovarianceMatrixWithDerivatives2 (const Coord &x1, Coord &x2, FieldMatrixIdx &dims1, FieldMatrixIdx &dims2, const Eigen::VectorXd &direction, FieldMatrixd &first, FieldMatrixd &second) |
| Evaluate directional first and second derivatives of the derivative-vs-derivative covariance block. | |
| bool | buildCrossBlockGeometry (const Coord &x1, const Coord &x2, uint8_t derivative_options, const FieldMatrixIdx &dims1, const FieldMatrixIdx &dims2, CrossBlockGeometry &geometry) const |
| Build theta-independent pairtype geometry for a covariance block. | |
| bool | buildCrossBlockDerivativesOnly (const Coord &x1, const Coord &x2, uint8_t derivative_options, const FieldMatrixIdx &dims1, const FieldMatrixIdx &dims2, CrossBlockGeometry &geometry) const |
| Populate only the derivative fields (d1, d2, d12) of a CrossBlockGeometry, skipping the per-pairtype distance computation. | |
| bool | buildSharedDistanceForTrainingGeometry (const Coord &x_loc, std::vector< FieldMatrixd > &shared_distance_neg_per_pt) const |
| Build the per-pairtype distance tensor at unit lengthscale for a single coordinate slice (shared across all training-cov blocks). The output convention matches CrossBlockGeometry.distance: shared_distance_neg_per_pt[pt] = -dist_at_vec(x_loc, x_loc, unit)[pt]. | |
| bool | evaluateCrossBlockGeometry (const CrossBlockGeometry &geometry, const Eigen::VectorXd &theta, FieldMatrixd &out) const |
| Evaluate a cross-block geometry at packed Sexpat log parameters. | |
| bool | evaluateCrossBlockGeometryShared (const CrossBlockGeometry &geometry, const std::vector< FieldMatrixd > &shared_distance_neg_per_pt, const Eigen::VectorXd &theta, FieldMatrixd &out) const |
| Same as evaluateCrossBlockGeometry but reads the per-pairtype distance from an externally-shared tensor (negated, matching the sign convention of buildCrossBlockGeometry). The supplied geometry's .distance field is ignored; .d1, .d2, .d12 are still consulted. | |
| bool | buildSharedKernel (const std::vector< FieldMatrixd > &shared_distance_neg_per_pt, const Eigen::VectorXd &theta, FieldMatrixd &kernel_out) const |
| Apply theta to a shared distance to produce the kernel value K(theta)[n, m] = exp(theta(0)) * exp(-0.5 * sum_pt exp(-2 theta(1+pt)). | |
| bool | evaluateCrossBlockGeometryWithSharedKernel (const CrossBlockGeometry &geometry, const FieldMatrixd &shared_kernel, const Eigen::VectorXd &theta, FieldMatrixd &out) const |
| Evaluate a derivative-only block against a pre-computed shared kernel matrix (from buildSharedKernel). No exp() per call. | |
| bool | calculateDirectionalCovarianceMatrixFromGeometry (const FieldMatrixd &shared_kernel, const std::vector< FieldMatrixd > &shared_distance_neg_per_pt, const Eigen::VectorXd &theta, const Eigen::VectorXd &direction, FieldMatrixd &first, FieldMatrixd &second) const |
| Directional first and second derivatives for the Kff block from shared training geometry. | |
| bool | calculateDirectionalCovarianceMatrixWithDerivativesFromGeometry (const CrossBlockGeometry &geometry, const FieldMatrixd &shared_kernel, const std::vector< FieldMatrixd > &shared_distance_neg_per_pt, const Eigen::VectorXd &theta, const Eigen::VectorXd &direction, FieldMatrixd &first, FieldMatrixd &second) const |
| Directional first and second derivatives for a Kdf block from shared training geometry. | |
| bool | calculateDirectionalCovarianceMatrixWithDerivatives2FromGeometry (const CrossBlockGeometry &geometry, const FieldMatrixd &shared_kernel, const std::vector< FieldMatrixd > &shared_distance_neg_per_pt, const Eigen::VectorXd &theta, const Eigen::VectorXd &direction, FieldMatrixd &first, FieldMatrixd &second) const |
| Directional first and second derivatives for a D/Kdf2 block from shared training geometry. | |
| bool | calculateGradOfCovMatrixFromGeometry (const FieldMatrixd &shared_kernel, const std::vector< FieldMatrixd > &shared_distance_neg_per_pt, const Eigen::VectorXd &theta, std::vector< FieldMatrixd > &DKff, const std::vector< Eigen::Index > *parameter_indices=nullptr) const |
| Geometry-path replacement for calculateGradOfCovMatrix. Produces DKff[0] = K (untruncated kernel), DKff[1+pt] = K * inv_l_pt^2 * shared_distance_neg[pt] (== -K * dist_pt_actual in the legacy negated sign convention). Scalar-length case collapses to a single DKff[1] entry that sums across pairtypes. An optional nonempty parameter list selects output blocks in the given order. All parameters still contribute to the kernel and its Cartesian derivatives; only the requested hyperparameter derivatives are formed. | |
| bool | calculateGradOfCovMatrixWithDerivativesFromGeometry (const CrossBlockGeometry &geometry, const FieldMatrixd &shared_kernel, const std::vector< FieldMatrixd > &shared_distance_neg_per_pt, const Eigen::VectorXd &theta, std::vector< FieldMatrixd > &DKff, const std::vector< Eigen::Index > *parameter_indices=nullptr) const |
| Geometry-path replacement for calculateGradOfCovMatrixWithDerivatives (Kdf block dK). | |
| bool | calculateGradOfCovMatrixWithDerivatives2FromGeometry (const CrossBlockGeometry &geometry, const FieldMatrixd &shared_kernel, const std::vector< FieldMatrixd > &shared_distance_neg_per_pt, const Eigen::VectorXd &theta, std::vector< FieldMatrixd > &DKff, const std::vector< Eigen::Index > *parameter_indices=nullptr) const |
| Geometry-path replacement for calculateGradOfCovMatrixWithDerivatives2 (D and Kdf2 blocks). | |
| bool | applyCrossBlockGeometryToVector (const CrossBlockGeometry &geometry, const Eigen::VectorXd &theta, const Eigen::VectorXd &weights, bool transpose_field, Eigen::VectorXd &out) const |
| Apply a cross-block geometry directly to a vector. | |
| void | ginput2 (const Coord &x1, Coord &x2, FieldMatrixIdx &dims, std::vector< FieldMatrixd > &DKff, ExpDistArray *out_expdist=nullptr) |
| void | ginput3 (const Coord &x1, Coord &x2, FieldMatrixIdx &dims1, FieldMatrixIdx &dims2, std::vector< FieldMatrixd > &DKff, ExpDistArray *out_expdist=nullptr, const SharedDerivatives *precomputed=nullptr) |
| void | ginput4 (const Coord &x1, Coord &x2, FieldMatrixIdx &dims, std::vector< FieldMatrixd > &DKff, ExpDistArray *out_expdist=nullptr) |
| Evaluate gradient of covariance function with respect to x. | |
| void | predictMeanAlphaK (const Coord &x_train, const Coord &x_test, const Eigen::Ref< const Eigen::VectorXd > &alpha_E, const Eigen::Ref< const Eigen::VectorXd > &alpha_G_flat, Eigen::Ref< Eigen::VectorXd > mu_E_out, Eigen::Ref< Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > > mu_G_out) |
| Per-test-point predict mean (energy + gradient) via the Schmitz/Chmiela JPCL 2022 eq.6 alpha-K early contraction applied at the per-pair level. | |
| bool | prepareAlphaK (const Coord &x_train, const Eigen::Ref< const Eigen::VectorXd > &alpha_E, const Eigen::Ref< const Eigen::VectorXd > &alpha_G_flat, PreparedAlphaK &prepared) const |
| void | predictMeanAlphaKPrepared (const PreparedAlphaK &prepared, const Coord &x_test, Eigen::Ref< Eigen::VectorXd > mu_E_out, Eigen::Ref< Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > > mu_G_out) const |
| void | trainingGradientAlphaK (const Coord &x_train, const Eigen::Ref< const Eigen::VectorXd > &alpha_E, const Eigen::Ref< const Eigen::VectorXd > &alpha_G_flat, Eigen::Ref< Eigen::VectorXd > quad_out, bool distributed=false, std::size_t *local_pair_count=nullptr, const linalg::MpiContext *process_group=nullptr) |
| void | setMagnSigma2 (double value) |
| void | setLengthScale (double value) |
| void | setFarFieldRadius (double radius) |
| double | farFieldRadius () const |
| void | setManifoldChart (std::shared_ptr< const geometry::InternalCoordinateChart > chart, double length_scale) |
| void | clearManifoldChart () |
| bool | usesManifoldChart () const noexcept |
| const std::shared_ptr< const geometry::InternalCoordinateChart > & | manifoldChart () const noexcept |
| Eigen::Index | manifoldDimensions () const noexcept |
| FieldMatrixd | manifoldJointEnergyGradientCovariance (const Coord &positions) const |
| FieldMatrixd | manifoldJointEnergyGradientCrossCovariance (const Coord &left_positions, const Coord &right_positions) const |
| void | resetManifoldGeometryRowsEvaluatedForTesting () const noexcept |
| void | addManifoldGeometryRowsEvaluatedForTesting (Eigen::Index left_rows, Eigen::Index right_rows) const noexcept |
| std::size_t | manifoldGeometryRowsEvaluatedForTesting () const noexcept |
| void | setGeodesicHeatReferencePath (const Coord &reference_path, double covariance_weight) |
| void | setGeodesicHeatKernel (std::shared_ptr< const GeodesicHeatEnergyForceKernel > kernel) |
| Attach an immutable heat component with its own reference and metric. | |
| const std::shared_ptr< const GeodesicHeatEnergyForceKernel > & | geodesicHeatKernel () const noexcept |
| void | rescaleGeodesicHeatCovariance (double factor) |
| Convert the additive component to a different output variance unit. | |
| void | clearGeodesicHeatKernel () noexcept |
| bool | usesGeodesicHeatKernel () const noexcept |
| Eigen::Index | geodesicHeatDimensions () const noexcept |
| FieldMatrixd | geodesicHeatJointEnergyGradientCovariance (const Coord &positions) const |
| FieldMatrixd | geodesicHeatJointEnergyGradientCrossCovariance (const Coord &left_positions, const Coord &right_positions) const |
| void | setConfInfo (const AtomsConfiguration &value) |
| const AtomsConfiguration & | getConfInfo () const noexcept |
| void | setParameters (const Eigen::VectorXd &w) |
| Set parameters of this covariance function using the provided vector. | |
| double | getMagnSigma2 () |
| double | getMagnSigma2 () const |
| FieldMatrixd & | getLengthScaleRef () |
| const FieldMatrixd & | getLengthScaleRef () const |
| FieldMatrixd & | getAtomisticLengthScaleRef () noexcept |
| Pair-type metric retained independently of the chart's fitted length. | |
| const FieldMatrixd & | getAtomisticLengthScaleRef () const noexcept |
| std::shared_ptr< const KernelOperator > | assembledOperator () const |
| The configured base and optional additive heat component. | |
| void | clear () |
| void | setPriorParametersGaussian (const PriorBase &prior) |
| void | setPriorParametersSqrtt (const PriorBase &prior) |
| void | setPriorParametersLogNormal (const PriorBase &prior) |
| PriorBase | getPriorParametersGaussian () |
| PriorBase | getPriorParametersSqrtt () |
| PriorBase | getPriorParametersLogNormal () |
| void | setUseLogNormalMagnPrior (bool enabled) noexcept |
| bool | useLogNormalMagnPrior () const noexcept |
| void | setModelProfile (GPModelProfile profile) |
| GPModelProfile | getModelProfile () const noexcept |
| void | setLengthScalePriorWeights (const Eigen::VectorXd &weights) |
| const Eigen::VectorXd & | lengthScalePriorWeights () const noexcept |
| void | setHierarchicalPrior (const Eigen::VectorXd &mu_log, double s2_log) |
| void | setHierarchicalPrior (const Eigen::VectorXd &mu_log, double s2_log, const Eigen::VectorXd &s2_log_per) |
| const Eigen::VectorXd & | hierarchicalPriorMu () const noexcept |
| void | setHierarchicalAnchorMask (std::vector< char > mask) |
| bool | hierarchicalAnchored (Eigen::Index n) const noexcept |
| double | hierarchicalPriorVariance (Eigen::Index n) const noexcept |
| Variance of packed parameter ~n~ under the hierarchical prior. | |
| void | clearHierarchicalPrior () |
| void | setPcLengthScalePrior (const Eigen::VectorXd &lambda) |
| void | clearPcLengthScalePrior () |
| bool | hasHierarchicalPrior () const |
| bool | hasPcLengthScalePrior () const noexcept |
| PriorState | priorState () const |
| void | restorePriorState (PriorState state) |
| Eigen::VectorXd | combineParameters () |
| Combine parameters of the covariance function into one Eigen vector. | |
| double | calculateDirectionalLogPriorCurvature (const Eigen::VectorXd &direction) const |
| Evaluate the second directional derivative of log p(theta) along the packed log-parameter direction. | |
| void | cacheDistances (const Coord &x1, const Coord &x2) |
| Pre-compute and cache inverse distances for the given positions. | |
| void | clearDistanceCache () |
| Invalidate the distance cache. | |
| bool | hasDistanceCache () const |
Friends | |
| class | Sexpat |
Pair-type inverse-distance squared-exponential primitive.
Geodesic add is assembled as Sum(Sexpat, GeodesicHeat). Manifold dispatch is assembled as Pullback(SE, chart). A geodesic summand can augment either base; chart and pair-metric length scales are independent.
Definition at line 74 of file SexpatCF.h.
Definition at line 81 of file SexpatCF.h.
Calculates covariances between the derivatives.
| x1 | Matrix of coordinates |
| x2 | Matrix of coordinates |
| dims | Coordinate-dimension indices for the derivative covariance. |
| DKff | Output derivative-covariance blocks. |
| out_expdist | Optional output array of the shared exponential distance factors. Row-major array of exp(-0.5 * d^2), the shared squared-exponential factor. ginput2 and ginput3 both build one; the out-parameter below hands it to a caller that would otherwise recompute the same transcendental over the same distances. |
Definition at line 472 of file SexpatCF.h.
Definition at line 83 of file SexpatCF.h.
Definition at line 82 of file SexpatCF.h.
| using gpr::SexpatCF::SharedDerivatives = Derivatives<std::vector<FieldMatrixd>> |
Evaluate gradient of covariance function with respect to both input variables x1 and x2 (in different dimensions).
This function takes a covariance function structure GPCF, a matrix X of input vectors and returns DKff, the gradients of twice derivatived covariance matrix K(df,df) = dk(X1,X2)/dX1dX2 (cell array with matrix elements). The derivative is calculated in multidimensional problem between input's observation dimensions which are not same. This subfunction is needed when using derivative observations.
| x1 | Configurations supplying the first covariance argument. |
| x2 | Configurations supplying the second covariance argument. |
| dims1 | Coordinate-dimension indices differentiated in x1. |
| dims2 | Coordinate-dimension indices differentiated in x2. |
| DKff | Output second-derivative covariance blocks. Optional precomputed D1/D2/D12 for ginput3. Its caller calculateGradOfCovMatrixWithDerivatives2 asks calculateDerivativesDiffDim for a superset of the same fields over the same inputs, and the direction argument that appears to distinguish the two calls is unread (Gradient.cpp), so the shared part is identical. Passing it in lets the pair be computed once. |
Definition at line 502 of file SexpatCF.h.
| gpr::SexpatCF::SexpatCF | ( | ) |
Definition at line 245 of file SexpatCF.cpp.
|
virtual |
Definition at line 250 of file SexpatCF.cpp.
|
inlinenoexcept |
Definition at line 638 of file SexpatCF.h.
|
nodiscard |
Apply a cross-block geometry directly to a vector.
When transpose_field is false, computes out = A(theta)^T * weights. When it is true, computes out = A(theta) * weights.
Definition at line 2003 of file SexpatCF.cpp.
|
nodiscard |
The configured base and optional additive heat component.
Definition at line 585 of file SexpatCF.cpp.
|
nodiscard |
Populate only the derivative fields (d1, d2, d12) of a CrossBlockGeometry, skipping the per-pairtype distance computation.
Companion to buildCrossBlockGeometry for callers that already hold a shared per-pairtype distance tensor across many blocks with identical atom positions (e.g. the SCG training-cov assembly, where each (block_n, block_m) (D+1)*N row slice contains the same coordinates with different derivative-dim tags by construction of assembleMatrixOfRepetitiveCoordinates). The shared distance must be applied at evaluate time via evaluateCrossBlockGeometryShared.
Definition at line 931 of file SexpatCF.cpp.
|
nodiscard |
Build theta-independent pairtype geometry for a covariance block.
The stored fields are raw pairtype contributions. They can be evaluated at any packed Sexpat log-parameter vector without re-walking atomic coordinates.
Definition at line 806 of file SexpatCF.cpp.
|
nodiscard |
Build the per-pairtype distance tensor at unit lengthscale for a single coordinate slice (shared across all training-cov blocks). The output convention matches CrossBlockGeometry.distance: shared_distance_neg_per_pt[pt] = -dist_at_vec(x_loc, x_loc, unit)[pt].
Definition at line 907 of file SexpatCF.cpp.
|
nodiscard |
Apply theta to a shared distance to produce the kernel value K(theta)[n, m] = exp(theta(0)) * exp(-0.5 * sum_pt exp(-2 theta(1+pt)).
Definition at line 1309 of file SexpatCF.cpp.
Pre-compute and cache inverse distances for the given positions.
Call once before an optimization loop. Subsequent covariance matrix evaluations will use the cached 1/r values, avoiding redundant coordinate extractions and norm computations.
Definition at line 2916 of file SexpatCF.cpp.
| void gpr::SexpatCF::calculateCovarianceMatrix | ( | const Coord & | x1, |
| Coord & | x2, | ||
| FieldMatrixd & | C ) |
Evaluate covariance matrix between two input vectors.
The function takes in covariance function of a Gaussian process GP and two matrixes TX and X that contain input vectors to GP. Returns covariance matrix C. Every element ij of C contains covariance between inputs i in TX and j in X. This is a mandatory subfunction used for example in prediction and energy computations.
| x1 | Input configurations supplying the rows of the covariance. |
| x2 | Input configurations supplying the columns of the covariance. |
| C | Output covariance matrix between x1 and x2. |
Definition at line 461 of file SexpatCF.cpp.
| void gpr::SexpatCF::calculateDirectionalCovarianceMatrix | ( | const Coord & | x1, |
| Coord & | x2, | ||
| const Eigen::VectorXd & | direction, | ||
| FieldMatrixd & | first, | ||
| FieldMatrixd & | second ) |
Evaluate the directional first and second derivatives of the covariance matrix along a parameter-space direction.
The direction is expressed in the packed log-parameter coordinates returned by combineParameters().
Definition at line 2392 of file SexpatCF.cpp.
|
nodiscard |
Directional first and second derivatives for the Kff block from shared training geometry.
Definition at line 1611 of file SexpatCF.cpp.
| void gpr::SexpatCF::calculateDirectionalCovarianceMatrixWithDerivatives | ( | const Coord & | x1, |
| Coord & | x2, | ||
| FieldMatrixIdx & | dims, | ||
| const Eigen::VectorXd & | direction, | ||
| FieldMatrixd & | first, | ||
| FieldMatrixd & | second ) |
Evaluate directional first and second derivatives of the derivative-vs-value covariance block.
Definition at line 2419 of file SexpatCF.cpp.
| void gpr::SexpatCF::calculateDirectionalCovarianceMatrixWithDerivatives2 | ( | const Coord & | x1, |
| Coord & | x2, | ||
| FieldMatrixIdx & | dims1, | ||
| FieldMatrixIdx & | dims2, | ||
| const Eigen::VectorXd & | direction, | ||
| FieldMatrixd & | first, | ||
| FieldMatrixd & | second ) |
Evaluate directional first and second derivatives of the derivative-vs-derivative covariance block.
Definition at line 2470 of file SexpatCF.cpp.
|
nodiscard |
Directional first and second derivatives for a D/Kdf2 block from shared training geometry.
Definition at line 1678 of file SexpatCF.cpp.
|
nodiscard |
Directional first and second derivatives for a Kdf block from shared training geometry.
Definition at line 1636 of file SexpatCF.cpp.
| double gpr::SexpatCF::calculateDirectionalLogPriorCurvature | ( | const Eigen::VectorXd & | direction | ) | const |
Evaluate the second directional derivative of log p(theta) along the packed log-parameter direction.
Definition at line 2549 of file SexpatCF.cpp.
| void gpr::SexpatCF::calculateGradOfCovMatrix | ( | const Coord & | x1, |
| Coord & | x2, | ||
| std::vector< FieldMatrixd > & | DKff ) |
Evaluate gradient of covariance function with respect to the parameters.
The function takes a covariance function structure GPCF, a matrix X of input vectors and returns DKff, the gradients of covariance matrix Kff = k(X,X) with respect to th (cell array with matrix elements). This is a mandatory subfunction used for example in gradient computations.
| x1 | Input configurations for the first covariance argument. |
| x2 | Input configurations for the second covariance argument. |
| DKff | Output covariance-matrix gradients with respect to the covariance hyperparameters. |
Definition at line 2110 of file SexpatCF.cpp.
|
nodiscard |
Geometry-path replacement for calculateGradOfCovMatrix. Produces DKff[0] = K (untruncated kernel), DKff[1+pt] = K * inv_l_pt^2 * shared_distance_neg[pt] (== -K * dist_pt_actual in the legacy negated sign convention). Scalar-length case collapses to a single DKff[1] entry that sums across pairtypes. An optional nonempty parameter list selects output blocks in the given order. All parameters still contribute to the kernel and its Cartesian derivatives; only the requested hyperparameter derivatives are formed.
Definition at line 1437 of file SexpatCF.cpp.
| void gpr::SexpatCF::calculateGradOfCovMatrixWithDerivatives | ( | const Coord & | x1, |
| Coord & | x2, | ||
| FieldMatrixIdx & | dims, | ||
| std::vector< FieldMatrixd > & | DKff ) |
Evaluate gradient of covariance function, of which has been taken partial derivative with respect to x1, with respect to parameters.
The function takes a covariance function structure GPCF, a matrix X of input vectors and returns DKff, the gradients of derivatived covariance matrix dK(df,f)/dhyp = d(d k(X,X)/dx)/dhyp, with respect to the parameters.
Evaluate: DKff{1:m} = d Kff / d magnSigma2 DKff{m+1:2m} = d Kff / d lengthScale_m m is the dimension of inputs. If ARD is used, then multiple lengthScales. This subfunction is needed when using derivative observations.
dims - is a vector of input dimensions with respect to which the
derivatives of the covariance function have been calculated
[by default dims=1:size(x,2)]
Note! When coding the derivatives of the covariance function, remember to double check them. See gp_cov for lines of code to check the matrices
| x1 | Configurations supplying the first covariance argument. |
| x2 | Configurations supplying the second covariance argument. |
| dims | Coordinate-dimension indices of the derivative observations. |
| DKff | Output covariance-derivative blocks for each hyperparameter. |
Definition at line 2185 of file SexpatCF.cpp.
| void gpr::SexpatCF::calculateGradOfCovMatrixWithDerivatives2 | ( | const Coord & | x1, |
| Coord & | x2, | ||
| FieldMatrixIdx & | dims1, | ||
| FieldMatrixIdx & | dims2, | ||
| std::vector< FieldMatrixd > & | DKff ) |
Evaluate gradient of covariance function, of which has been taken partial derivatives with respect to both input variables x1 and x2 with respect to parameters.
The function takes a covariance function structure GPCF, a matrix X of input vectors and returns DKff, the gradients of derivative covariance matrix dK(df,df)/dhyp = d(d^2 k(X1,X2)/dX1dX2)/dhyp with respect to the parameters.
Evaluate: DKff{1-m} = d Kff / d magnSigma2 DKff{m+1-2m} = d Kff / d lengthScale_m m is the dimension of inputs. If ARD is used, then multiple lengthScales. This subfunction is needed when using derivative observations.
| x1 | Configurations supplying the first covariance argument. |
| x2 | Configurations supplying the second covariance argument. |
| dims1 | Coordinate-dimension indices differentiated in x1. |
| dims2 | Coordinate-dimension indices differentiated in x2. |
| DKff | Output second-derivative covariance blocks for each hyperparameter. |
Definition at line 2286 of file SexpatCF.cpp.
|
nodiscard |
Geometry-path replacement for calculateGradOfCovMatrixWithDerivatives2 (D and Kdf2 blocks).
Same shape as the original: DKff[0] is the block value at theta (== evaluateCrossBlockGeometryWithSharedKernel options=D1|D2|D12), DKff[1+pt] is the derivative wrt loglength_pt.
Definition at line 1853 of file SexpatCF.cpp.
|
nodiscard |
Geometry-path replacement for calculateGradOfCovMatrixWithDerivatives (Kdf block dK).
The Kdf block geometry (built once at unit lengthscale and stored in geometry with derivative_options=D1) gives the per-pairtype d1 fields. DKff[0] = Kdf(theta) (== evaluateCrossBlockGeometryWithSharedKernel with options=D1). DKff[1+pt] is dKdf/dloglength_pt; the algebra matches the live calculateGradOfCovMatrixWithDerivatives (DK_pt[pt] = magnSigma2 * exp * (-D1_pt[pt] + 0.5 * D1[n] * dist_pt[pt])) with D1_pt being the per-pairtype gradient at unit lengthscale and D1 being the lengthscale-weighted sum across pairtypes.
Definition at line 1744 of file SexpatCF.cpp.
| double gpr::SexpatCF::calculateLogPrior | ( | ) |
Evaluate the log prior density of the parameters.
This function takes a covariance function structure GPCF and returns log(p(th)), where th collects the parameters. This is a mandatory subfunction used for example in energy computations.
Evaluate the prior contribution to the error. The parameters that are sampled are transformed, e.g., W = log(w) where w is all the "real" samples. On the other hand errors are evaluated in the W-space so we need take into account also the Jacobian of transformation, e.g., W -> w = exp(W). See Gelman et al. (2013), Bayesian Data Analysis, third edition, p. 21.
Definition at line 255 of file SexpatCF.cpp.
| FieldMatrixd gpr::SexpatCF::calculateLogPriorGradient | ( | ) |
Evaluate the gradient of the log prior density of the parameters with respect to parameters.
This function takes a covariance function structure GPCF and returns LPG = d log (p(th))/dth, where th is the vector of parameters. This is a mandatory subfunction used in gradient computations.
Definition at line 370 of file SexpatCF.cpp.
| void gpr::SexpatCF::calculateTrainingCovarianceMatrix | ( | const Coord & | x, |
| FieldMatrixd & | C ) |
Evaluate the prior variance for each training input.
Function takes in covariance function of a Gaussian process GPCF and matrix TX that contains training inputs. Returns variance vector C. Every element i of C contains variance of input i in TX. This is a mandatory subfunction used for example in prediction and energy computations.
| x | Input configurations whose prior variances are evaluated. |
| C | Output column vector of prior variances, one per configuration. |
Definition at line 786 of file SexpatCF.cpp.
|
inline |
Definition at line 68 of file SexpatCF.inl.
| void gpr::SexpatCF::clearDistanceCache | ( | ) |
Invalidate the distance cache.
Call when positions change (e.g. after optimization completes and new observations are added).
Definition at line 2963 of file SexpatCF.cpp.
|
noexcept |
Definition at line 723 of file SexpatCF.cpp.
|
inline |
Disable the hierarchical prior set via ~setHierarchicalPrior~. Restores the global-GP zero-prior branch.
Definition at line 152 of file SexpatCF.inl.
| void gpr::SexpatCF::clearManifoldChart | ( | ) |
Definition at line 513 of file SexpatCF.cpp.
|
inline |
Definition at line 167 of file SexpatCF.inl.
|
inline |
Combine parameters of the covariance function into one Eigen vector.
Definition at line 173 of file SexpatCF.inl.
| void gpr::SexpatCF::correlationDistances | ( | const Coord & | left, |
| const Coord & | right, | ||
| const AtomsConfiguration & | configuration, | ||
| FieldMatrixd & | distances ) const |
Dimensionless support scores from the selected prediction covariance. A score of one corresponds to normalized energy covariance exp(-1/2). Nonpositive composed covariance gives an infinite score.
Definition at line 2921 of file SexpatCF.cpp.
|
nodiscard |
Evaluate a cross-block geometry at packed Sexpat log parameters.
Definition at line 1018 of file SexpatCF.cpp.
|
nodiscard |
Same as evaluateCrossBlockGeometry but reads the per-pairtype distance from an externally-shared tensor (negated, matching the sign convention of buildCrossBlockGeometry). The supplied geometry's .distance field is ignored; .d1, .d2, .d12 are still consulted.
Used together with buildCrossBlockDerivativesOnly to skip 946-fold redundant dist_at_vec calls in the SCG training-cov assembly when all (block_n, block_m) blocks share the same atom positions.
Definition at line 1148 of file SexpatCF.cpp.
|
nodiscard |
Evaluate a derivative-only block against a pre-computed shared kernel matrix (from buildSharedKernel). No exp() per call.
Definition at line 1345 of file SexpatCF.cpp.
|
inlinenodiscard |
Definition at line 605 of file SexpatCF.h.
|
inlinenodiscardnoexcept |
Definition at line 668 of file SexpatCF.h.
|
nodiscard |
Definition at line 729 of file SexpatCF.cpp.
|
nodiscard |
Definition at line 740 of file SexpatCF.cpp.
|
inlinenodiscardnoexcept |
Definition at line 657 of file SexpatCF.h.
|
inlinenodiscardnoexcept |
Definition at line 705 of file SexpatCF.h.
|
inlinenodiscardnoexcept |
Pair-type metric retained independently of the chart's fitted length.
Definition at line 700 of file SexpatCF.h.
|
inlinenodiscardnoexcept |
Definition at line 678 of file SexpatCF.h.
|
inline |
Definition at line 58 of file SexpatCF.inl.
|
inline |
Definition at line 63 of file SexpatCF.inl.
|
inline |
Definition at line 53 of file SexpatCF.inl.
|
inline |
Definition at line 692 of file SexpatCF.h.
|
inlinenodiscardnoexcept |
Definition at line 739 of file SexpatCF.h.
|
inline |
Definition at line 93 of file SexpatCF.inl.
|
inline |
Definition at line 103 of file SexpatCF.inl.
|
inline |
Definition at line 98 of file SexpatCF.inl.
| void gpr::SexpatCF::ginput2 | ( | const Coord & | x1, |
| Coord & | x2, | ||
| FieldMatrixIdx & | dims, | ||
| std::vector< FieldMatrixd > & | DKff, | ||
| ExpDistArray * | out_expdist = nullptr ) |
Definition at line 2650 of file SexpatCF.cpp.
| void gpr::SexpatCF::ginput3 | ( | const Coord & | x1, |
| Coord & | x2, | ||
| FieldMatrixIdx & | dims1, | ||
| FieldMatrixIdx & | dims2, | ||
| std::vector< FieldMatrixd > & | DKff, | ||
| ExpDistArray * | out_expdist = nullptr, | ||
| const SharedDerivatives * | precomputed = nullptr ) |
Definition at line 2722 of file SexpatCF.cpp.
| void gpr::SexpatCF::ginput4 | ( | const Coord & | x1, |
| Coord & | x2, | ||
| FieldMatrixIdx & | dims, | ||
| std::vector< FieldMatrixd > & | DKff, | ||
| ExpDistArray * | out_expdist = nullptr ) |
Evaluate gradient of covariance function with respect to x.
Simplified and faster version of sexp_ginput, returns full matrices.
Returns DKff, the gradients of covariance matrix Kff = k(X,X2) with respect to dimensions DIMS of X.
| x1 | Configurations supplying the first covariance argument. |
| x2 | Configurations supplying the second covariance argument. |
| dims | Coordinate-dimension indices differentiated in x1. |
| DKff | Output covariance-derivative blocks. |
| out_expdist | Optional output array of the shared exponential distance factors. |
Definition at line 2804 of file SexpatCF.cpp.
|
inline |
Definition at line 897 of file SexpatCF.h.
|
inlinenodiscard |
Definition at line 818 of file SexpatCF.h.
|
inlinenodiscardnoexcept |
Definition at line 822 of file SexpatCF.h.
|
inlinenodiscardnoexcept |
Definition at line 89 of file SexpatCF.h.
|
inlinenodiscardnoexcept |
Definition at line 792 of file SexpatCF.h.
|
inlinenodiscardnoexcept |
Definition at line 780 of file SexpatCF.h.
|
inlinenodiscardnoexcept |
Variance of packed parameter ~n~ under the hierarchical prior.
Definition at line 799 of file SexpatCF.h.
|
inlinenodiscardnoexcept |
Definition at line 767 of file SexpatCF.h.
|
inlinenodiscardnoexcept |
Definition at line 622 of file SexpatCF.h.
|
inlinenodiscardnoexcept |
Definition at line 626 of file SexpatCF.h.
|
inlinenodiscardnoexcept |
Definition at line 643 of file SexpatCF.h.
|
nodiscard |
Definition at line 751 of file SexpatCF.cpp.
|
nodiscard |
Definition at line 768 of file SexpatCF.cpp.
|
nodiscard |
Definition at line 609 of file SexpatCF.cpp.
| void gpr::SexpatCF::predictMeanAlphaK | ( | const Coord & | x_train, |
| const Coord & | x_test, | ||
| const Eigen::Ref< const Eigen::VectorXd > & | alpha_E, | ||
| const Eigen::Ref< const Eigen::VectorXd > & | alpha_G_flat, | ||
| Eigen::Ref< Eigen::VectorXd > | mu_E_out, | ||
| Eigen::Ref< Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > > | mu_G_out ) |
Per-test-point predict mean (energy + gradient) via the Schmitz/Chmiela JPCL 2022 eq.6 alpha-K early contraction applied at the per-pair level.
For each test point m, accumulates into mu_E_out[m] and mu_G_out(m, beta) the SexpAt contribution to predict mean:
mu_E[m] += Sum_i alpha_E[i] * k(x_i, x_m)
Cost: O(num_train * n_pairs) per test point instead of the O(num_train * num_test * D^2) of the legacy per-(d1, d2) loop.
alpha_G_flat layout matches the existing accumulator's weights vector: alpha_G_flat[d * num_train + i] is the gradient alpha for training point i, atomic-coord dim d (1-based d, i.e. uDdim[k] for k in 0..D-1; entries at d=0 are alpha_E and live separately in alpha_E).
Outputs are ACCUMULATED in place (callers zero them first). RowMajor mu_G_out keeps the layout consistent with image1.G in calculatePotential.
Math notes:
Definition at line 2872 of file SexpatCF.cpp.
| void gpr::SexpatCF::predictMeanAlphaKPrepared | ( | const PreparedAlphaK & | prepared, |
| const Coord & | x_test, | ||
| Eigen::Ref< Eigen::VectorXd > | mu_E_out, | ||
| Eigen::Ref< Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > > | mu_G_out ) const |
Definition at line 2894 of file SexpatCF.cpp.
|
nodiscard |
Definition at line 2885 of file SexpatCF.cpp.
|
inlinenodiscard |
Definition at line 842 of file SexpatCF.h.
| void gpr::SexpatCF::rescaleGeodesicHeatCovariance | ( | double | factor | ) |
Convert the additive component to a different output variance unit.
Definition at line 710 of file SexpatCF.cpp.
|
inlinenoexcept |
Definition at line 634 of file SexpatCF.h.
|
inline |
Definition at line 851 of file SexpatCF.h.
|
inline |
Definition at line 38 of file SexpatCF.inl.
|
inline |
Frozen atoms at or beyond radius use the dipole tensor. Zero keeps the exact inverse-distance pairs.
Definition at line 32 of file SexpatCF.inl.
| void gpr::SexpatCF::setGeodesicHeatKernel | ( | std::shared_ptr< const GeodesicHeatEnergyForceKernel > | kernel | ) |
Attach an immutable heat component with its own reference and metric.
Definition at line 519 of file SexpatCF.cpp.
| void gpr::SexpatCF::setGeodesicHeatReferencePath | ( | const Coord & | reference_path, |
| double | covariance_weight ) |
Attach a geodesic heat summand to the selected pair or chart base. A zero covariance weight disables it.
Definition at line 530 of file SexpatCF.cpp.
|
inlinenoexcept |
Definition at line 85 of file SexpatCF.h.
|
inline |
Length scales (index into the length-scale block) the population prior anchors: under the classic joint energy/force prior of the gprd profiles these take the per-type log-Gaussian in place of the classic term; the others keep the classic term.
Definition at line 788 of file SexpatCF.h.
|
inline |
Definition at line 129 of file SexpatCF.inl.
|
inline |
The same prior with a variance per packed parameter (the shared ~s2_log~ where an entry is not positive): the population prior of a pair type sets its own width.
Definition at line 138 of file SexpatCF.inl.
|
inline |
Definition at line 24 of file SexpatCF.inl.
|
inline |
Enable a hierarchical-Bayes Gaussian prior on the log-space kernel parameters: ~log(theta_i) ~ N(mu_log, s2_log * I)~ where ~mu_log~ is the packed log-parameter target (~[log(magnSigma2), log(lengthScale[0]), ..., log(lengthScale[K-1])]~, same layout as ~combineParameters()~) and ~s2_log~ is the shared variance. When enabled, ~calculateLogPrior~ / ~calculateLogPriorGradient~ use this hierarchical density instead of the global-GP zero-prior branch. The density operates in log-space directly, so no linear-to-log Jacobian terms are added (the SCG optimiser already runs on the packed log-parameters returned by ~combineParameters~).
Per-image GP fits use ~mu_log = theta_global~ from the session GP's MAP and a shared ~s2_log = tau^2~ regulariser that pulls per-image ~theta_i~ back toward the global MAP when the per-image data set is small. Per-length-scale weights of the prior terms; empty restores one prior per length scale.
Definition at line 763 of file SexpatCF.h.
|
inline |
Definition at line 19 of file SexpatCF.inl.
| void gpr::SexpatCF::setManifoldChart | ( | std::shared_ptr< const geometry::InternalCoordinateChart > | chart, |
| double | length_scale ) |
Attach a chart so assembly can wrap this primitive as Pullback(SE, chart). Sexpat itself stays the inverse-distance kernel.
Definition at line 495 of file SexpatCF.cpp.
|
inline |
Definition at line 118 of file SexpatCF.inl.
|
inline |
Set parameters of this covariance function using the provided vector.
| w | Vector of combined parameters from covariance functions and likelyhood |
Definition at line 44 of file SexpatCF.inl.
|
inline |
Penalized-Complexity length-scale prior for the global GP. lambda is the per-pairtype PC rate (lambda_k = -rho0_k * ln(alpha)); element k applies to lengthScale[k]. magnSigma2 is left unpenalised.
Definition at line 161 of file SexpatCF.inl.
|
inline |
Definition at line 78 of file SexpatCF.inl.
|
inline |
Parameters of the optional log-normal prior on magnSigma2. Inactive until setUseLogNormalMagnPrior(true).
Definition at line 88 of file SexpatCF.inl.
|
inline |
Definition at line 83 of file SexpatCF.inl.
|
inlinenoexcept |
Opt-in log-normal prior on the positive signal variance magnSigma2. Off (the default) keeps the half-Student-t magnitude prior on classic profiles and the half-Cauchy magnitude prior in the MAP objective.
Definition at line 108 of file SexpatCF.inl.
|
inlinenoexcept |
Definition at line 93 of file SexpatCF.h.
| void gpr::SexpatCF::trainingGradientAlphaK | ( | const Coord & | x_train, |
| const Eigen::Ref< const Eigen::VectorXd > & | alpha_E, | ||
| const Eigen::Ref< const Eigen::VectorXd > & | alpha_G_flat, | ||
| Eigen::Ref< Eigen::VectorXd > | quad_out, | ||
| bool | distributed = false, | ||
| std::size_t * | local_pair_count = nullptr, | ||
| const linalg::MpiContext * | process_group = nullptr ) |
Accumulate joint energy/force quadratic derivatives. Distributed execution is collective; local calls do not enter MPI. The optional count reports the unique training pairs evaluated by this rank.
Definition at line 2905 of file SexpatCF.cpp.
|
inlinenodiscardnoexcept |
Definition at line 113 of file SexpatCF.inl.
|
inlinenodiscardnoexcept |
Definition at line 98 of file SexpatCF.h.
|
inlinenodiscardnoexcept |
Definition at line 664 of file SexpatCF.h.
|
inlinenodiscardnoexcept |
Definition at line 616 of file SexpatCF.h.
|
friend |
Definition at line 75 of file SexpatCF.h.