class gpr::TrustRadius¶
Overview¶
Trust radius enforcement for GP surrogate models. More…
#include <gpr/ml/TrustRadius.h>
class TrustRadius {
public:
// construction
TrustRadius();
// methods
void setTrainingData(const EigenMatrix& R_train);
void setAtomsConfiguration(const AtomsConfiguration& atoms_config);
void setDistanceMetric(DistanceMetricType metric);
double distanceToTraining(const Eigen::VectorXd& x_new) const;
bool isWithinTrust(const Eigen::VectorXd& x_new, double radius) const;
bool projectLineToTrustBoundary(const Eigen::VectorXd& x_current, const Eigen::VectorXd& x_trial, double radius, Eigen::VectorXd& x_projected) const;
double certifiedLineStep(const Eigen::VectorXd& x_from, const Eigen::VectorXd& x_to, double radius) const;
std::vector<int> kNearestIndices(const Eigen::VectorXd& x_new, int k) const;
int nTraining() const;
};
Detailed Documentation¶
Trust radius enforcement for GP surrogate models.
Stores training data positions and provides distance queries and displacement clipping relative to a trust radius boundary.
Methods¶
void setTrainingData(const EigenMatrix& R_train)
Store training positions for distance queries.
Parameters:
R_train |
Matrix of training positions (n_samples x dim). Each row is one training point. |
void setAtomsConfiguration(const AtomsConfiguration& atoms_config)
Store atomic metadata for permutation-aware distance metrics.
void setDistanceMetric(DistanceMetricType metric)
Select the atomic distance metric for trust checks.
Calling this switches distanceToTraining away from Euclidean vector norm.
double distanceToTraining(const Eigen::VectorXd& x_new) const
Minimum Euclidean distance from x_new to any training point.
Parameters:
x_new |
Query point |
Returns:
Minimum distance (infinity if no training data)
bool isWithinTrust(const Eigen::VectorXd& x_new, double radius) const
Check whether x_new is within the trust radius of training data.
Parameters:
x_new |
Query point |
radius |
Trust radius threshold |
Returns:
True if distanceToTraining(x_new) <= 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.
The configured distance metric defines the metric ball. If x_trial is outside radius and x_current is inside radius, this returns the largest point on the line segment x_current + alpha * (x_trial - x_current), alpha in [0,1], that remains inside the trust set. For the EMD metric (and the plain Euclidean fallback with no atomic metric configured) alpha is the closed-form certifiedLineStep bound, evaluated once. For RMSD/MAX_1D_LOG, where that Lipschitz certificate is not established, this falls back to mantissa-width bisection.
Returns:
true when x_projected was moved to a boundary point; false when no projection was needed or no trusted anchor exists.
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, without bisection.
Along x(t) = x_from + t * (x_to - x_from), the configured distance metric is Lipschitz in t: d(x(t)) <= d(x_from) + t * L(step), where L(step) is the EMD rate: the maximum over atom types T of the mean displacement norm within T (per-atom triangle inequality, grouped by type exactly as dist_emd) for the EMD metric, or ||step||_2 for the plain Euclidean fallback. Solving d(x(t*)) <= radius for the worst case gives t* = clamp((radius - d(x_from)) / L(step), 0, 1), which is a conservative (never unsafe) certificate: the true boundary may sit further along the segment, since a specific training-row assignment can only move less than the worst-case bound.
The certificate only bounds an INCREASE in distance along the segment: when x_from itself is already outside radius, t* evaluates to 0 rather than certifying any recovery. Callers must check distanceToTraining(x_from) <= radius themselves if they need that distinction.
Returns 0.0 for RMSD/MAX_1D_LOG (no such rate is established for those metrics), for non-finite radius/distances, or for mismatched x_from/x_to sizes.
Returns:
Certified alpha in [0, 1].
std::vector<int> kNearestIndices(const Eigen::VectorXd& x_new, int k) const
Indices of the k training points nearest to x_new.
Ranks every stored training row by the configured distance metric (EMD/RMSD/MAX_1D_LOG with an AtomsConfiguration, or the Euclidean vector norm otherwise) and returns the indices of the k smallest, sorted ascending so the result is a stable set. The result has min(k, nTraining()) entries; it is empty when there is no training data.
Parameters:
x_new |
Query point |
k |
Neighbourhood size |
Returns:
Ascending-sorted row indices of the k nearest points