namespace gpr::optim¶
Overview¶
namespace optim {
// typedefs
typedef std::function<std::pair<double, Eigen::VectorXd>(const Eigen::VectorXd&positions)> OracleFn;
// enums
enum RefinedCurvatureSign;
enum RigidMotionMetric;
enum SaddleSearchFamily;
enum SecantAccounting;
enum SecantHessianMethod;
enum SecantSeedStatus;
enum SecantSeedSupport;
enum StencilAction;
enum VibrationalStencil;
// structs
struct CompletedSecondMode;
struct EndpointConnectivityReport;
struct EndpointSpectrum;
struct ForceStopCertificateResult;
struct ForceStopMeasurement;
struct ForceStopStencilPlan;
struct ForceStopStencilQuery;
struct FragmentRotations;
struct IrcCertificateRecord;
struct KnownOracleRow;
struct MeasuredCurvatureSpectrum;
struct MeasuredDirectionalCubic;
struct MeasuredHessianColumn;
struct MeasuredIndexDecision;
struct MinimizationConfig;
struct MinimizationLayoutStamp;
struct MinimizationResult;
struct MinimumSpectrumCache;
struct NegativePairRejection;
struct NegativeRitzPairRefinement;
struct PairRitzProbe;
struct RefinedCurvatureActions;
struct RefinedWeakModes;
struct RelaxedEndpointCache;
struct RestrictedPartitionedRfoStep;
struct SecantConsistency;
struct SecantCurvatureCounts;
struct SecantForceSample;
struct SecantHessianConfig;
struct SecantNewtonFactor;
struct SecantSeed;
struct SmoothedCurvatureSpectrum;
struct SoftModeRefusal;
struct SpectralTrustRegionStep;
struct StationaryCurvaturePosterior;
struct StencilIndex;
struct StencilIndexCertificate;
struct SubspaceRitzProbe;
struct WeakModeContinuation;
// classes
class RgminStep;
class SecantHessian;
class SketchedHessianH0;
// global variables
std::uint32_t kMinimizationLayoutVersion = 2;
// global functions
Eigen::RowVectorXd consistentGradientPrediction(const Eigen::Ref<const Eigen::RowVectorXd>& measured_reference, const Eigen::Ref<const Eigen::RowVectorXd>& predicted_reference, const Eigen::Ref<const Eigen::RowVectorXd>& predicted_trial);
double gradientChangeAgreement(const Eigen::Ref<const Eigen::RowVectorXd>& measured_change, const Eigen::Ref<const Eigen::RowVectorXd>& predicted_change);
Eigen::RowVectorXd gradientChangeVariance(const Eigen::MatrixXd& covariance, Eigen::Index dimension, double likelihood_variance);
bool measuredForceChangeCalibrated(double error, double variance, double force_scale);
double measuredTrialTrustAgreement(double rho, bool calibrated, double displacement, double radius, double rho_grow);
template <class Left, class Right>
bool coordinatesCoincideAtRoundoff(const Eigen::MatrixBase<Left>& left, const Eigen::MatrixBase<Right>& right);
const char* endpointConnectivityLabel(const EndpointConnectivityReport& report);
double atomicMassAmu(int atomic_number);
double corderoRadius(int atomic_number);
std::string bondGraph(const Eigen::VectorXd& positions, const std::vector<int>& atomic_numbers);
Eigen::VectorXd massesFromAtomicNumbers(const std::vector<int>& numbers);
double labelledRmsd(const Eigen::VectorXd& reference, const Eigen::VectorXd& mobile, const std::vector<int>& atomic_numbers);
double permutationAwareRmsd(const Eigen::VectorXd& reference, const Eigen::VectorXd& mobile_in, const std::vector<int>& atomic_numbers);
void appendIrcProfile(std::ostream& line, const EndpointConnectivityReport& report);
std::string formatEndpointConnectivity(const EndpointConnectivityReport& report);
Eigen::MatrixXd ircStencilDirections(const Eigen::VectorXd& center, const Eigen::VectorXd& masses, const Eigen::MatrixXd* held_directions, VibrationalStencil mode = VibrationalStencil::Full);
bool cartesianHessianColumns(Eigen::MatrixXd& columns, double& resolution, const Eigen::VectorXd& center, double step, const Eigen::MatrixXd& directions, const std::function<bool(const Eigen::VectorXd&, Eigen::VectorXd&)>& gradient_at, Eigen::MatrixXd* raw_columns = nullptr);
Eigen::MatrixXd cartesianRigidMotions(const Eigen::VectorXd& positions);
Eigen::VectorXd projectOutRigidMotions(const Eigen::VectorXd& positions, Eigen::VectorXd displacement);
EndpointSpectrum spectrumOfColumns(const Eigen::MatrixXd& hessian, double resolution, const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, double stiff_floor);
EndpointSpectrum spectrumAt(const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, double step, const std::function<bool(const Eigen::VectorXd&, Eigen::VectorXd&)>& gradient_at, double stiff_floor = std::numeric_limits<double>::infinity(), Eigen::MatrixXd* raw_columns = nullptr, const Eigen::MatrixXd* held_directions = nullptr);
template <typename GradientAt>
EndpointSpectrum probeVibrationalMinimum(const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, double step, const GradientAt& gradient_at, double stiff_floor = std::numeric_limits<double>::infinity());
template <typename GradientAt>
EndpointSpectrum spectrumForMinimumCheck(const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, double step, const GradientAt& gradient_at, MinimumSpectrumCache* cache = nullptr, double stiff_floor = std::numeric_limits<double>::infinity());
EndpointSpectrum spectrumOfModelHessian(const Eigen::MatrixXd& raw, const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, double stiff_floor);
double endpointMatchBall(double tolerance, double lambda_min, double half_separation);
bool labelledEndpointsResolve(double separation, double harmonic_reactant, double harmonic_product);
bool insideEndpointBall(double to_this, double to_other, double ball);
template <typename Oracle>
EndpointConnectivityReport reportEndpointConnectivity(const Eigen::VectorXd& saddle, const Eigen::VectorXd& masses, double force_tolerance, const Eigen::VectorXd& reactant, const Eigen::VectorXd& product, const std::vector<int>& atomic_numbers, Oracle oracle, RelaxedEndpointCache* cache = nullptr, double hessian_step = defaultStencilStep(), const std::function<bool()>* stop = nullptr, const std::vector<KnownOracleRow>* known = nullptr, const Eigen::MatrixXd* model_hessian = nullptr, const Eigen::MatrixXd* held_directions = nullptr, VibrationalStencil stencil = VibrationalStencil::Full);
bool writeIrcCertificate(const std::string& path, const EndpointConnectivityReport& report, const std::vector<int>& atomic_numbers);
bool readIrcCertificate(const std::string& path, IrcCertificateRecord& record);
FragmentRotations fragmentRotationDirections(const Eigen::VectorXd& positions, const std::vector<std::pair<int, int>>& bonds);
MinimizationLayoutStamp libraryMinimizationLayout();
MinimizationResult gp_minimize(OracleFn oracle, const Eigen::VectorXd& x_init, const AtomsConfiguration& atoms_config, const MinimizationConfig& config, const policy::TrainingPolicy* policy, const Observation* seed = nullptr, const io::TrainedGpState* gp_state = nullptr);
MinimizationResult gp_minimize(OracleFn oracle, const Eigen::VectorXd& x_init, const AtomsConfiguration& atoms_config, const MinimizationConfig& config = {});
MinimizationLayoutStamp compiledMinimizationLayout();
std::string minimizationLayoutMismatch(const MinimizationLayoutStamp& driver, const MinimizationLayoutStamp& library);
void requireMinimizationLayout();
void excludeNonPositiveCurvatureBlock(Eigen::VectorXd& s, Eigen::VectorXd& y, Eigen::Index offset, Eigen::Index length);
double barzilaiBorweinInverseScale(const Eigen::VectorXd& s, const Eigen::VectorXd& y, double fallback);
Eigen::VectorXd twoLoopRecursion(const std::deque<Eigen::VectorXd>& s_hist, const std::deque<Eigen::VectorXd>& y_hist, const std::deque<double>& rho_hist, const Eigen::VectorXd& force, double H0);
Eigen::VectorXd twoLoopRecursion(const std::deque<Eigen::VectorXd>& s_hist, const std::deque<Eigen::VectorXd>& y_hist, const std::deque<double>& rho_hist, const Eigen::VectorXd& force, const std::function<Eigen::VectorXd(const Eigen::VectorXd&)>& apply_H0);
MeasuredDirectionalCubic refinedDirectionalCubic(const RefinedCurvatureActions& stencil, const Eigen::VectorXd& center_gradient, const Eigen::VectorXd& mode, double step);
double massWeightedMeasuredCurvatureResolution(const gpr::Coord& positions, const gpr::AtomsConfiguration& configuration, const Eigen::MatrixXd& basis, const Eigen::MatrixXd& actions);
double refinedIndexOnePositiveLowerBound(const MeasuredCurvatureSpectrum& complete, Eigen::Index dimension, const RefinedCurvatureActions& refined);
MeasuredCurvatureSpectrum analyzeMeasuredCurvature(const Eigen::MatrixXd& basis, const Eigen::MatrixXd& action);
Eigen::MatrixXd measuredIndexZeroHessian(const Eigen::MatrixXd& basis, const Eigen::MatrixXd& physical, const Eigen::MatrixXd& action);
Eigen::VectorXd measuredModeExpansion(const Eigen::MatrixXd& basis, const Eigen::MatrixXd& physical, const Eigen::VectorXd& action);
double measuredCurvaturePriorScale(const Eigen::MatrixXd& prior, const Eigen::MatrixXd& basis, const Eigen::MatrixXd& action);
Eigen::MatrixXd completeMeasuredHessian(const Eigen::MatrixXd& prior, const Eigen::MatrixXd& basis, const Eigen::MatrixXd& action);
double curvatureAtWavenumber(double wavenumber, const Eigen::VectorXd& direction, const Eigen::VectorXd& atomic_masses);
CompletedSecondMode completedSecondMode(const Eigen::MatrixXd& completed, const Eigen::MatrixXd& basis, Eigen::Index k = 1);
CompletedSecondMode completedAdditionalNegativeMode(const Eigen::MatrixXd& completed, const Eigen::MatrixXd& basis, const Eigen::VectorXd& negative_mode);
Eigen::VectorXd nextMeasuredCurvatureDirection(const Eigen::MatrixXd& basis, const Eigen::MatrixXd& action, const MeasuredCurvatureSpectrum& spectrum, const Eigen::MatrixXd& physical, const Eigen::MatrixXd& preferred, const Eigen::MatrixXd& prior = Eigen::MatrixXd{});
Eigen::MatrixXd nextMeasuredCurvatureDirections(const Eigen::MatrixXd& basis, const Eigen::MatrixXd& action, const MeasuredCurvatureSpectrum& spectrum, const Eigen::MatrixXd& physical, const Eigen::MatrixXd& preferred, Eigen::Index count, const Eigen::MatrixXd& prior = Eigen::MatrixXd{});
MeasuredCurvatureSpectrum analyzeRefinedMeasuredCurvature(const Eigen::MatrixXd& basis, const Eigen::MatrixXd& at_h, const Eigen::MatrixXd& at_2h);
template <typename Evaluate>
MeasuredCurvatureSpectrum refineMeasuredCurvature(const Eigen::VectorXd& center, const Eigen::MatrixXd& basis, double step, Evaluate&& evaluate, RefinedCurvatureActions* actions = nullptr);
template <typename Evaluate>
double refinePositiveCurvatureComplement(const MeasuredCurvatureSpectrum& complete, Eigen::Index dimension, const Eigen::VectorXd& center, double step, Evaluate&& evaluate);
Eigen::VectorXd movingAtomicMasses(const gpr::AtomsConfiguration& config, Eigen::Index n_moving);
Eigen::MatrixXd physicalCurvatureBasis(const gpr::Coord& positions, const gpr::AtomsConfiguration& config, bool exclude_rotations = true, RigidMotionMetric metric = RigidMotionMetric::MassWeighted);
Eigen::MatrixXd vibrationalStencilDirections(const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, bool periodic, bool anchored, const Eigen::VectorXi* frozen = nullptr);
Eigen::MatrixXd stencilDirectionsForMode(VibrationalStencil mode, const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, bool periodic, bool anchored, const Eigen::VectorXi* frozen = nullptr);
bool directionsAreCoordinateAxes(const Eigen::MatrixXd& directions);
Eigen::MatrixXd centralDifferencePoints(const Eigen::VectorXd& center, double step, const Eigen::MatrixXd& directions);
Eigen::MatrixXd massWeightedPhysicalCurvatureBasis(const gpr::Coord& positions, const gpr::AtomsConfiguration& config, bool exclude_rotations = true);
Eigen::MatrixXd transportPhysicalDirections(const Eigen::MatrixXd& directions, const Eigen::MatrixXd& physical);
Eigen::MatrixXd transportMeasuredHessianActions(const gpr::Coord& positions, const gpr::Coord& gradient, const Eigen::MatrixXd& measured_basis, const Eigen::MatrixXd& measured_action, const Eigen::MatrixXd& physical, bool include_rotations = true);
Eigen::MatrixXd hessianColumnsFromDirections(const Eigen::VectorXd& center, const Eigen::VectorXd& center_gradient, const Eigen::MatrixXd& directions, const Eigen::MatrixXd& actions);
RestrictedPartitionedRfoStep restrictedPartitionedRfoStep(const Eigen::VectorXd& curvatures, const Eigen::VectorXd& gradient, const Eigen::MatrixXd& cartesian_modes, double radius);
Eigen::VectorXd richardsonExtrapolate(const Eigen::VectorXd& at_h, const Eigen::VectorXd& at_2h);
Eigen::VectorXd richardsonTruncation(const Eigen::VectorXd& at_h, const Eigen::VectorXd& at_2h);
double refinedCurvatureResolution(double refined_resolution, double anharmonic_scale);
RefinedCurvatureSign refinedCurvatureSign(double curvature, double refined_resolution, double anharmonic_scale);
bool curvatureResolvedByStencil(double measured, double anharmonic_scale);
bool curvatureResolvedByThirdDerivative(double measured, double third, double step);
double richardsonForwardExtrapolate(double at_h, double at_2h);
double richardsonForwardTruncation(double at_h, double at_2h);
bool curvatureResolvedBySurrogate(double measured, double surrogate);
int certifiedCurvatureSign(double extrapolated, double estimate);
void writeSecantCurvatureCounts(std::ostream& out, const SecantCurvatureCounts& counts);
void recordSecantObservation(SecantHessian& secant, const Eigen::VectorXd& position, const Eigen::VectorXd& gradient, double energy, SecantCurvatureCounts& counts, SecantAccounting accounting = SecantAccounting::Count);
const char* secantSeedStatusName(SecantSeedStatus status);
std::optional<Eigen::VectorXd> secantResolvedNegativeMode(const SecantHessian& secant);
SecantSeed secantSeedDirection(const SecantHessian& secant, const Eigen::VectorXd& current_direction);
std::optional<double> secantPositiveInverseScale(const SecantHessian& secant);
SecantNewtonFactor secantNewtonFactor(const SecantHessian& secant);
SecantSeedStatus seedHessianOnSecantRange(Eigen::MatrixXd& model, const Eigen::MatrixXd& secant_hessian);
SecantSeedStatus seedHessianOnMeasuredStepRange(Eigen::MatrixXd& model, const Eigen::MatrixXd& secant_hessian, const Eigen::MatrixXd& measured_steps);
SecantSeedStatus seedHessianFromSecant(Eigen::MatrixXd& model, const SecantHessian& secant, const Eigen::MatrixXd& weight, SecantSeedSupport support = SecantSeedSupport::WholeHessian);
template <class Prior>
SecantHessian secantFittedToResidual(SecantHessianMethod method, const std::vector<SecantForceSample>& samples, Prior&& prior);
int bofillThroughLoadedRgsaddle(std::int64_t n, double* hessian_row_major, const double* step, const double* gradient_change);
std::string bofillRgsaddleAbiRefusal();
void setBofillRgsaddleLibrary(const char* path);
SmoothedCurvatureSpectrum smoothMeasuredCurvature(const Eigen::MatrixXd& prior, const std::vector<MeasuredHessianColumn>& columns, const SmoothedCurvatureSpectrum* previous = nullptr, const linalg::MpiContext& context = linalg::MpiContext::local());
Eigen::VectorXd nextSmoothedCurvatureDirection(const SmoothedCurvatureSpectrum& spectrum, Eigen::Index k);
double measuredUpperBound(const SmoothedCurvatureSpectrum& spectrum, const std::vector<MeasuredHessianColumn>& columns, Eigen::Index k);
Eigen::VectorXd softestUnmeasuredDirection(const SmoothedCurvatureSpectrum& spectrum);
Eigen::Index coarseColumnToRefine(const SmoothedCurvatureSpectrum& spectrum, const std::vector<MeasuredHessianColumn>& columns, Eigen::Index k);
Eigen::VectorXd spectralResidualStep(const Eigen::VectorXd& eigenvalues, const Eigen::MatrixXd& modes, const Eigen::VectorXd& gradient, double radius);
SpectralTrustRegionStep spectralTrustRegionStep(const Eigen::VectorXd& curvatures, const Eigen::MatrixXd& modes, Eigen::Index mode_index, const Eigen::VectorXd& force, double radius, const std::vector<std::pair<Eigen::VectorXd, double>>& measured_negative);
double measuredCubicColumnContribution(double overlap, double mode_quadratic, double axis_quadratic);
double axisStencilDirectionalCubic(const Eigen::MatrixXd& axes, const Eigen::MatrixXd& second_differences, const Eigen::VectorXd& mode);
StationaryCurvaturePosterior stationaryCurvaturePosterior(double c, double c_spread, double f, double f_spread, double b, double b_spread, Eigen::Index samples = detail::kSpectrumSamples);
Eigen::MatrixXd massWeightedRigidMotions(const Eigen::VectorXd& positions, const Eigen::VectorXd& masses);
Eigen::MatrixXd vibrationalComplement(const Eigen::VectorXd& positions, const Eigen::VectorXd& masses);
StencilIndex analyzeStencilIndex(const Eigen::MatrixXd& columns, const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, const Eigen::MatrixXd* measured = nullptr);
template <typename Gradients>
RefinedWeakModes refineWeakModes(const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, const Eigen::MatrixXd& weak, double step, const Gradients& gradients, double noise_multiplier = 0.0);
template <typename Gradients>
SoftModeRefusal refuseSecondNegativeMode(const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, const Eigen::MatrixXd& mass_weighted_modes, double step, const Gradients& gradients, double noise_multiplier = 0.0);
double rotatedPositiveRestrictionLowerBound(const Eigen::MatrixXd& block, const Eigen::MatrixXd& errors, const Eigen::MatrixXd& coupling, const Eigen::VectorXd& tail, double allowance);
template <typename Gradients>
StencilIndexCertificate certifyStencilIndex(const StencilIndex& index, const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, double step, const Gradients& gradients, Eigen::Index minimum_weak = 0, double noise_multiplier = 0.0);
template <typename Gradients>
MeasuredIndexDecision decideMeasuredIndex(const Eigen::MatrixXd& columns, const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, double step, const Gradients& gradients, const Eigen::MatrixXd* measured = nullptr);
WeakModeContinuation boundedWeakModeContinuation(const Eigen::VectorXd& direction, double third, double step, double lower, double resolution, double step_bound);
WeakModeContinuation weakModeContinuation(const StencilIndexCertificate& certificate, const Eigen::VectorXd& centre_gradient, double resolution, double step_bound);
template <typename Gradients>
NegativePairRejection rejectMeasuredNegativePair(const Eigen::MatrixXd& previous_cartesian_hessian, const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, const Eigen::VectorXd& centre_gradient, double step, double step_bound, const Gradients& gradients);
StencilAction nextStencilAction(bool higher_order, bool weak_higher_order, bool weak_uncertified, int& continuations, int maximum_continuations);
double defaultStencilStep();
double stencilStepOrDefault(double requested);
int forceStopAdaptiveStepReductions();
template <typename Gradients>
StencilIndexCertificate certifyAdaptiveStencilIndex(const StencilIndex& index, const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, double step, const Gradients& gradients, double noise_multiplier = 0.0);
template <typename Gradients>
PairRitzProbe probePairRitz(const Eigen::VectorXd& center, const Eigen::VectorXd& masses, const Eigen::VectorXd& u, const Eigen::VectorXd& v, double step, const Gradients& gradients);
template <typename Gradients>
SubspaceRitzProbe probeSubspaceRitz(const Eigen::VectorXd& center, const Eigen::VectorXd& masses, const Eigen::MatrixXd& candidates, double step, const Gradients& gradients);
bool forceStopMeasurementInconclusiveOrHigher(const ForceStopMeasurement& measured);
int forceStopSoftRefinementLimit();
int forceStopRefinementCertified();
int forceStopRefinementStillHigher();
bool sameStencilGeometry(const Eigen::VectorXd& first, const Eigen::VectorXd& second);
int forceStopMinModeEscapes();
ForceStopStencilPlan planForceStopStencil(ForceStopStencilQuery query);
ForceStopStencilPlan planForceStopStencil(SaddleSearchFamily family, bool requested);
bool forceStopCertificatePlanned(const ForceStopStencilPlan& plan);
Eigen::Index forceStopHeldColumn(const Eigen::MatrixXd& held, const Eigen::VectorXd& query, double relative = 1e-6);
Eigen::MatrixXd forceStopLowestModes(const Eigen::MatrixXd& columns, const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, Eigen::Index count, const Eigen::MatrixXd* measured = nullptr);
bool forceStopStencilCertifies(bool measured, bool first_order);
template <typename Measure, typename Refine>
ForceStopCertificateResult runForceStopCertificate(Measure measure, Refine refine, ForceStopStencilPlan plan, const ForceStopMeasurement* prior = nullptr);
const char* vibrationalStencilName(VibrationalStencil mode);
bool parseVibrationalStencil(std::string_view text, VibrationalStencil& out);
VibrationalStencil vibrationalStencilFromInt(int value);
double maxAtomDisplacement(const Eigen::VectorXd& delta);
} // namespace optim
Detailed Documentation¶
Typedefs¶
typedef std::function<std::pair<double, Eigen::VectorXd>(const Eigen::VectorXd&positions)> OracleFn
Oracle function: positions -> (energy, gradient).
Global Variables¶
std::uint32_t kMinimizationLayoutVersion = 2
Layout of MinimizationConfig and MinimizationResult. Bump when either struct’s layout changes, including a reorder that keeps the size. 2: MinimizationResult::prior_observations.
Global Functions¶
Eigen::RowVectorXd consistentGradientPrediction(const Eigen::Ref<const Eigen::RowVectorXd>& measured_reference, const Eigen::Ref<const Eigen::RowVectorXd>& predicted_reference, const Eigen::Ref<const Eigen::RowVectorXd>& predicted_trial)
Anchor a local force-merit model to its measured reference gradient. Both predictions must come from the same posterior. Their difference retains its curvature while cancelling a constant gradient bias.
double gradientChangeAgreement(const Eigen::Ref<const Eigen::RowVectorXd>& measured_change, const Eigen::Ref<const Eigen::RowVectorXd>& predicted_change)
Agreement of measured and predicted gradient changes, in [-1, 1]. Dimer steps can increase the force norm, so model validity is independent of a monotone force merit. Zero changes carry no radius information.
Eigen::RowVectorXd gradientChangeVariance(const Eigen::MatrixXd& covariance, Eigen::Index dimension, double likelihood_variance)
Marginal variances of a noisy gradient difference at two query points. Joint channels contain two energies followed by two values per gradient coordinate. Correlated latent errors cancel through the cross covariance; independent likelihood errors contribute twice their physical variance.
bool measuredForceChangeCalibrated(double error, double variance, double force_scale)
Statistical agreement certifies a force-change model only when the error also resolves the physical force scale on which the step acts. Likelihood regularization cannot enlarge that scale as a root is approached.
double measuredTrialTrustAgreement(double rho, bool calibrated, double displacement, double radius, double rho_grow)
Radius agreement for a measured gradient-change model. A discrepancy resolved beyond its predictive spread uses rho. An unresolved discrepancy does not justify contraction; a trial at the boundary enlarges the domain in which the search can resolve a change. Final force acceptance is separate.
template <class Left, class Right>
bool coordinatesCoincideAtRoundoff(const Eigen::MatrixBase<Left>& left, const Eigen::MatrixBase<Right>& right)
Numerical stagnation in stored Cartesian coordinates. Each component has a binary64 roundoff allowance; acquisition distances and force tolerances do not define geometry identity.
double atomicMassAmu(int atomic_number)
Standard atomic weight (amu) for the elements in the Baker and Birkholz sets. An unlisted element keeps unit mass; the caller can pass masses it already trusts instead.
double corderoRadius(int atomic_number)
Cordero et al., Dalton Trans. 2008, angstrom. An unlisted element contributes no edges.
std::string bondGraph(const Eigen::VectorXd& positions, const std::vector<int>& atomic_numbers)
Bonds as sorted index pairs. The cutoff is 1.2 times the sum of the Cordero radii. Atom order is the file order, which the walk keeps.
double labelledRmsd(const Eigen::VectorXd& reference, const Eigen::VectorXd& mobile, const std::vector<int>& atomic_numbers)
Rigidly aligned RMSD in the file’s atom order. Rigid motion is removed and atoms are not re-paired. The bond graph is indexed the same way, so a label swap that keeps the permutation-aware distance at zero stays a real separation here.
double permutationAwareRmsd(const Eigen::VectorXd& reference, const Eigen::VectorXd& mobile_in, const std::vector<int>& atomic_numbers)
RMSD after a rigid alignment and a re-pairing that only exchanges atoms of the same element. The length is the root mean square over atoms. One start pairs by sorted distances, which a rotation does not change; the other pairs in the lab frame. Both are repeated until the assignment stops improving, and the smaller RMSD is kept. The certificate distance does not use this: a degenerate rearrangement would then sit on top of itself.
Eigen::MatrixXd ircStencilDirections(const Eigen::VectorXd& center, const Eigen::VectorXd& masses, const Eigen::MatrixXd* held_directions, VibrationalStencil mode = VibrationalStencil::Full)
Directions of the IRC’s Hessian stencils at a free geometry: the held validation directions when they fit, so rows measured at the saddle are read again, and otherwise the requested stencil. Full is every coordinate. Vibrational is vibrationalStencilDirections.
bool cartesianHessianColumns(Eigen::MatrixXd& columns, double& resolution, const Eigen::VectorXd& center, double step, const Eigen::MatrixXd& directions, const std::function<bool(const Eigen::VectorXd&, Eigen::VectorXd&)>& gradient_at, Eigen::MatrixXd* raw_columns = nullptr)
Central-difference Hessian along directions, as Cartesian columns: columns.col(j) is d(gradient)/dx_j (hessianColumnsFromDirections, which reads the center gradient when rigid columns were removed). The resolution is the antisymmetric residual of the measured block: of the whole matrix for a complete stencil, of directions^T raw directions when the rigid columns were rebuilt rather than measured.
Eigen::VectorXd projectOutRigidMotions(const Eigen::VectorXd& positions, Eigen::VectorXd displacement)
Component of displacement orthogonal to rigid translation and rotation at positions. The rank is the numerical rank of that basis.
EndpointSpectrum spectrumAt(const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, double step, const std::function<bool(const Eigen::VectorXd&, Eigen::VectorXd&)>& gradient_at, double stiff_floor = std::numeric_limits<double>::infinity(), Eigen::MatrixXd* raw_columns = nullptr, const Eigen::MatrixXd* held_directions = nullptr)
The spectrum of one Hessian stencil along held_directions, or along the default full Cartesian stencil at positions (ircStencilDirections).
template <typename GradientAt>
EndpointSpectrum probeVibrationalMinimum(const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, double step, const GradientAt& gradient_at, double stiff_floor = std::numeric_limits<double>::infinity())
Lanczos on the Cartesian vibrational complement, with true-oracle Hessian-vector products.
Central differences along the orthonormal complement of rigid motion are the vibrational operator. A Ritz value is an upper bound on the lowest eigenvalue (Courant Fischer), so one below minus the measured asymmetry, with its full-space residual inside both that asymmetry and the gap to the next Ritz value, proves a negative mode. The same residual test cannot prove there is no negative mode: a direction outside an invariant subspace can carry either sign (scripts/derive_krylov_index_certificate.py). Positive definiteness is the spectrum at exhaustion of the complement. A Krylov subspace that stalls is extended by the least-represented complement direction. The probe reports nothing when that extension is impossible or a product cannot be measured; the caller then builds the complete stencil.
template <typename GradientAt>
EndpointSpectrum spectrumForMinimumCheck(const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, double step, const GradientAt& gradient_at, MinimumSpectrumCache* cache = nullptr, double stiff_floor = std::numeric_limits<double>::infinity())
Vibrational Lanczos when the probe produced a spectrum. The complete stencil (spectrumAt) is used only when the probe cannot be measured. A spectrum stored at these coordinates is returned as it stands. A curvature inside the measured asymmetry is not a second stencil: the sign test is the same comparison, lowest < -resolution.
EndpointSpectrum spectrumOfModelHessian(const Eigen::MatrixXd& raw, const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, double stiff_floor)
A symmetric matrix from a model, judged with the same resolution as a measured stencil: the singular value of its antisymmetric part.
double endpointMatchBall(double tolerance, double lambda_min, double half_separation)
Match ball around a relaxed minimum.
A residual max-atom force tolerance moves a quadratic minimum by at most tolerance / λ_min in RMSD. The Cartesian gradient then has L2 norm at most tolerance * sqrt(N), the displacement has L2 norm at most that over λ_min, and dividing by sqrt(N) cancels the atom count. Rigid motions are absent from λ_min and from the Kabsch RMSD, so they do not belong in the ball. Each of the walk and the relaxed endpoint can sit one residual from the true minimum, so the RMSD between them is at most twice that. The ball is also not larger than half the RMSD between the two relaxed minima.
bool labelledEndpointsResolve(double separation, double harmonic_reactant, double harmonic_product)
The harmonic radius is the largest distance the force tolerance still counts as one minimum. The endpoints are two centres when the labelled separation exceeds both radii. A smaller separation is one minimum counted twice: the field is ball=na, and the radius used for a resolved pair is unchanged.
template <typename Oracle>
EndpointConnectivityReport reportEndpointConnectivity(const Eigen::VectorXd& saddle, const Eigen::VectorXd& masses, double force_tolerance, const Eigen::VectorXd& reactant, const Eigen::VectorXd& product, const std::vector<int>& atomic_numbers, Oracle oracle, RelaxedEndpointCache* cache = nullptr, double hessian_step = defaultStencilStep(), const std::function<bool()>* stop = nullptr, const std::vector<KnownOracleRow>* known = nullptr, const Eigen::MatrixXd* model_hessian = nullptr, const Eigen::MatrixXd* held_directions = nullptr, VibrationalStencil stencil = VibrationalStencil::Full)
Relax the deposited endpoints once, walk downhill both ways from the saddle with the same L-BFGS and the same force tolerance, and decide whether those walks are the two relaxed minima. held_directions are the directions of a stencil the search measured at the saddle, whose rows known carries; the saddle Hessian is measured along them.
bool writeIrcCertificate(const std::string& path, const EndpointConnectivityReport& report, const std::vector<int>& atomic_numbers)
Exact record of the saddle, the mode, and both walk ends. Hex floating point round-trips, so a replay from the written saddle sees the same bits the walk used.
MinimizationLayoutStamp libraryMinimizationLayout()
What libgpridge was built with. Defined in the library, not inline.
MinimizationResult gp_minimize(OracleFn oracle, const Eigen::VectorXd& x_init, const AtomsConfiguration& atoms_config, const MinimizationConfig& config, const policy::TrainingPolicy* policy, const Observation* seed = nullptr, const io::TrainedGpState* gp_state = nullptr)
GP-accelerated geometry minimization with a training policy.
Parameters:
oracle |
Energy and gradient evaluator. |
x_init |
Starting Cartesian coordinates, flattened in atom order. |
atoms_config |
Atomic configuration for the GP kernel. |
config |
Surrogate and minimization settings. |
policy |
Training policy. Null keeps the engine’s decisions. |
seed |
Observations already paid for. A row at x_init is reused and is not an oracle call. Null starts from the oracle. |
gp_state |
Saved hyperparameters. Null keeps a cold first fit. |
MinimizationResult gp_minimize(OracleFn oracle, const Eigen::VectorXd& x_init, const AtomsConfiguration& atoms_config, const MinimizationConfig& config = {})
GP-accelerated geometry minimization.
The four-argument overload is the original symbol. A defaulted fifth parameter would change that mangled name, so the policy is a separate overload and is not defaulted.
Parameters:
oracle |
Energy/gradient evaluation function |
x_init |
Initial positions (flat 3*N_atoms vector) |
atoms_config |
Atomic configuration for GP kernel |
config |
Minimization parameters |
Returns:
void excludeNonPositiveCurvatureBlock(Eigen::VectorXd& s, Eigen::VectorXd& y, Eigen::Index offset, Eigen::Index length)
Remove a block’s nonpositive secant contribution. Positive curvature is retained, including the reflected unstable direction at an index-one saddle. Invalid blocks and nonfinite curvature leave the pair unchanged for the caller’s full-pair validity check.
double barzilaiBorweinInverseScale(const Eigen::VectorXd& s, const Eigen::VectorXd& y, double fallback)
Scalar BB2 inverse-curvature seed for L-BFGS H0.
Uses the Barzilai-Borwein two-point spectral scale gamma_k = (s_k^T y_k)/(y_k^T y_k) as the scalar inverse-Hessian seed for the two-loop recursion (doi:10.1093/imanum/8.1.141). Degenerate, non-finite, or non-positive curvature pairs return the caller’s fallback.
Eigen::VectorXd twoLoopRecursion(const std::deque<Eigen::VectorXd>& s_hist, const std::deque<Eigen::VectorXd>& y_hist, const std::deque<double>& rho_hist, const Eigen::VectorXd& force, double H0)
Nocedal two-loop recursion (the LBFGS kernel).
Computes z = H^{-1} (-force) where H is the inverse-Hessian approximation reconstructed from m curvature pairs (s_k, y_k) and their reciprocal dot products rho_k = 1 / (y_k . s_k). The caller applies the step as x <- x - z (force-convention: z points downhill when force is the negative gradient).
H0 is the initial-iter inverse-Hessian diagonal scaling. The scalar BB2 seed is gamma = s_{m-1}^T y_{m-1} / y_{m-1}^T y_{m-1}; on empty history (m == 0) the caller supplies the fallback scale.
No internal mutation of the history; the caller owns appending, trimming, and resetting. gpr::neb::detail::GlobalLBFGSOptimizer calls into this kernel so the recursion is defined once.
Eigen::VectorXd twoLoopRecursion(const std::deque<Eigen::VectorXd>& s_hist, const std::deque<Eigen::VectorXd>& y_hist, const std::deque<double>& rho_hist, const Eigen::VectorXd& force, const std::function<Eigen::VectorXd(const Eigen::VectorXd&)>& apply_H0)
Two-loop recursion with a caller-supplied H0 application.
Identical to the scalar overload except H0 is consumed via apply_H0(q) -> H0 q. Used by callers that supply a Nystrom-sketched (or otherwise structured) initial inverse Hessian: the scalar form is just apply_H0 = [&](v){ return H0_scalar * v; }.
The kernel does not touch the H0 functor’s internals it is the caller’s responsibility to keep the sketch consistent with the history vectors it pairs with (typically: rebuild the sketch once per outer iter at the same band position the latest (s, y) was collected from).
MeasuredDirectionalCubic refinedDirectionalCubic(const RefinedCurvatureActions& stencil, const Eigen::VectorXd& center_gradient, const Eigen::VectorXd& mode, double step)
The complete cubic within a refined two-dimensional plane. Even gradient residuals at h and h/2 identify its four symmetric coefficients. Richardson extrapolation removes the leading fifth-energy-derivative term. The error is an empirical stencil estimate plus roundoff, not a global Taylor bound.
double massWeightedMeasuredCurvatureResolution(const gpr::Coord& positions, const gpr::AtomsConfiguration& configuration, const Eigen::MatrixXd& basis, const Eigen::MatrixXd& actions)
Empirical resolution in the mass-weighted physical coordinates of the refinement, in eV/(A^2 amu). The Cartesian measured map is B (B^T A) B^T with zero action outside the measured space. Its congruence on D Q is C^T (B^T A) C, where D = M^(-1/2), Q is the physical basis of the refinement and C = B^T D Q. Raw actions retain the measured asymmetry.
double refinedIndexOnePositiveLowerBound(const MeasuredCurvatureSpectrum& complete, Eigen::Index dimension, const RefinedCurvatureActions& refined)
Lower bound on the positive codimension-one restriction, conditional on the complete stencil and refined weak directions’ empirical error bounds. Nonpositive results do not certify the index.
MeasuredCurvatureSpectrum analyzeMeasuredCurvature(const Eigen::MatrixXd& basis, const Eigen::MatrixXd& action)
Symmetrize measured Hessian actions and retain their common empirical resolution. Asymmetry and roundoff do not bound symmetric truncation error.
Eigen::MatrixXd measuredIndexZeroHessian(const Eigen::MatrixXd& basis, const Eigen::MatrixXd& physical, const Eigen::MatrixXd& action)
Cartesian Hessian of a complete measured expansion that resolves no negative curvature. The basis must span the supplied physical space, so the excluded rigid directions carry zero curvature. Empty when the expansion is incomplete or invalid, or when its lowest curvature lies below minus its own resolution.
Eigen::VectorXd measuredModeExpansion(const Eigen::MatrixXd& basis, const Eigen::MatrixXd& physical, const Eigen::VectorXd& action)
Independent part of a measured lowest-mode action at a fixed midpoint. Two projection passes keep stiff directions out of the retained basis; a residual within projection roundoff supplies no new measured column.
double measuredCurvaturePriorScale(const Eigen::MatrixXd& prior, const Eigen::MatrixXd& basis, const Eigen::MatrixXd& action)
Positive least-squares scale of a prior’s measured Hessian actions. Orthogonal changes of physical basis and curvature units preserve this fit. A zero or oppositely correlated prior supplies no positive scale. Leave-one-direction-out prediction must improve on the unscaled prior. This calibrates probe proposals; measured actions determine the index.
Eigen::MatrixXd completeMeasuredHessian(const Eigen::MatrixXd& prior, const Eigen::MatrixXd& basis, const Eigen::MatrixXd& action)
Least-change symmetric completion of measured columns over a prior. An orthonormal basis fixes its measured block and cross terms; the unmeasured block keeps the prior. Incompatible columns are symmetrized within the measured block. This operator supplies proposals, not signs.
double curvatureAtWavenumber(double wavenumber, const Eigen::VectorXd& direction, const Eigen::VectorXd& atomic_masses)
Cartesian curvature of a displacement whose harmonic wavenumber is wavenumber (cm^-1): (2 pi c nu)^2 u^T M u / u^T u, in eV/A^2 for masses in amu. A softer direction is below that frequency resolution whatever its sign. Zero when no masses are given or the sizes disagree.
CompletedSecondMode completedSecondMode(const Eigen::MatrixXd& completed, const Eigen::MatrixXd& basis, Eigen::Index k = 1)
The direction a completion proposes for measurement: its k-th lowest mode (the second by default). completed is a symmetric completion of the columns measured along the orthonormal basis. This supplies a proposal, not a sign.
CompletedSecondMode completedAdditionalNegativeMode(const Eigen::MatrixXd& completed, const Eigen::MatrixXd& basis, const Eigen::VectorXd& negative_mode)
Eliminate a measured negative direction by congruence before choosing another probe. For H = [a b^T; b D], a < 0, the remaining inertia is that of D - b b^T/a. Lifting its mode y to [-b^T y/a; y] preserves the sign of its quadratic form. This orders measurements only; the measured Ritz pair and the final oracle stencil decide the index.
Eigen::VectorXd nextMeasuredCurvatureDirection(const Eigen::MatrixXd& basis, const Eigen::MatrixXd& action, const MeasuredCurvatureSpectrum& spectrum, const Eigen::MatrixXd& physical, const Eigen::MatrixXd& preferred, const Eigen::MatrixXd& prior = Eigen::MatrixXd{})
Expand toward the second mode of a measured completion when a prior is available, then the second Ritz residual. An invariant subspace needs an independent seed; the physical basis guarantees complement coverage.
Eigen::MatrixXd nextMeasuredCurvatureDirections(const Eigen::MatrixXd& basis, const Eigen::MatrixXd& action, const MeasuredCurvatureSpectrum& spectrum, const Eigen::MatrixXd& physical, const Eigen::MatrixXd& preferred, Eigen::Index count, const Eigen::MatrixXd& prior = Eigen::MatrixXd{})
Expand by independent physical directions that can share an oracle batch. The leading column follows the completed prior or second Ritz residual. Further residuals and physical seeds fill its orthogonal complement.
MeasuredCurvatureSpectrum analyzeRefinedMeasuredCurvature(const Eigen::MatrixXd& basis, const Eigen::MatrixXd& at_h, const Eigen::MatrixXd& at_2h)
Refine a measured subspace using central stencils at h and 2h. The projected leading truncation correction supplies an empirical resolution; it is not a bound on arbitrary higher derivatives of the potential.
template <typename Evaluate>
MeasuredCurvatureSpectrum refineMeasuredCurvature(const Eigen::VectorXd& center, const Eigen::MatrixXd& basis, double step, Evaluate&& evaluate, RefinedCurvatureActions* actions = nullptr)
Measure central actions at h and h/2 in one owned batch. The evaluator accepts row-wise Cartesian positions, returns their energy gradients, and owns distribution and retention of every true observation.
template <typename Evaluate>
double refinePositiveCurvatureComplement(const MeasuredCurvatureSpectrum& complete, Eigen::Index dimension, const Eigen::VectorXd& center, double step, Evaluate&& evaluate)
Refine every unresolved positive mode while retaining the measured lower bound on the rest of the complete physical space. The evaluator owns every acquisition, including repeated positions and their multiplicities.
Eigen::VectorXd movingAtomicMasses(const gpr::AtomsConfiguration& config, Eigen::Index n_moving)
Positive finite masses in the packed moving-coordinate order. With a mobility mask, input masses describe the full frame and moving entries are selected in mask order. Empty input masses select unit masses.
Eigen::MatrixXd physicalCurvatureBasis(const gpr::Coord& positions, const gpr::AtomsConfiguration& config, bool exclude_rotations = true, RigidMotionMetric metric = RigidMotionMetric::MassWeighted)
Cartesian orthonormal basis for the physical vibrational subspace. If R spans rigid displacements and M contains atomic masses, the Cartesian image of the mass-weighted vibrational space is ker(R^T M). Congruence on this space preserves the index without changing Cartesian probe lengths.
Eigen::MatrixXd vibrationalStencilDirections(const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, bool periodic, bool anchored, const Eigen::VectorXi* frozen = nullptr)
Displacement directions of the vibrational stencil: the orthonormal Cartesian basis B of ker(R^T M), 3N-6 columns (3N-5 for a linear molecule, 3N-3 in a periodic cell, where rotations are not symmetries). An anchored geometry keeps every coordinate, and so does a lone atom, whose energy can only vary in an external field. Frozen atoms (nonzero frozen flags, one per atom) anchor the rest and never move: the directions are then the moving atoms’ coordinate axes. With Q the mass-weighted vibrational basis, M^{-1/2} Q = B C for C = B^T M^{-1/2} Q, so Q^T M^{-1/2} H M^{-1/2} Q = C^T (B^T H B) C reads only H B: the vibrational index needs no rigid column and no invariance of the oracle.
Eigen::MatrixXd stencilDirectionsForMode(VibrationalStencil mode, const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, bool periodic, bool anchored, const Eigen::VectorXi* frozen = nullptr)
Full measures every Cartesian coordinate: all 3 coordinates for N=1, and all 3N when atoms are frozen, so measureVibrationalIndex(frozen, Full) probes all 3N. Vibrational uses vibrationalStencilDirections. A lone atom is the identity in both.
bool directionsAreCoordinateAxes(const Eigen::MatrixXd& directions)
True when every direction is a distinct coordinate axis: the stencil of a geometry whose other coordinates are frozen. No coordinate axis is orthogonal to the mass-weighted translations, so a vibrational basis never reads as one.
Eigen::MatrixXd centralDifferencePoints(const Eigen::VectorXd& center, double step, const Eigen::MatrixXd& directions)
Central-difference geometries along each direction: column 2k is center + step d_k and column 2k+1 is center - step d_k. Every stencil forms its points here, so a held row is found again bit for bit.
Eigen::MatrixXd massWeightedPhysicalCurvatureBasis(const gpr::Coord& positions, const gpr::AtomsConfiguration& config, bool exclude_rotations = true)
Orthonormal physical step directions in mass-weighted coordinates. Cartesian directions in ker(R^T M) map through sqrt(M) to the complement of the mass-weighted rigid motions. Frozen anchors retain every moving coordinate; periodic cells exclude translations and retain rotations.
Eigen::MatrixXd transportPhysicalDirections(const Eigen::MatrixXd& directions, const Eigen::MatrixXd& physical)
Reproject search directions in their supplied order. Curvature signs require fresh measurements; projection alone carries no certificate.
Eigen::MatrixXd transportMeasuredHessianActions(const gpr::Coord& positions, const gpr::Coord& gradient, const Eigen::MatrixXd& measured_basis, const Eigen::MatrixXd& measured_action, const Eigen::MatrixXd& physical, bool include_rotations = true)
Express measured Cartesian Hessian actions in another complete physical basis at the same geometry. Rigid translations have zero action; rotational invariance gives H (omega x R) = omega x gradient, including at nonstationary points. These identities supply the rigid part removed when changing between mass-weighted and Cartesian constraints.
Eigen::MatrixXd hessianColumnsFromDirections(const Eigen::VectorXd& center, const Eigen::VectorXd& center_gradient, const Eigen::MatrixXd& directions, const Eigen::MatrixXd& actions)
Cartesian Hessian columns of a stencil measured along orthonormal directions, with actions.col(k) the central difference of the gradient along direction k. A complete set is the measurement itself. Otherwise the removed rigid columns are the identities of transportMeasuredHessianActions, about the measured center gradient: rotations when more than translations were removed. The columns along the directions stay the measured ones, so the vibrational block of the result is the measured block exactly, and only full-Cartesian consumers read the rigid columns: the spectrum and its resolution are taken on the measured block (analyzeStencilIndex). Coordinate-axis directions leave frozen coordinates, which carry no curvature: the result is the measured moving block with zero frozen rows and columns. Empty when the inputs cannot form that matrix.
RestrictedPartitionedRfoStep restrictedPartitionedRfoStep(const Eigen::VectorXd& curvatures, const Eigen::VectorXd& gradient, const Eigen::MatrixXd& cartesian_modes, double radius)
Restricted partitioned RFO on an ascending Hessian spectrum. rgsaddle_prfo_step mass-weights a Cartesian Hessian and brackets alpha by doubling and bisection. rgsaddle_trust_update is Sella’s rho schedule. Neither is this secular problem on a supplied basis whose columns need not be orthonormal, so this walk does not call them and there is no second copy kept for a build without rgsaddle. Mode zero is maximized and its complement is minimized. The full-column- rank map cartesian_modes converts eigenbasis coefficients to Cartesian displacement; its columns need not be orthonormal. Both partitions share alpha = c^2, with c >= 1, and the Cartesian norm supplies the restriction.
Regular steps satisfy (D - mu I) s = -g and mu = c^2 g.s in each partition. A feasible pure step has c = 1. A binding step retains the feasible side of a continuous secular branch until the c bracket reaches floating-point resolution; no monotonicity of the Cartesian norm is required. An exact homogeneous hard case retains a boundary direction, rather than claiming a finite alpha resolves a vanishing affine coordinate. Scalar secular arithmetic uses the extended exponent range of long double. Targets where long double has only binary64 range can decline extreme inputs.
Eigen::VectorXd richardsonExtrapolate(const Eigen::VectorXd& at_h, const Eigen::VectorXd& at_2h)
Central-difference curvature measurements along a direction drop every even power of the displacement, so the separations h and 2h combine into an estimate exact through the quartic force term (scripts/derive_richardson_transverse_curvature.py, proofs/lean/GPRidge/RichardsonCurvature.lean): c_R = (4 c(h) - c(2h)) / 3, delta = (c(2h) - c(h)) / 3 = d h^2, where delta is the truncation term the single-separation estimate carried. The same combination applies entrywise to the measured Hessian actions the Rayleigh-Ritz curvatures are built from.
bool curvatureResolvedByStencil(double measured, double anharmonic_scale)
Screen for refining a single-separation curvature: its magnitude against the stencil’s own anharmonicity scale, the even residual (F(h) + F(-h))/2 - F(0) = b h^2 of the same three measurements over h. This is not a sign certificate. The even residual is F’’(0) h^2 / 2 and vanishes on a symmetric direction whatever the truncation is; the certificate is curvatureResolvedByThirdDerivative.
bool curvatureResolvedByThirdDerivative(double measured, double third, double step)
One central difference resolves the sign of the curvature only against an explicit third-derivative bound. If abs(phi’’’) <= third on [-step, step], abs((phi(step) - phi(-step)) / (2 * step) - phi’(0)) <= third * step * step / 6 (centralCurvature_error). The even residual (φ(step) + φ(-step)) / 2 - φ(0) is φ''(0) step² / 2 and does not bound that error: φ(t) = t - 100 t³ at step = 0.2 has even residual 0 and a central quotient of -3, while the true curvature is +1.
double richardsonForwardExtrapolate(double at_h, double at_2h)
One measured side only (the dimer axis: the midpoint and one image): the forward difference c_f(h) = (F(h) - F(0))/h carries c + b h + d h^2, and 2 c_f(h) - c_f(2h) = c - 2 d h^2 is exact through the quadratic force term; c_f(2h) - c_f(h) = b h + 3 d h^2 is the first-order truncation the single estimate carried.
bool curvatureResolvedBySurrogate(double measured, double surrogate)
With one measured side there is no even residual; the surrogate’s disagreement with the measurement is the only resolution scale a single-separation estimate carries.
int certifiedCurvatureSign(double extrapolated, double estimate)
The sign of the extrapolated curvature certified against its truncation estimate: +1 or -1 when the magnitude exceeds the estimate, 0 when the measurement cannot resolve the sign.
void recordSecantObservation(SecantHessian& secant, const Eigen::VectorXd& position, const Eigen::VectorXd& gradient, double energy, SecantCurvatureCounts& counts, SecantAccounting accounting = SecantAccounting::Count)
Record one true-force geometry. A nonzero displacement that the selected update refuses is a rejected pair; the first geometry is neither. The energy joins the reference only with the geometry it was measured at.
std::optional<Eigen::VectorXd> secantResolvedNegativeMode(const SecantHessian& secant)
Lowest Ritz vector of the secant Hessian on the measured-step span when its Ritz value is a resolved negative curvature. Curvature outside that span is not measured; in particular, a one-step Bofill update from zero can create a spurious negative eigenvalue on a convex surface. Empty when the secant has no accepted pair or the projection resolves no negative mode.
std::optional<double> secantPositiveInverseScale(const SecantHessian& secant)
Inverse curvature 1 / (u^T H u) along the latest accepted step, when that curvature is positive. Empty means the secant does not define a descent scale.
SecantSeedStatus seedHessianOnSecantRange(Eigen::MatrixXd& model, const Eigen::MatrixXd& secant_hessian)
Replace model on the range of secant_hessian with that Hessian’s action and leave the orthogonal complement unchanged. An eigenvalue is in the range when its magnitude exceeds the square root of epsilon times the largest magnitude, so the criterion has no units. A secant with no such eigenvalue carries no curvature to seed, and model stays as it is.
SecantSeedStatus seedHessianOnMeasuredStepRange(Eigen::MatrixXd& model, const Eigen::MatrixXd& secant_hessian, const Eigen::MatrixXd& measured_steps)
As above, but only on the Ritz pairs of secant_hessian projected onto the span of measured_steps. Curvature outside that span is not evidence for modifying the model. The tolerance is relative to the largest projected magnitude. measured_steps must be expressed in the coordinates of model and secant_hessian.
SecantSeedStatus seedHessianFromSecant(Eigen::MatrixXd& model, const SecantHessian& secant, const Eigen::MatrixXd& weight, SecantSeedSupport support = SecantSeedSupport::WholeHessian)
Seed model from secant, whose Hessian is first weighted entry by entry by weight (the mass weighting the model lives in). Refuses, leaving model unchanged, when the secant has no accepted pair or was measured in another dimension.
support picks the part of the weighted Hessian that is taken. A MeasuredSteps seed projects onto the measured steps in the weighted coordinates: weight is the outer product w w^T of the coordinate scale w (M^{-1/2} for a mass weighting), so a Cartesian step s becomes s / w. The two agree only when w is constant. In that mode the diagonal of weight must be positive and finite, otherwise std::invalid_argument is thrown.
template <class Prior>
SecantHessian secantFittedToResidual(SecantHessianMethod method, const std::vector<SecantForceSample>& samples, Prior&& prior)
Fit q to (E - m, F - grad m). prior writes the exact prior energy and Cartesian gradient at a geometry. The returned secant is the production residual quadratic.
int bofillThroughLoadedRgsaddle(std::int64_t n, double* hessian_row_major, const double* step, const double* gradient_change)
Bofill through the linked librgsaddle (rgsaddle_hessian_bofill). hessian_row_major is n by n. Returns 1 when the runtime wrote an update, 0 when it refused and left the buffer unchanged, and -1 when the linked ABI stamp is not major 1 with minor at least 3. bofillRgsaddleAbiRefusal names that required ABI and the stamp that was found.
std::string bofillRgsaddleAbiRefusal()
Refusal text for a Bofill call the linked ABI rejects. Names the required rgsaddle ABI major and minor 3, and the major and minor (or stamp status) that were found.
void setBofillRgsaddleLibrary(const char* path)
Records the index-test choice before the first Bofill call. The update uses the linked library, so the path is not opened. Null or empty clears the recorded choice.
SmoothedCurvatureSpectrum smoothMeasuredCurvature(const Eigen::MatrixXd& prior, const std::vector<MeasuredHessianColumn>& columns, const SmoothedCurvatureSpectrum* previous = nullptr, const linalg::MpiContext& context = linalg::MpiContext::local())
Condition measured Hessian columns, then distribute independent spectrum samples over the supplied process group. Local contexts enter no MPI.
Eigen::VectorXd nextSmoothedCurvatureDirection(const SmoothedCurvatureSpectrum& spectrum, Eigen::Index k)
The direction to measure for the k-th eigenvalue: the part of its posterior mode outside the measured span, normalized. Empty when the mode lies in the span to floating-point resolution, in which case no further column changes the eigenvalue’s first-order posterior.
double measuredUpperBound(const SmoothedCurvatureSpectrum& spectrum, const std::vector<MeasuredHessianColumn>& columns, Eigen::Index k)
Bauer-Fike verdict on a mode: with u in the measured span, H u is a combination of measured columns, the Rayleigh quotient theta and the residual ||H u - theta u|| are measured, and some eigenvalue of H lies within the residual of theta (Bauer 1960, Parlett 1998 Thm 4.5.1). The upper bound theta + ||r|| below zero certifies a negative eigenvalue from measurements alone. Returns the bound; +infinity when the mode leaves the measured span beyond floating-point resolution.
Eigen::VectorXd softestUnmeasuredDirection(const SmoothedCurvatureSpectrum& spectrum)
The softest direction of the posterior mean restricted to the unmeasured complement, normalized; empty when nothing is unmeasured.
Eigen::Index coarseColumnToRefine(const SmoothedCurvatureSpectrum& spectrum, const std::vector<MeasuredHessianColumn>& columns, Eigen::Index k)
The coarse column with the largest overlap with the k-th posterior mode, the one whose refinement most reduces that eigenvalue’s spread; -1 when every overlapping column is refined already.
Eigen::VectorXd spectralResidualStep(const Eigen::VectorXd& eigenvalues, const Eigen::MatrixXd& modes, const Eigen::VectorXd& gradient, double radius)
Minimize ||g + H s||^2 within a Euclidean trust radius on a supplied orthonormal Hessian spectrum. The normal equations give s_i = -lambda_i g_i / (lambda_i^2 + shift), with shift >= 0. This is a local force-root proposal; the measured saddle index decides whether a converged root belongs to the saddle search.
SpectralTrustRegionStep spectralTrustRegionStep(const Eigen::VectorXd& curvatures, const Eigen::MatrixXd& modes, Eigen::Index mode_index, const Eigen::VectorXd& force, double radius, const std::vector<std::pair<Eigen::VectorXd, double>>& measured_negative)
The exact trust-region minimizer (More and Sorensen 1983) of the modified quadratic model m(s) = -F.s + s^T M s / 2 with M = sum_k mu_k q_k q_k^T on the eigenbasis ~modes~ (columns) with ~curvatures~, the selected curvature reversed (Banerjee 1985; Baker 1986). A transverse mode with nonpositive curvature has no minimizer and is left out unless a direction in ~measured_negative~ (Cartesian direction, measured curvature) covers it by majority overlap, in which case its measured curvature enters and the step descends along it to the boundary. The Levenberg shift is solved on the secular equation so the step lies within ~radius~.
double measuredCubicColumnContribution(double overlap, double mode_quadratic, double axis_quadratic)
Contribution of a measured axis u to the cubic along v. The measured gradient second difference supplies T[u,u]; overlap is u dot v. Summing over orthonormal measured axes retains every symmetric cubic coefficient with a repeated axis index. Coefficients with three distinct unmeasured index combinations are zero in this model; two axes determine a full bivariate cubic. Reversing u preserves this contribution, while reversing v reverses its sign.
double axisStencilDirectionalCubic(const Eigen::MatrixXd& axes, const Eigen::MatrixXd& second_differences, const Eigen::VectorXd& mode)
Cubic coefficient along mode from measured axis stencils: column j of second_differences is the gradient second difference along the orthonormal axis u_j (column j of axes), that is T[u_j, u_j, .]. The sum of measuredCubicColumnContribution over the axes is odd in the mode, as the cubic coefficient is, so a mode and its negative give opposite signs.
Eigen::MatrixXd massWeightedRigidMotions(const Eigen::VectorXd& positions, const Eigen::VectorXd& masses)
Mass-weighted translations and rotations as columns, about the centre of mass.
Eigen::MatrixXd vibrationalComplement(const Eigen::VectorXd& positions, const Eigen::VectorXd& masses)
Orthonormal basis of the mass-weighted coordinates orthogonal to the rigid motions at positions : the left singular vectors of the rigid basis beyond its numerical rank (five for a linear molecule, six otherwise).
StencilIndex analyzeStencilIndex(const Eigen::MatrixXd& columns, const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, const Eigen::MatrixXd* measured = nullptr)
columns holds the Cartesian Hessian actions: column j is the central difference of the gradient along Cartesian coordinate j. measured, when it has fewer orthonormal Cartesian columns than there are coordinates, names the directions the stencil displaced along; the other columns of columns were rebuilt, not measured. The resolution is then the antisymmetric norm of the mass-weighted block on the image sqrt(M) measured, which reads only the measured columns. The spectrum is the vibrational complement’s when the image contains it (a free molecule, whose image it is, or a periodic cell, whose image adds the rotations), and otherwise the image’s own block (the moving coordinates of a geometry with frozen atoms). Either block reads only measured columns.
template <typename Gradients>
RefinedWeakModes refineWeakModes(const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, const Eigen::MatrixXd& weak, double step, const Gradients& gradients, double noise_multiplier = 0.0)
weak holds mass-weighted mode columns. gradients takes Cartesian positions as columns and returns their gradients as rows, so the host can evaluate the whole batch at once.
The difference of the two stencils estimates truncation only when the oracle is exact. With gradient noise of standard deviation s in each coarse curvature, the half step doubles it, the difference has standard deviation sqrt(5) s and the Richardson value sqrt(65)/3 s, so one third of the absolute coarse-minus-fine difference understates the error of the Richardson value by a factor of about 3.6. A positive noise_multiplier m adds m times the root mean square of the coarse-minus-fine curvatures, pooled over the refined modes, to every entry of the error envelope. m = 3.6 is three standard deviations of the Richardson value when the differences are noise.
double rotatedPositiveRestrictionLowerBound(const Eigen::MatrixXd& block, const Eigen::MatrixXd& errors, const Eigen::MatrixXd& coupling, const Eigen::VectorXd& tail, double allowance)
A second comparison bound in the eigenbasis of the weak block. For abs(D) <= E, and abs(U^T D U) <= abs(U)^T E abs(U); the complete tail coupling is bounded by C abs(U). The Gram defect accounts for a computed rotation that is not exactly orthogonal. All bounds remain conditional on E.
template <typename Gradients>
StencilIndexCertificate certifyStencilIndex(const StencilIndex& index, const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, double step, const Gradients& gradients, Eigen::Index minimum_weak = 0, double noise_multiplier = 0.0)
Refine unresolved modes in one batch and retain the complete positive restriction, including its coupling to the resolved complement. The same comparison matrix determines the independent validation’s bound.
template <typename Gradients>
MeasuredIndexDecision decideMeasuredIndex(const Eigen::MatrixXd& columns, const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, double step, const Gradients& gradients, const Eigen::MatrixXd* measured = nullptr)
measured is analyzeStencilIndex’s.
double defaultStencilStep()
Cartesian displacement of a central-difference stencil when the caller names none, in the coordinate unit. A stencil on a learned potential needs a step that keeps the noise of the gradient below the curvature it resolves; 0.01 A does so for the potentials the drivers support.
double stencilStepOrDefault(double requested)
The requested stencil step, or the default when none was requested.
int forceStopAdaptiveStepReductions()
Step halvings while a weak block’s error keeps falling. Truncation error shrinks with the step, so an unbounded loop chases it to underflow without ever signing the mode.
template <typename Gradients>
StencilIndexCertificate certifyAdaptiveStencilIndex(const StencilIndex& index, const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, double step, const Gradients& gradients, double noise_multiplier = 0.0)
Refine the uncertainty that prevents a terminal decision. A weak block whose own sign is unresolved gets a smaller stencil; a positive weak block coupled to an unresolved complement gets another measured mode. Identical Cartesian requests reuse their measured gradients. A smaller step must reduce the whole weak-block error before another reduction is tried; one positive Rayleigh bound does not resolve that block’s sign.
bool forceStopMeasurementInconclusiveOrHigher(const ForceStopMeasurement& measured)
A measured stencil that is not index-one. Higher-order and unresolved both qualify: neither certifies the stopped geometry.
int forceStopSoftRefinementLimit()
How many soft-mode refinements follow a higher-order stencil. One walk, then a fresh stencil. A second walk was still higher-order on the cells that needed an escape, and it paid another full stencil.
int forceStopRefinementCertified()
refine returns this when the soft-mode walk itself reached an index-one point inside the force tolerance. The certificate accepts that point. Another full stencil is not started: the walk already measured the modes, and a fresh 3N stencil after the report line is what kept a converged search from printing its call total.
int forceStopRefinementStillHigher()
refine returns this when the soft-mode walk is still higher-order. The low modes were measured, so another full Cartesian stencil is not started. The certificate refines again or leaves along the extra mode.
bool sameStencilGeometry(const Eigen::VectorXd& first, const Eigen::VectorXd& second)
Two geometries share one stencil when a later request has not moved.
int forceStopMinModeEscapes()
Min-mode escapes after a higher-order certificate, for every search.
bool forceStopCertificatePlanned(const ForceStopStencilPlan& plan)
True when the plan spends evaluations on an index certificate at this stage: a stencil to measure, or stored columns to read.
Eigen::Index forceStopHeldColumn(const Eigen::MatrixXd& held, const Eigen::VectorXd& query, double relative = 1e-6)
True when query is a column already stored at held. A later certificate at an unchanged geometry uses the stored gradient.
Eigen::MatrixXd forceStopLowestModes(const Eigen::MatrixXd& columns, const Eigen::VectorXd& positions, const Eigen::VectorXd& masses, Eigen::Index count, const Eigen::MatrixXd* measured = nullptr)
Lowest Cartesian modes of a measured Hessian, lowest curvature first. measured is analyzeStencilIndex’s.
bool forceStopStencilCertifies(bool measured, bool first_order)
An unmeasured stop is uncertified. 0fa3c694 returned there. Certification is the measured stencil reporting one negative mode.
template <typename Measure, typename Refine>
ForceStopCertificateResult runForceStopCertificate(Measure measure, Refine refine, ForceStopStencilPlan plan, const ForceStopMeasurement* prior = nullptr)
One certificate for every search. measure reads one stencil at the stopped geometry. refine moves only along the soft modes of a higher-order stencil. It returns a negative value when it cannot, forceStopRefinementStillHigher() when the low modes are still higher-order and a full stencil would only repeat that, forceStopRefinementCertified() when the walk reached an index-one point inside the force tolerance, and a positive call count when the point has to be measured again. A higher-order result that survives that walk sets needs_min_mode_escape. The force loop is not resumed. A following saddle defers the stencil. A prior measurement at this geometry is the hand-off: its columns are not requested again, and an inconclusive or higher-order reading is given to that saddle.
double maxAtomDisplacement(const Eigen::VectorXd& delta)
Largest displacement of one atom, with a short coordinate tail counted as a final group.