Loading...
Searching...
No Matches
NlmlCurvature.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3// See LICENSE for details.
4#ifndef GPR_ML_NLML_CURVATURE_H_
5#define GPR_ML_NLML_CURVATURE_H_
6
7#include <Eigen/Core>
8#include <cmath>
9#include <concepts>
10#include <limits>
11
13
14namespace funcmin {
15
16template <typename Holder>
18 requires(Holder& holder, const Eigen::VectorXd& vector,
19 const gpr::EigenMatrix& matrix, Eigen::VectorXd& product) {
20 {
21 holder.exactNlmlHessianVectorAvailable()
22 } -> std::convertible_to<bool>;
23 {
24 holder.evaluateNlmlHessianVector(vector, matrix, vector, vector,
25 product)
26 } -> std::convertible_to<bool>;
27 };
28
31template <typename Holder>
32[[nodiscard]] bool holderHasNlmlHessianVector(Holder& holder)
33{
34 if constexpr (NlmlHessianVectorHolder<Holder>) {
35 return holder.exactNlmlHessianVectorAvailable();
36 } else {
37 return false;
38 }
39}
40
44template <typename Holder>
45bool holderNlmlHessianVector(Holder& holder, const Eigen::VectorXd& x_ind,
46 const gpr::EigenMatrix& x,
47 const Eigen::VectorXd& y,
48 const Eigen::VectorXd& direction,
49 Eigen::VectorXd& product)
50{
51 if constexpr (NlmlHessianVectorHolder<Holder>) {
52 if (!holder.exactNlmlHessianVectorAvailable()) return false;
53 return holder.evaluateNlmlHessianVector(x_ind, x, y, direction,
54 product) &&
55 product.size() == direction.size() && product.allFinite();
56 } else {
57 return false;
58 }
59}
60
63template <typename Holder>
65 const Eigen::VectorXd& x_ind,
66 const gpr::EigenMatrix& x,
67 const Eigen::VectorXd& y,
68 const Eigen::VectorXd& direction,
69 double& curvature)
70{
71 curvature = std::numeric_limits<double>::quiet_NaN();
72 Eigen::VectorXd product;
73 if (!holderNlmlHessianVector(holder, x_ind, x, y, direction, product)) {
74 return false;
75 }
76 curvature = direction.dot(product);
77 return std::isfinite(curvature);
78}
79
80} // namespace funcmin
81
82#endif // GPR_ML_NLML_CURVATURE_H_
@ x
Definition Enums.h:28
@ y
Definition Enums.h:28
bool holderHasNlmlHessianVector(Holder &holder)
bool holderNlmlDirectionalCurvature(Holder &holder, const Eigen::VectorXd &x_ind, const gpr::EigenMatrix &x, const Eigen::VectorXd &y, const Eigen::VectorXd &direction, double &curvature)
bool holderNlmlHessianVector(Holder &holder, const Eigen::VectorXd &x_ind, const gpr::EigenMatrix &x, const Eigen::VectorXd &y, const Eigen::VectorXd &direction, Eigen::VectorXd &product)
Eigen::Matrix< double, EigenDynamic, EigenDynamic, EigenMatrixStorage > EigenMatrix
Definition Macros.h:20