.. index:: pair: class; gpr::TrustRadius .. _doxid-classgpr_1_1_trust_radius: class gpr::TrustRadius ====================== .. toctree:: :hidden: Overview ~~~~~~~~ Trust radius enforcement for GP surrogate models. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include class TrustRadius { public: // construction :target:`TrustRadius`(); // methods void :ref:`setTrainingData`(const :ref:`EigenMatrix`& R_train); void :ref:`setAtomsConfiguration`(const :ref:`AtomsConfiguration`& atoms_config); void :ref:`setDistanceMetric`(:ref:`DistanceMetricType` metric); double :ref:`distanceToTraining`(const Eigen::VectorXd& x_new) const; bool :ref:`isWithinTrust`(const Eigen::VectorXd& x_new, double radius) const; bool :ref:`projectLineToTrustBoundary`(const Eigen::VectorXd& x_current, const Eigen::VectorXd& x_trial, double radius, Eigen::VectorXd& x_projected) const; double :ref:`certifiedLineStep`(const Eigen::VectorXd& x_from, const Eigen::VectorXd& x_to, double radius) const; std::vector :ref:`kNearestIndices`(const Eigen::VectorXd& x_new, int k) const; int :target:`nTraining`() const; }; .. _details-classgpr_1_1_trust_radius: 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 ------- .. index:: pair: function; setTrainingData .. _doxid-classgpr_1_1_trust_radius_1ad5390a52cdbcccc66b72ee4536bff3cf: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setTrainingData(const :ref:`EigenMatrix`& R_train) Store training positions for distance queries. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - R_train - Matrix of training positions (n_samples x dim). Each row is one training point. .. index:: pair: function; setAtomsConfiguration .. _doxid-classgpr_1_1_trust_radius_1af1f3bd5462f40895317237e3c3469f6f: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setAtomsConfiguration(const :ref:`AtomsConfiguration`& atoms_config) Store atomic metadata for permutation-aware distance metrics. .. index:: pair: function; setDistanceMetric .. _doxid-classgpr_1_1_trust_radius_1a4e7ea209d1bdf644529e0a64409a6680: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setDistanceMetric(:ref:`DistanceMetricType` metric) Select the atomic distance metric for trust checks. Calling this switches distanceToTraining away from Euclidean vector norm. .. index:: pair: function; distanceToTraining .. _doxid-classgpr_1_1_trust_radius_1a18d755bc04330ea1ad05230525a21ae4: .. ref-code-block:: cpp :class: doxyrest-title-code-block double distanceToTraining(const Eigen::VectorXd& x_new) const Minimum Euclidean distance from x_new to any training point. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - x_new - Query point .. rubric:: Returns: Minimum distance (infinity if no training data) .. index:: pair: function; isWithinTrust .. _doxid-classgpr_1_1_trust_radius_1a13287a72025fe7c8cf507fd4f01d8772: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool isWithinTrust(const Eigen::VectorXd& x_new, double radius) const Check whether x_new is within the trust radius of training data. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - x_new - Query point * - radius - Trust radius threshold .. rubric:: Returns: True if distanceToTraining(x_new) <= radius .. index:: pair: function; projectLineToTrustBoundary .. _doxid-classgpr_1_1_trust_radius_1a7cb1b0972e95839ac57ff335fc247506: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool projectLineToTrustBoundary(const Eigen::VectorXd& x_current, const Eigen::VectorXd& x_trial, double radius, Eigen::VectorXd& x_projected) const :ref:`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. .. rubric:: Returns: true when ``x_projected`` was moved to a boundary point; false when no projection was needed or no trusted anchor exists. .. index:: pair: function; certifiedLineStep .. _doxid-classgpr_1_1_trust_radius_1a4f7507bb86816884d5372644bfd2f4e0: .. ref-code-block:: cpp :class: doxyrest-title-code-block 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 :ref:`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. .. rubric:: Returns: Certified alpha in [0, 1]. .. index:: pair: function; kNearestIndices .. _doxid-classgpr_1_1_trust_radius_1a20cfdc83e4f816cdc3f10401f6abe947: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::vector 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 :ref:`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. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - x_new - Query point * - k - Neighbourhood size .. rubric:: Returns: Ascending-sorted row indices of the k nearest points