87 hessian_precision_ = precision;
91 return hessian_precision_;
96 enabled ? HessianPrecision::LongDouble : HessianPrecision::Double;
100 return hessian_precision_ == HessianPrecision::LongDouble;
104 const Eigen::VectorXd& weights,
105 const Eigen::VectorXd& position,
106 const Eigen::VectorXd& direction,
107 Eigen::VectorXd& action)
const;
184 std::vector<FieldMatrixd>& DKff);
216 std::vector<FieldMatrixd>& DKff);
253 const Eigen::VectorXd& direction,
279 std::vector<FieldMatrixd>
d1;
280 std::vector<FieldMatrixd>
d2;
281 std::vector<FieldMatrixd>
d12;
293 const Coord& x1,
const Coord& x2, uint8_t derivative_options,
310 const Coord& x1,
const Coord& x2, uint8_t derivative_options,
322 std::vector<FieldMatrixd>& shared_distance_neg_per_pt)
const;
343 const std::vector<FieldMatrixd>& shared_distance_neg_per_pt,
353 const std::vector<FieldMatrixd>& shared_distance_neg_per_pt,
354 const Eigen::VectorXd& theta,
FieldMatrixd& kernel_out)
const;
370 const std::vector<FieldMatrixd>& shared_distance_neg_per_pt,
371 const Eigen::VectorXd& theta,
const Eigen::VectorXd& direction,
381 const std::vector<FieldMatrixd>& shared_distance_neg_per_pt,
382 const Eigen::VectorXd& theta,
const Eigen::VectorXd& direction,
392 const std::vector<FieldMatrixd>& shared_distance_neg_per_pt,
393 const Eigen::VectorXd& theta,
const Eigen::VectorXd& direction,
408 const std::vector<FieldMatrixd>& shared_distance_neg_per_pt,
409 const Eigen::VectorXd& theta, std::vector<FieldMatrixd>& DKff,
410 const std::vector<Eigen::Index>* parameter_indices =
nullptr)
const;
428 const std::vector<FieldMatrixd>& shared_distance_neg_per_pt,
429 const Eigen::VectorXd& theta, std::vector<FieldMatrixd>& DKff,
430 const std::vector<Eigen::Index>* parameter_indices =
nullptr)
const;
442 const std::vector<FieldMatrixd>& shared_distance_neg_per_pt,
443 const Eigen::VectorXd& theta, std::vector<FieldMatrixd>& DKff,
444 const std::vector<Eigen::Index>* parameter_indices =
nullptr)
const;
455 const Eigen::VectorXd& weights,
bool transpose_field,
456 Eigen::VectorXd&
out)
const;
473 Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
476 std::vector<FieldMatrixd>& DKff,
526 std::vector<FieldMatrixd>& DKff,
569 const Eigen::Ref<const Eigen::VectorXd>& alpha_E,
570 const Eigen::Ref<const Eigen::VectorXd>& alpha_G_flat,
571 Eigen::Ref<Eigen::VectorXd> mu_E_out,
572 Eigen::Ref<Eigen::Matrix<
double, Eigen::Dynamic, Eigen::Dynamic,
577 const Coord& x_train,
const Eigen::Ref<const Eigen::VectorXd>& alpha_E,
578 const Eigen::Ref<const Eigen::VectorXd>& alpha_G_flat,
583 Eigen::Ref<Eigen::VectorXd> mu_E_out,
584 Eigen::Ref<Eigen::Matrix<
double, Eigen::Dynamic, Eigen::Dynamic,
592 const Coord& x_train,
const Eigen::Ref<const Eigen::VectorXd>& alpha_E,
593 const Eigen::Ref<const Eigen::VectorXd>& alpha_G_flat,
594 Eigen::Ref<Eigen::VectorXd> quad_out,
bool distributed =
false,
595 std::size_t* local_pair_count =
nullptr,
607 return far_field_radius_;
613 std::shared_ptr<const geometry::InternalCoordinateChart> chart,
614 double length_scale);
618 return static_cast<bool>(manifold_chart_);
620 [[nodiscard]]
const std::shared_ptr<
624 return manifold_chart_;
628 return manifold_chart_ ? manifold_chart_->anchor().size() : 0;
631 const Coord& positions)
const;
633 const Coord& left_positions,
const Coord& right_positions)
const;
636 manifold_geometry_rows_evaluated_for_testing_ = 0;
639 Eigen::Index left_rows, Eigen::Index right_rows)
const noexcept
641 noteManifoldGeometryRows(left_rows, right_rows);
646 return manifold_geometry_rows_evaluated_for_testing_;
652 double covariance_weight);
655 std::shared_ptr<const GeodesicHeatEnergyForceKernel> kernel);
656 [[nodiscard]]
const std::shared_ptr<const GeodesicHeatEnergyForceKernel>&
659 return geodesic_heat_kernel_;
666 return static_cast<bool>(geodesic_heat_kernel_);
670 return geodesic_heat_kernel_ ? geodesic_heat_kernel_->dimensions() : 0;
673 const Coord& positions)
const;
675 const Coord& left_positions,
const Coord& right_positions)
const;
741 return model_profile_;
765 length_prior_weight_ = weights;
770 return length_prior_weight_;
779 const Eigen::VectorXd& s2_log_per);
782 return hierarchical_mu_log_;
790 hierarchical_anchor_ = std::move(mask);
795 n < static_cast<Eigen::Index>(hierarchical_anchor_.size()) &&
796 hierarchical_anchor_[
static_cast<std::size_t
>(n)] != 0;
800 Eigen::Index n)
const noexcept
802 if (n >= 0 && n < hierarchical_s2_log_per_.size() &&
803 hierarchical_s2_log_per_(n) > 0.0)
804 return hierarchical_s2_log_per_(n);
805 return hierarchical_s2_log_;
820 return use_hierarchical_prior_;
824 return use_pc_lengthscale_prior_;
844 return {prior_parameters_gaussian, prior_parameters_sqrtt,
845 prior_parameters_lognormal, use_lognormal_magn_prior_,
846 use_hierarchical_prior_, length_prior_weight_,
847 hierarchical_mu_log_, hierarchical_s2_log_,
848 hierarchical_s2_log_per_, hierarchical_anchor_,
849 use_pc_lengthscale_prior_, pc_lambda_};
853 prior_parameters_gaussian.setParameters(state.
gaussian);
854 prior_parameters_sqrtt.setParameters(state.
sqrtt);
855 prior_parameters_lognormal.setParameters(state.
lognormal);
878 const Eigen::VectorXd& direction)
const;
899 return dist_calculator_.hasCachedDistances();
904 const Coord& left,
const Coord& right, Eigen::Index left_channel,
905 Eigen::Index right_channel,
907 void chartDirectionalBlocks(
const Coord& left,
const Coord& right,
908 Eigen::Index left_channel,
909 Eigen::Index right_channel,
910 const Eigen::VectorXd& direction,
913 void noteManifoldGeometryRows(Eigen::Index left_rows,
914 Eigen::Index right_rows)
const noexcept;
915 [[nodiscard]]
FieldMatrixd inverseDistanceCovarianceBlock(
916 const Eigen::MatrixXd& left_positions,
917 const Eigen::MatrixXd& right_positions, Eigen::Index left_channel,
918 Eigen::Index right_channel)
const;
923 double far_field_radius_ = 0.0;
928 std::shared_ptr<const geometry::InternalCoordinateChart> manifold_chart_;
929 std::shared_ptr<const GeodesicHeatEnergyForceKernel> geodesic_heat_kernel_;
930 mutable std::size_t manifold_geometry_rows_evaluated_for_testing_ = 0;
931 mutable bool compose_operators_ =
true;
937 bool use_lognormal_magn_prior_ =
false;
943 bool use_hierarchical_prior_ =
false;
946 Eigen::VectorXd length_prior_weight_;
947 [[nodiscard]]
double lengthPriorWeight(Eigen::Index n)
const noexcept
949 return n >= 0 && n < length_prior_weight_.size()
950 ? length_prior_weight_(n)
953 Eigen::VectorXd hierarchical_mu_log_;
954 double hierarchical_s2_log_ = 0.0;
955 Eigen::VectorXd hierarchical_s2_log_per_;
956 std::vector<char> hierarchical_anchor_;
966 bool use_pc_lengthscale_prior_ =
false;
967 Eigen::VectorXd pc_lambda_;
Tiny value type describing the MPI dispatch context for a probe loop.
Methods to calculate distances between atoms.
Class of prior parameters.
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),...
FieldMatrixd & getAtomisticLengthScaleRef() noexcept
Pair-type metric retained independently of the chart's fitted length.
void setParameters(const Eigen::VectorXd &w)
Set parameters of this covariance function using the provided vector.
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
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 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.
double farFieldRadius() const
Sexpat::AlphaKPairInfo AlphaKPairInfo
Sexpat::HessianPrecision HessianPrecision
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.
const Eigen::VectorXd & lengthScalePriorWeights() const noexcept
FieldMatrixd manifoldJointEnergyGradientCovariance(const Coord &positions) const
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).
void addManifoldGeometryRowsEvaluatedForTesting(Eigen::Index left_rows, Eigen::Index right_rows) const noexcept
PriorBase getPriorParametersSqrtt()
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-spac...
void setUseLogNormalMagnPrior(bool enabled) noexcept
void setFarFieldRadius(double radius)
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 tens...
void setPcLengthScalePrior(const Eigen::VectorXd &lambda)
void ginput2(const Coord &x1, Coord &x2, FieldMatrixIdx &dims, std::vector< FieldMatrixd > &DKff, ExpDistArray *out_expdist=nullptr)
double getMagnSigma2() const
void clearGeodesicHeatKernel() noexcept
double calculateDirectionalLogPriorCurvature(const Eigen::VectorXd &direction) const
Evaluate the second directional derivative of log p(theta) along the packed log-parameter direction.
const AtomsConfiguration & getConfInfo() const noexcept
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.
void setGeodesicHeatKernel(std::shared_ptr< const GeodesicHeatEnergyForceKernel > kernel)
Attach an immutable heat component with its own reference and metric.
void calculateGradOfCovMatrix(const Coord &x1, Coord &x2, std::vector< FieldMatrixd > &DKff)
Evaluate gradient of covariance function with respect to the parameters.
double hierarchicalPriorVariance(Eigen::Index n) const noexcept
Variance of packed parameter ~n~ under the hierarchical prior.
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 acro...
void setModelProfile(GPModelProfile profile)
const FieldMatrixd & getAtomisticLengthScaleRef() const noexcept
void cacheDistances(const Coord &x1, const Coord &x2)
Pre-compute and cache inverse distances for the given positions.
void correlationDistances(const Coord &left, const Coord &right, const AtomsConfiguration &configuration, FieldMatrixd &distances) const
void setLengthScale(double value)
const std::shared_ptr< const geometry::InternalCoordinateChart > & manifoldChart() const noexcept
FieldMatrixd calculateLogPriorGradient()
Evaluate the gradient of the log prior density of the parameters with respect to parameters.
PriorState priorState() const
Eigen::VectorXd combineParameters()
Combine parameters of the covariance function into one Eigen vector.
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 calculateTrainingCovarianceMatrix(const Coord &x, FieldMatrixd &C)
Evaluate the prior variance for each training input.
GPModelProfile getModelProfile() const noexcept
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.
std::size_t manifoldGeometryRowsEvaluatedForTesting() const noexcept
void setPriorParametersSqrtt(const PriorBase &prior)
std::shared_ptr< const KernelOperator > assembledOperator() const
The configured base and optional additive heat component.
Sexpat::PreparedAlphaK PreparedAlphaK
PriorBase getPriorParametersGaussian()
bool usesManifoldChart() const noexcept
Eigen::Index manifoldDimensions() const noexcept
bool hasHierarchicalPrior() const
FieldMatrixd geodesicHeatJointEnergyGradientCovariance(const Coord &positions) const
void clearHierarchicalPrior()
bool meanHessianVector(const Coord &training, const Eigen::VectorXd &weights, const Eigen::VectorXd &position, const Eigen::VectorXd &direction, Eigen::VectorXd &action) const
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....
void setHierarchicalPrior(const Eigen::VectorXd &mu_log, double s2_log)
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 clearPcLengthScalePrior()
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 setMagnSigma2(double value)
FieldMatrixd manifoldJointEnergyGradientCrossCovariance(const Coord &left_positions, const Coord &right_positions) const
void setUseLongDoubleHessian(bool enabled) noexcept
void setLengthScalePriorWeights(const Eigen::VectorXd &weights)
void setPriorParametersGaussian(const PriorBase &prior)
void setPriorParametersLogNormal(const PriorBase &prior)
void setHierarchicalAnchorMask(std::vector< char > mask)
Derivatives< std::vector< FieldMatrixd > > SharedDerivatives
Evaluate gradient of covariance function with respect to both input variables x1 and x2 (in different...
void calculateCovarianceMatrix(const Coord &x1, Coord &x2, FieldMatrixd &C)
Evaluate covariance matrix between two input vectors.
HessianPrecision hessianPrecision() const noexcept
const std::shared_ptr< const GeodesicHeatEnergyForceKernel > & geodesicHeatKernel() const noexcept
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)...
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 ...
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...
void ginput3(const Coord &x1, Coord &x2, FieldMatrixIdx &dims1, FieldMatrixIdx &dims2, std::vector< FieldMatrixd > &DKff, ExpDistArray *out_expdist=nullptr, const SharedDerivatives *precomputed=nullptr)
void rescaleGeodesicHeatCovariance(double factor)
Convert the additive component to a different output variance unit.
void clearManifoldChart()
PriorBase getPriorParametersLogNormal()
FieldMatrixd geodesicHeatJointEnergyGradientCrossCovariance(const Coord &left_positions, const Coord &right_positions) const
FieldMatrixd & getLengthScaleRef()
void setManifoldChart(std::shared_ptr< const geometry::InternalCoordinateChart > chart, double length_scale)
bool useLogNormalMagnPrior() const noexcept
void restorePriorState(PriorState state)
bool useLongDoubleHessian() const noexcept
const Eigen::VectorXd & hierarchicalPriorMu() const noexcept
bool evaluateCrossBlockGeometry(const CrossBlockGeometry &geometry, const Eigen::VectorXd &theta, FieldMatrixd &out) const
Evaluate a cross-block geometry at packed Sexpat log parameters.
bool usesGeodesicHeatKernel() const noexcept
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.
void setConfInfo(const AtomsConfiguration &value)
bool hierarchicalAnchored(Eigen::Index n) const noexcept
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 ...
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.
bool hasPcLengthScalePrior() const noexcept
double calculateLogPrior()
Evaluate the log prior density of the parameters.
void setHessianPrecision(HessianPrecision precision) noexcept
Eigen::Array< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > ExpDistArray
Calculates covariances between the derivatives.
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....
void resetManifoldGeometryRowsEvaluatedForTesting() const noexcept
void setGeodesicHeatReferencePath(const Coord &reference_path, double covariance_weight)
void clearDistanceCache()
Invalidate the distance cache.
Eigen::Index geodesicHeatDimensions() const noexcept
bool hasDistanceCache() const
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
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Eigen::Matrix< Index_t, EigenDynamic, EigenDynamic, FieldMatrixStorage > FieldMatrixIdx
bool sexpat_local_oracle_active
Eigen::Matrix< double, EigenDynamic, EigenDynamic, FieldMatrixStorage > FieldMatrixd
Stores configurations of all atoms in the system.
Structure of directional derivatives.
std::vector< FieldMatrixd > d2
std::vector< FieldMatrixd > d12
std::vector< FieldMatrixd > distance
uint8_t derivative_options
std::vector< FieldMatrixd > d1
Every prior the kernel places on its magnitude and length scales.
Eigen::VectorXd length_prior_weight
Eigen::VectorXd hierarchical_mu_log
Eigen::VectorXd hierarchical_s2_log_per
std::vector< char > hierarchical_anchor
Eigen::VectorXd pc_lambda
double hierarchical_s2_log
~SexpatLocalOracleScope() noexcept
SexpatLocalOracleScope(const SexpatLocalOracleScope &)=delete
SexpatLocalOracleScope & operator=(const SexpatLocalOracleScope &)=delete
SexpatLocalOracleScope() noexcept