Loading...
Searching...
No Matches
TrustRadius.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3// See LICENSE for details.
4
17
18#ifndef GPR_ML_TRUSTRADIUS_H_
19#define GPR_ML_TRUSTRADIUS_H_
20
21#include <Eigen/Dense>
22#include <vector>
23
26#include "../Enums.h"
27
28namespace gpr {
29
37public:
38 TrustRadius() = default;
39
46 void setTrainingData(const EigenMatrix& R_train);
47
51 void setAtomsConfiguration(const AtomsConfiguration& atoms_config);
52
59
66 double distanceToTraining(const Eigen::VectorXd& x_new) const;
67
75 bool isWithinTrust(const Eigen::VectorXd& x_new, double radius) const;
76
93 bool projectLineToTrustBoundary(const Eigen::VectorXd& x_current,
94 const Eigen::VectorXd& x_trial,
95 double radius,
96 Eigen::VectorXd& x_projected) const;
97
126 double certifiedLineStep(const Eigen::VectorXd& x_from,
127 const Eigen::VectorXd& x_to, double radius) const;
128
143 std::vector<int> kNearestIndices(const Eigen::VectorXd& x_new, int k) const;
144
145 int nTraining() const
146 {
147 return static_cast<int>(R_train_.rows());
148 }
149
150private:
151 // EMD Lipschitz rate of a displacement: max_T (1/size(T)) sum_{i in T}
152 // ||step_i||, grouped by atoms_config_.atoms_mov.type the same way
153 // Distance::dist_emd groups its cost matrix. Falls back to the whole
154 // step's Euclidean norm when the type index does not line up with the
155 // step size: by Cauchy-Schwarz, (1/size(T)) sum_{i in T} ||step_i|| <=
156 // ||step_T||_2 <= ||step||_2 for any size(T) >= 1, so the whole-vector norm
157 // is always a valid, if looser, upper bound.
158 double emdLipschitzRate(const Eigen::VectorXd& step) const;
159
160 EigenMatrix R_train_; // (n_samples x dim)
161 AtomsConfiguration atoms_config_;
163 bool use_atomic_metric_ = false;
164 bool has_atoms_config_ = false;
165};
166
167} // namespace gpr
168
169#endif // GPR_ML_TRUSTRADIUS_H_
DistanceMetricType
Definition Enums.h:46
TrustRadius()=default
bool isWithinTrust(const Eigen::VectorXd &x_new, double radius) const
Check whether x_new is within the trust radius of training data.
double distanceToTraining(const Eigen::VectorXd &x_new) const
Minimum Euclidean distance from x_new to any training point.
std::vector< int > kNearestIndices(const Eigen::VectorXd &x_new, int k) const
Indices of the k training points nearest to x_new.
int nTraining() const
void setDistanceMetric(DistanceMetricType metric)
Select the atomic distance metric for trust checks.
double certifiedLineStep(const Eigen::VectorXd &x_from, const Eigen::VectorXd &x_to, double radius) const
Largest certified fraction of the segment x_from -> x_to that stays within the trust radius,...
bool projectLineToTrustBoundary(const Eigen::VectorXd &x_current, const Eigen::VectorXd &x_trial, double radius, Eigen::VectorXd &x_projected) const
Project a trial point along a line segment to the trust boundary.
void setTrainingData(const EigenMatrix &R_train)
Store training positions for distance queries.
void setAtomsConfiguration(const AtomsConfiguration &atoms_config)
Store atomic metadata for permutation-aware distance metrics.
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition Macros.h:16
Eigen::Matrix< double, EigenDynamic, EigenDynamic, EigenMatrixStorage > EigenMatrix
Definition Macros.h:20
Stores configurations of all atoms in the system.
Definition Structures.h:832