namespace gpr::derivatives

Overview

namespace derivatives {
 
// namespaces
 
namespace gpr::derivatives::generated;
 
// typedefs
 
typedef Eigen::VectorXd Vector;
typedef Eigen::MatrixXd Matrix;
typedef std::function<bool(const Vector&, Vector&)> HessianAction;
typedef std::function<HessianAction(const Vector&)> HessianPreparation;
typedef std::function<bool(const Vector&, Vector&)> ForceFunction;
 
// enums
 
enum MeanDerivativeMethod;
enum RadialProfile;
 
// structs
 
struct FiniteDifferenceOptions;
 
template <typename T>
struct Lift;
 
template <typename Derivatives>
struct Lift<Eigen::AutoDiffScalar<Derivatives>>;
 
struct OperationCounts;
struct RadialMeanExpansion;
 
// classes
 
class CountedReal;
class DerivativeProvider;
 
// global variables
 
bool kEnzymeToolchainDetected = false;
bool kEnzymeDerivativeProviderAvailable = false;
 
// global functions
 
OperationCounts& operationCounts();
double plainValue(double x);
double plainValue(const CountedReal& x);
DerivativeProvider makeAnalyticDerivativeProvider(HessianPreparation prepare);
double coordinateCharacteristicScale(Eigen::Index column, const FiniteDifferenceOptions& options = {});
bool coordinateCharacteristicScale(Eigen::Index column, double& result, const FiniteDifferenceOptions& options = {}, std::string* reason = nullptr);
double finiteDifferenceCoordinateStep(const Vector& position, Eigen::Index column, const FiniteDifferenceOptions& options = {});
bool finiteDifferenceCoordinateStep(const Vector& position, Eigen::Index column, double& result, const FiniteDifferenceOptions& options = {}, std::string* reason = nullptr);
double finiteDifferenceDirectionStep(const Vector& position, const Vector& direction, const FiniteDifferenceOptions& options = {});
bool finiteDifferenceDirectionStep(const Vector& position, const Vector& direction, double& result, const FiniteDifferenceOptions& options = {}, std::string* reason = nullptr);
DerivativeProvider makeFiniteDifferenceForceProvider(ForceFunction force, FiniteDifferenceOptions options = {});
DerivativeProvider makeEnzymeDerivativeProvider(const ForceFunction&);
 
template <typename T, typename Value>
T lift(const Value& value);
 
double nestedAtan2(double y, double x);
 
template <typename Derivatives>
Eigen::AutoDiffScalar<Derivatives> nestedAtan2(const Eigen::AutoDiffScalar<Derivatives>& y, const Eigen::AutoDiffScalar<Derivatives>& x);
 
template <typename Real = double>
bool radialMeanGradient(const RadialMeanExpansion& expansion, MeanDerivativeMethod method, const detail::RealVector<Real>& q, detail::RealVector<Real>& gradient);
 
template <typename Real = double>
bool radialMeanHessianVector(const RadialMeanExpansion& expansion, MeanDerivativeMethod method, const detail::RealVector<Real>& q, const detail::RealVector<Real>& u, detail::RealVector<Real>& action);
 
template <typename Real = double>
bool radialMeanHessian(const RadialMeanExpansion& expansion, MeanDerivativeMethod method, const detail::RealVector<Real>& q, detail::RealMatrix<Real>& hessian);
 
bool radialMeanCartesianHessianVector(const RadialMeanExpansion& expansion, MeanDerivativeMethod method, const Eigen::VectorXd& q, const Eigen::MatrixXd& jacobian, const Eigen::VectorXd& v, Eigen::VectorXd& action);
 
} // namespace derivatives

Detailed Documentation

Global Variables

bool kEnzymeDerivativeProviderAvailable = false

The Enzyme bridge is unavailable until its ABI is pinned.

Global Functions

DerivativeProvider makeAnalyticDerivativeProvider(HessianPreparation prepare)

Adapt an analytic Hessian preparation, such as a fitted GP posterior.

double coordinateCharacteristicScale(Eigen::Index column, const FiniteDifferenceOptions& options = {})

Characteristic coordinate length floor scale_i for column.

Parameters:

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.

bool coordinateCharacteristicScale(Eigen::Index column, double& result, const 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.

double finiteDifferenceCoordinateStep(const Vector& position, Eigen::Index column, const FiniteDifferenceOptions& options = {})

Per-coordinate central-difference step h_i = h_0 * max(abs(x_i), scale_i).

Parameters:

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.

bool finiteDifferenceCoordinateStep(const Vector& position, Eigen::Index column, double& result, const 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.

double finiteDifferenceDirectionStep(const Vector& position, const Vector& direction, const 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.

Parameters:

std::invalid_argument

if position, direction, or an option is invalid, or if coordinateScales does not match position.

bool finiteDifferenceDirectionStep(const Vector& position, const Vector& direction, double& result, const 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.

DerivativeProvider makeFiniteDifferenceForceProvider(ForceFunction force, 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.

DerivativeProvider makeEnzymeDerivativeProvider(const ForceFunction&)

Reserved source-compatible factory for the optional Enzyme bridge.

template <typename Derivatives>
Eigen::AutoDiffScalar<Derivatives> nestedAtan2(const Eigen::AutoDiffScalar<Derivatives>& y, const Eigen::AutoDiffScalar<Derivatives>& x)

atan2 that keeps the derivative type of its arguments; Eigen ‘s overload returns a dynamically sized derivative that does not nest.

template <typename Real = double>
bool radialMeanGradient(const RadialMeanExpansion& expansion, MeanDerivativeMethod method, const detail::RealVector<Real>& q, detail::RealVector<Real>& 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.

template <typename Real = double>
bool radialMeanHessianVector(const RadialMeanExpansion& expansion, MeanDerivativeMethod method, const detail::RealVector<Real>& q, const detail::RealVector<Real>& u, detail::RealVector<Real>& action)

Hessian of m at q applied to u. False as for radialMeanGradient.

template <typename Real = double>
bool radialMeanHessian(const RadialMeanExpansion& expansion, MeanDerivativeMethod method, const detail::RealVector<Real>& q, detail::RealMatrix<Real>& hessian)

Full Hessian of m at q. False as for radialMeanGradient.

bool radialMeanCartesianHessianVector(const RadialMeanExpansion& expansion, 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.