.. index:: pair: namespace; gpr::derivatives .. _doxid-namespacegpr_1_1derivatives: namespace gpr::derivatives ========================== .. toctree:: :hidden: namespace_gpr_derivatives_generated.rst enum_gpr_derivatives_MeanDerivativeMethod.rst enum_gpr_derivatives_RadialProfile.rst struct_gpr_derivatives_FiniteDifferenceOptions.rst struct_gpr_derivatives_Lift.rst struct_gpr_derivatives_Lift-2.rst struct_gpr_derivatives_OperationCounts.rst struct_gpr_derivatives_RadialMeanExpansion.rst class_gpr_derivatives_CountedReal.rst class_gpr_derivatives_DerivativeProvider.rst Overview ~~~~~~~~ .. ref-code-block:: cpp :class: doxyrest-overview-code-block namespace derivatives { // namespaces namespace :ref:`gpr::derivatives::generated`; // typedefs typedef Eigen::VectorXd :target:`Vector`; typedef Eigen::MatrixXd :target:`Matrix`; typedef std::function`&, :ref:`Vector`&)> :target:`HessianAction`; typedef std::function<:ref:`HessianAction`(const :ref:`Vector`&)> :target:`HessianPreparation`; typedef std::function`&, :ref:`Vector`&)> :target:`ForceFunction`; // enums enum :ref:`MeanDerivativeMethod`; enum :ref:`RadialProfile`; // structs struct :ref:`FiniteDifferenceOptions`; template struct :ref:`Lift`; template struct :ref:`Lift>`; struct :ref:`OperationCounts`; struct :ref:`RadialMeanExpansion`; // classes class :ref:`CountedReal`; class :ref:`DerivativeProvider`; // global variables bool :target:`kEnzymeToolchainDetected` = false; bool :ref:`kEnzymeDerivativeProviderAvailable` = false; // global functions :ref:`OperationCounts`& :target:`operationCounts`(); double :target:`plainValue`(double x); double :target:`plainValue`(const :ref:`CountedReal`& x); :ref:`DerivativeProvider` :ref:`makeAnalyticDerivativeProvider`(:ref:`HessianPreparation` prepare); double :ref:`coordinateCharacteristicScale`(Eigen::Index column, const :ref:`FiniteDifferenceOptions`& options = {}); bool :ref:`coordinateCharacteristicScale`(Eigen::Index column, double& result, const :ref:`FiniteDifferenceOptions`& options = {}, std::string* reason = nullptr); double :ref:`finiteDifferenceCoordinateStep`(const :ref:`Vector`& position, Eigen::Index column, const :ref:`FiniteDifferenceOptions`& options = {}); bool :ref:`finiteDifferenceCoordinateStep`(const :ref:`Vector`& position, Eigen::Index column, double& result, const :ref:`FiniteDifferenceOptions`& options = {}, std::string* reason = nullptr); double :ref:`finiteDifferenceDirectionStep`(const :ref:`Vector`& position, const :ref:`Vector`& direction, const :ref:`FiniteDifferenceOptions`& options = {}); bool :ref:`finiteDifferenceDirectionStep`(const :ref:`Vector`& position, const :ref:`Vector`& direction, double& result, const :ref:`FiniteDifferenceOptions`& options = {}, std::string* reason = nullptr); :ref:`DerivativeProvider` :ref:`makeFiniteDifferenceForceProvider`(:ref:`ForceFunction` force, :ref:`FiniteDifferenceOptions` options = {}); :ref:`DerivativeProvider` :ref:`makeEnzymeDerivativeProvider`(const :ref:`ForceFunction`&); template T :target:`lift`(const Value& value); double :target:`nestedAtan2`(double y, double x); template Eigen::AutoDiffScalar<:ref:`Derivatives`> :ref:`nestedAtan2`(const Eigen::AutoDiffScalar<:ref:`Derivatives`>& y, const Eigen::AutoDiffScalar<:ref:`Derivatives`>& x); template bool :ref:`radialMeanGradient`(const :ref:`RadialMeanExpansion`& expansion, :ref:`MeanDerivativeMethod` method, const detail::RealVector& q, detail::RealVector& gradient); template bool :ref:`radialMeanHessianVector`(const :ref:`RadialMeanExpansion`& expansion, :ref:`MeanDerivativeMethod` method, const detail::RealVector& q, const detail::RealVector& u, detail::RealVector& action); template bool :ref:`radialMeanHessian`(const :ref:`RadialMeanExpansion`& expansion, :ref:`MeanDerivativeMethod` method, const detail::RealVector& q, detail::RealMatrix& hessian); bool :ref:`radialMeanCartesianHessianVector`(const :ref:`RadialMeanExpansion`& expansion, :ref:`MeanDerivativeMethod` method, const Eigen::VectorXd& q, const Eigen::MatrixXd& jacobian, const Eigen::VectorXd& v, Eigen::VectorXd& action); } // namespace derivatives .. _details-namespacegpr_1_1derivatives: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ Global Variables ---------------- .. index:: pair: variable; kEnzymeDerivativeProviderAvailable .. _doxid-namespacegpr_1_1derivatives_1a56f5727936d1168bdc858a41915ca621: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool kEnzymeDerivativeProviderAvailable = false The Enzyme bridge is unavailable until its ABI is pinned. Global Functions ---------------- .. index:: pair: function; makeAnalyticDerivativeProvider .. _doxid-namespacegpr_1_1derivatives_1a944cef32110486ef5b37163868202f17: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`DerivativeProvider` makeAnalyticDerivativeProvider(:ref:`HessianPreparation` prepare) Adapt an analytic Hessian preparation, such as a fitted GP posterior. .. index:: pair: function; coordinateCharacteristicScale .. _doxid-namespacegpr_1_1derivatives_1acc888e353e315df2fe9fa05378bfa865: .. ref-code-block:: cpp :class: doxyrest-title-code-block double coordinateCharacteristicScale(Eigen::Index column, const :ref:`FiniteDifferenceOptions`& options = {}) Characteristic coordinate length floor scale_i for column. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - std::invalid_argument - if a configured scale is non-finite or not positive. * - std::out_of_range - if column is negative or not represented by coordinateScales. .. index:: pair: function; coordinateCharacteristicScale .. _doxid-namespacegpr_1_1derivatives_1a247adfda631ab8e81152676d79b68691: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool coordinateCharacteristicScale(Eigen::Index column, double& result, const :ref:`FiniteDifferenceOptions`& options = {}, std::string* reason = nullptr) Non-throwing characteristic-scale query. On failure, returns false, resets result to zero and records the validation error through reason when provided. .. index:: pair: function; finiteDifferenceCoordinateStep .. _doxid-namespacegpr_1_1derivatives_1a88d2ac68bb5d3ac7d2df193dcfce07f4: .. ref-code-block:: cpp :class: doxyrest-title-code-block double finiteDifferenceCoordinateStep(const :ref:`Vector`& position, Eigen::Index column, const :ref:`FiniteDifferenceOptions`& options = {}) Per-coordinate central-difference step h_i = h_0 \* max(abs(x_i), scale_i). .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - std::invalid_argument - if position or an option is invalid, or if coordinateScales does not match position. * - std::out_of_range - if column does not index position. .. index:: pair: function; finiteDifferenceCoordinateStep .. _doxid-namespacegpr_1_1derivatives_1a6a6104177b88b73b6d8b7faafd560b49: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool finiteDifferenceCoordinateStep(const :ref:`Vector`& position, Eigen::Index column, double& result, const :ref:`FiniteDifferenceOptions`& options = {}, std::string* reason = nullptr) Non-throwing per-coordinate step query. On failure, returns false, resets result to zero and records the validation error through reason when provided. .. index:: pair: function; finiteDifferenceDirectionStep .. _doxid-namespacegpr_1_1derivatives_1aeb5f1c6ffb7d9226f3115bd9c4c1e854: .. ref-code-block:: cpp :class: doxyrest-title-code-block double finiteDifferenceDirectionStep(const :ref:`Vector`& position, const :ref:`Vector`& direction, const :ref:`FiniteDifferenceOptions`& options = {}) Directional central-difference step h = (h_0 / M) max(1, cbrt(||x||_2 M / 4)), where u is the normalized direction, M = max_i(abs(u_i) / max(abs(x_i), scale_i)) and h_0 is relativeStep. The base step h_0 / M moves the coordinate with the largest weight by h_0 max(abs(x_i), scale_i). It ignores the spacing of the floating-point numbers near x. The stencil F(x + h u) - F(x - h u) is formed from fl(x + h u) and fl(x - h u), which differ from x +- h u by at most (epsilon / 2) abs(x_i) per coordinate, so the displacement 2 h u carries an error r with ||r||_2 <= epsilon ||x||_2. Relative to ||2 h u||_2 = 2 h that is epsilon ||x||_2 / (2 h). It is a property of the whole vector, so it is bounded and continuous in u; a small component of u on a coordinate of order one does not enter it. The truncation error of the stencil is (h M)^2. Their sum E(h) = (h M)^2 + epsilon ||x||_2 / (2 h) has E'(h) = 2 h M^2 - epsilon ||x||_2 / (2 h^2), which vanishes where 4 M^2 h^3 = epsilon ||x||_2, and E''(h) = 6 M^2 > 0 there, so the minimum is h_r = cbrt(epsilon ||x||_2 / (4 M^2)). With the default h_0 = cbrt(epsilon) the base step is cbrt(epsilon) / M, and h_r / (cbrt(epsilon) / M) = cbrt(||x||_2 M / 4). The step is the base step times the larger of 1 and that ratio. At the default h_0 it equals max(cbrt(epsilon) / M, h_r). For another h_0 the whole step scales with h_0, so the steps h and 2 h of a Richardson comparison differ by exactly the factor 2 that it assumes. ||x||_2 M exceeds 4 only when the large coordinates carry little of the direction, the case in which the base step leaves the displacement of a large coordinate below the floating-point spacing and the stencil drops it. Position, direction and options are validated once per call. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - std::invalid_argument - if position, direction, or an option is invalid, or if coordinateScales does not match position. .. index:: pair: function; finiteDifferenceDirectionStep .. _doxid-namespacegpr_1_1derivatives_1a78b4b7a7de7556db2161adf5ad975ab1: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool finiteDifferenceDirectionStep(const :ref:`Vector`& position, const :ref:`Vector`& direction, double& result, const :ref:`FiniteDifferenceOptions`& options = {}, std::string* reason = nullptr) Non-throwing directional step query. On failure, returns false, resets result to zero and records the validation error through reason when provided. .. index:: pair: function; makeFiniteDifferenceForceProvider .. _doxid-namespacegpr_1_1derivatives_1a9c2f259ea382cb1d3f0576ebc4fe98ac: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`DerivativeProvider` makeFiniteDifferenceForceProvider(:ref:`ForceFunction` force, :ref:`FiniteDifferenceOptions` options = {}) Central differences of a physical force F=-grad(E). Steps are relative to each coordinate for a full Hessian and to the direction-weighted characteristic scale for an HVP. The representable displacement, rather than twice the requested step, is used as the denominator. .. index:: pair: function; makeEnzymeDerivativeProvider .. _doxid-namespacegpr_1_1derivatives_1ac21fd996fbd4bc4f79004a8a322006a9: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`DerivativeProvider` makeEnzymeDerivativeProvider(const :ref:`ForceFunction`&) Reserved source-compatible factory for the optional Enzyme bridge. .. index:: pair: function; nestedAtan2 .. _doxid-namespacegpr_1_1derivatives_1ab2f0b04278539ed3ade82b55261bc154: .. ref-code-block:: cpp :class: doxyrest-title-code-block template Eigen::AutoDiffScalar<:ref:`Derivatives`> nestedAtan2(const Eigen::AutoDiffScalar<:ref:`Derivatives`>& y, const Eigen::AutoDiffScalar<:ref:`Derivatives`>& x) atan2 that keeps the derivative type of its arguments; :ref:`Eigen ` 's overload returns a dynamically sized derivative that does not nest. .. index:: pair: function; radialMeanGradient .. _doxid-namespacegpr_1_1derivatives_1a4ed46927fac5f3a4443de1779391a323: .. ref-code-block:: cpp :class: doxyrest-title-code-block template bool radialMeanGradient(const :ref:`RadialMeanExpansion`& expansion, :ref:`MeanDerivativeMethod` method, const detail::RealVector& q, detail::RealVector& gradient) Gradient of m at q. False on invalid input or a non-finite result, which a Matern profile produces at an exact centre where its derivative with gradient weights is undefined. HyperDual and Jet need Real = double and return false for a counting scalar. .. index:: pair: function; radialMeanHessianVector .. _doxid-namespacegpr_1_1derivatives_1a9c61e7c7acd9934b81ad8a05a31aac19: .. ref-code-block:: cpp :class: doxyrest-title-code-block template bool radialMeanHessianVector(const :ref:`RadialMeanExpansion`& expansion, :ref:`MeanDerivativeMethod` method, const detail::RealVector& q, const detail::RealVector& u, detail::RealVector& action) Hessian of m at q applied to u. False as for radialMeanGradient. .. index:: pair: function; radialMeanHessian .. _doxid-namespacegpr_1_1derivatives_1ab412cf576caab7b3051ae7e4b8e6c471: .. ref-code-block:: cpp :class: doxyrest-title-code-block template bool radialMeanHessian(const :ref:`RadialMeanExpansion`& expansion, :ref:`MeanDerivativeMethod` method, const detail::RealVector& q, detail::RealMatrix& hessian) Full Hessian of m at q. False as for radialMeanGradient. .. index:: pair: function; radialMeanCartesianHessianVector .. _doxid-namespacegpr_1_1derivatives_1a0657e3b22d898f16723259e3bf2e03d8: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool radialMeanCartesianHessianVector(const :ref:`RadialMeanExpansion`& expansion, :ref:`MeanDerivativeMethod` method, const Eigen::VectorXd& q, const Eigen::MatrixXd& jacobian, const Eigen::VectorXd& v, Eigen::VectorXd& action) Cartesian pullback J^T H (J v) of the descriptor Hessian. The descriptor curvature term sum_k (grad m)_k D^2 q_k is the caller's: it does not depend on the kernel derivative method.