Loading...
Searching...
No Matches
RichardsonCurvature.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 GPRIDGEIZATION_RICHARDSON_CURVATURE_H_
5#define GPRIDGEIZATION_RICHARDSON_CURVATURE_H_
6
7#include <Eigen/Dense>
8#include <algorithm>
9#include <cmath>
10
11namespace gpr {
12namespace optim {
13
23inline Eigen::VectorXd richardsonExtrapolate(const Eigen::VectorXd& at_h,
24 const Eigen::VectorXd& at_2h)
25{
26 return (4.0 * at_h - at_2h) / 3.0;
27}
28
29inline Eigen::VectorXd richardsonTruncation(const Eigen::VectorXd& at_h,
30 const Eigen::VectorXd& at_2h)
31{
32 return (at_2h - at_h) / 3.0;
33}
34
46
47inline double refinedCurvatureResolution(double refined_resolution,
48 double anharmonic_scale) noexcept
49{
50 double resolution =
51 std::isfinite(refined_resolution) ? std::abs(refined_resolution) : 0.0;
52 if (std::isfinite(anharmonic_scale))
53 resolution = std::max(resolution, std::abs(anharmonic_scale));
54 return resolution;
55}
56
58 double curvature, double refined_resolution,
59 double anharmonic_scale) noexcept
60{
61 const double resolution =
62 refinedCurvatureResolution(refined_resolution, anharmonic_scale);
63 if (!std::isfinite(curvature)) return RefinedCurvatureSign::Unresolved;
64 if (curvature > resolution) return RefinedCurvatureSign::Positive;
65 if (curvature < -resolution) return RefinedCurvatureSign::Negative;
67}
68
75inline bool curvatureResolvedByStencil(double measured,
76 double anharmonic_scale) noexcept
77{
78 if (!std::isfinite(measured)) return false;
79 if (!std::isfinite(anharmonic_scale)) return false;
80 return std::abs(measured) > std::abs(anharmonic_scale);
81}
82
91inline bool curvatureResolvedByThirdDerivative(double measured, double third,
92 double step) noexcept
93{
94 if (!std::isfinite(measured) || !std::isfinite(third) || !(third >= 0.0) ||
95 !(step > 0.0) || !std::isfinite(step))
96 return false;
97 return std::abs(measured) > third * step * step / 6.0;
98}
99
105inline double richardsonForwardExtrapolate(double at_h, double at_2h) noexcept
106{
107 return 2.0 * at_h - at_2h;
108}
109
110inline double richardsonForwardTruncation(double at_h, double at_2h) noexcept
111{
112 return at_2h - at_h;
113}
114
118inline bool curvatureResolvedBySurrogate(double measured,
119 double surrogate) noexcept
120{
121 if (!std::isfinite(measured)) return false;
122 if (!std::isfinite(surrogate)) return true;
123 return std::abs(measured) > std::abs(measured - surrogate);
124}
125
129inline int certifiedCurvatureSign(double extrapolated, double estimate) noexcept
130{
131 if (!std::isfinite(extrapolated) || !std::isfinite(estimate)) return 0;
132 const double resolution = std::abs(estimate);
133 if (extrapolated > resolution) return 1;
134 if (extrapolated < -resolution) return -1;
135 return 0;
136}
137
138} // namespace optim
139} // namespace gpr
140
141#endif // GPRIDGEIZATION_RICHARDSON_CURVATURE_H_
double richardsonForwardTruncation(double at_h, double at_2h) noexcept
bool curvatureResolvedByThirdDerivative(double measured, double third, double step) noexcept
Eigen::VectorXd richardsonExtrapolate(const Eigen::VectorXd &at_h, const Eigen::VectorXd &at_2h)
double refinedCurvatureResolution(double refined_resolution, double anharmonic_scale) noexcept
Eigen::VectorXd richardsonTruncation(const Eigen::VectorXd &at_h, const Eigen::VectorXd &at_2h)
bool curvatureResolvedBySurrogate(double measured, double surrogate) noexcept
RefinedCurvatureSign refinedCurvatureSign(double curvature, double refined_resolution, double anharmonic_scale) noexcept
bool curvatureResolvedByStencil(double measured, double anharmonic_scale) noexcept
double richardsonForwardExtrapolate(double at_h, double at_2h) noexcept
int certifiedCurvatureSign(double extrapolated, double estimate) noexcept
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition Macros.h:16