iterative-solver 0.0
Interpolate.h
1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_INTERPOLATE_H_
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_INTERPOLATE_H_
3#include <molpro/linalg/scalar_traits.h>
4
5#include <cmath>
6#include <limits>
7#include <ostream>
8#include <string>
9#include <vector>
10
15namespace molpro::linalg::itsolv {
16
30template <typename value_type = double>
33 "the interpolant orders function values in order to minimise them, so it is defined "
34 "only for a real type; pass the real type underlying your scalar, as Optimize does");
35
36public:
37 using value_t = value_type;
38
39 struct point {
40 value_type x; //< abscissa
41 value_type f = std::numeric_limits<value_type>::quiet_NaN(); //< function value at x
42 value_type f1 = std::numeric_limits<value_type>::quiet_NaN(); //< function first gradient at x
43 value_type f2 = std::numeric_limits<value_type>::quiet_NaN(); //< function second gradient at x
44 };
52 explicit Interpolator(point p0, point p1, std::string interpolant = "cubic", int verbosity = 0);
58 point operator()(value_type x) const;
69 point minimize(value_type xa, value_type xb, size_t bracket_grid = 100, size_t max_bracket_grid = 100000,
70 bool analytic = true) const;
71 point minimize_cubic() const;
72 static std::vector<std::string> interpolants();
73
74 const std::vector<value_type>& parameters() const { return m_parameters; }
75
76private:
77 const point m_p0, m_p1;
78 const std::string m_interpolant;
79 std::vector<value_type> m_parameters;
80};
81
84
85template <typename value_type>
87 const typename Interpolator<value_type>::point& rhs) {
88 return lhs.x == rhs.x && lhs.f == rhs.f && lhs.f1 == rhs.f1;
89}
90
91inline bool operator==(const Interpolate::point& lhs, const Interpolate::point& rhs) {
92 return lhs.x == rhs.x && lhs.f == rhs.f && lhs.f1 == rhs.f1;
93}
94
95template <typename value_type>
96std::ostream& operator<<(std::ostream& os, const Interpolator<value_type>& interpolant) {
97 for (const auto& parameter : interpolant.parameters())
98 os << " " << parameter;
99 return os;
100}
101
102template <typename value_type>
103std::ostream& operator<<(std::ostream& os, const typename Interpolator<value_type>::point& p) {
104 os << "x=" << p.x << ", value=" << p.f << ", gradient=" << p.f1 << ", curvature=" << p.f2;
105 return os;
106}
107
108inline std::ostream& operator<<(std::ostream& os, const Interpolate::point& p) {
109 os << "x=" << p.x << ", value=" << p.f << ", gradient=" << p.f1 << ", curvature=" << p.f2;
110 return os;
111}
112
113extern template class Interpolator<double>;
114extern template class Interpolator<long double>;
115
116} // namespace molpro::linalg::itsolv
117#endif // LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_INTERPOLATE_H_
The interpolant, in the precision of the problem it is used for.
Definition: Interpolate.h:31
const std::vector< value_type > & parameters() const
Definition: Interpolate.h:74
point minimize(value_type xa, value_type xb, size_t bracket_grid=100, size_t max_bracket_grid=100000, bool analytic=true) const
Find the minimum of the interpolant within a range.
Definition: Interpolate-implementation.h:142
point operator()(value_type x) const
Evaluate the interpolant and its derivative at a given point.
Definition: Interpolate-implementation.h:104
point minimize_cubic() const
Definition: Interpolate-implementation.h:119
Interpolator(point p0, point p1, std::string interpolant="cubic", int verbosity=0)
Construct the interpolant.
Definition: Interpolate-implementation.h:62
value_type value_t
Definition: Interpolate.h:37
static std::vector< std::string > interpolants()
Definition: Interpolate-implementation.h:99
4-parameter interpolation of a 1-dimensional function given two points for which function values and ...
Definition: helper.h:14
std::ostream & operator<<(std::ostream &o, const Statistics &statistics)
Definition: Statistics.h:39
bool operator==(const typename Interpolator< value_type >::point &lhs, const typename Interpolator< value_type >::point &rhs)
Definition: Interpolate.h:86
Definition: scalar_traits.h:19
value_type f
Definition: Interpolate.h:41
value_type f2
Definition: Interpolate.h:43
value_type f1
Definition: Interpolate.h:42
value_type x
Definition: Interpolate.h:40