1 #ifndef MEDUSA_BITS_APPROXIMATIONS_RBFBASIS_HPP_
2 #define MEDUSA_BITS_APPROXIMATIONS_RBFBASIS_HPP_
15 template <
class vec_t,
class RBFType>
17 int index,
const vector_t& point,
const std::vector<vector_t>& support)
const {
18 assert_msg(0 <= index && index < size_,
"Basis index %d out of range [0, %d)", index, size_);
19 assert_msg(
static_cast<int>(support.size()) >= size_,
20 "Not enough support points given for this basis size, got %d support points for "
21 "basis size %d.", support.size(), size_);
22 return rbf_((point-support[index]).squaredNorm());
25 template <
class RBFType,
class vec_t>
26 template <
typename operator_t>
28 operator_t op,
const std::vector<vector_t>& support,
scalar_t scale)
const {
29 return op.apply(*
this, index, point, support, scale);
33 template <
class RBFType,
class vec_t>
35 int index,
const vector_t& point,
Lap<dim> op,
const std::vector<vector_t>& support,
37 assert_msg(0 <= index && index < size_,
"Basis index %d out of range [0, %d)", index, size_);
38 assert_msg(
static_cast<int>(support.size()) >= size_,
39 "Not enough support points given for this basis size, got %d support points for "
40 "basis size %d.", support.size(), size_);
41 return rbf_((point - support[index]).squaredNorm(), op)/scale/scale;
44 template <
class RBFType,
class vec_t>
46 int index,
const vector_t& point,
Der1<dim> op,
const std::vector<vector_t>& support,
48 assert_msg(0 <= index && index < size_,
"Basis index %d out of range [0, %d)", index, size_);
49 assert_msg(
static_cast<int>(support.size()) >= size_,
50 "Not enough support points given for this basis size, got %d support points for "
51 "basis size %d.", support.size(), size_);
52 vec_t p = point - support[index];
53 return 2*p[op.
var]*rbf_(p.squaredNorm(), 1)/scale;
56 template <
class RBFType,
class vec_t>
58 int index,
const vector_t& point,
Der2<dim> op,
const std::vector<vector_t>& support,
60 assert_msg(0 <= index && index < size_,
"Basis index %d out of range [0, %d)", index, size_);
61 assert_msg(
static_cast<int>(support.size()) >= size_,
62 "Not enough support points given for this basis size, got %d support points for "
63 "basis size %d.", support.size(), size_);
64 vec_t p = point - support[index];
66 double res = 4*p[op.
var1]*p[op.
var2]*rbf_(r2, 2);
70 return res/scale/scale;
73 template <
class vec_t,
class RBFType>
75 int index,
const std::vector<vector_t>& support)
const {
76 assert_msg(0 <= index && index < size_,
"Basis index %d out of range [0, %d)", index, size_);
77 assert_msg(
static_cast<int>(support.size()) >= size_,
78 "Not enough support points given for this basis size, got %d support points for "
79 "basis size %d.", support.size(), size_);
80 return rbf_(support[index].squaredNorm());
83 template <
class RBFType,
class vec_t>
86 const std::vector<vector_t>& support,
scalar_t scale)
const {
87 assert_msg(0 <= index && index < size_,
"Basis index %d out of range [0, %d)", index, size_);
88 assert_msg(
static_cast<int>(support.size()) >= size_,
89 "Not enough support points given for this basis size, got %d support points for "
90 "basis size %d.", support.size(), size_);
91 return rbf_(support[index].squaredNorm(),
lap)/scale/scale;
94 template <
class RBFType,
class vec_t>
96 const std::vector<vector_t>& support,
scalar_t scale)
const {
97 assert_msg(0 <= index && index < size_,
"Basis index %d out of range [0, %d)", index, size_);
98 assert_msg(
static_cast<int>(support.size()) >= size_,
99 "Not enough support points given for this basis size, got %d support points for "
100 "basis size %d.", support.size(), size_);
101 assert_msg(der1.
var >= 0,
"Index of derived variable %d should be higher or equal to 0.",
104 " than the number of dimensions %d", der1.
var,
dim);
106 const auto& s = support[index];
113 template <
class RBFType,
class vec_t>
115 const std::vector<vector_t>& support,
scalar_t scale)
const {
116 assert_msg(0 <= index && index < size_,
"Basis index %d out of range [0, %d)", index, size_);
117 assert_msg(
static_cast<int>(support.size()) >= size_,
118 "Not enough support points given for this basis size, got %d support points for "
119 "basis size %d.", support.size(), size_);
120 assert_msg(der2.
var1 >= 0 && der2.
var2 >=0,
"Indexes of derived variables %d and %d should"
121 " be both higher or equal to 0.",
124 " both be lower than the number of dimensions %d", der2.
var1, der2.
var2,
dim);
126 auto& s = support[index];
134 return v/scale/scale;
138 template <
typename V,
typename R>
140 return os <<
"RBF basis " << m.
dim <<
"D, " << m.
size() <<
"x " << m.
rbf();
145 #endif // MEDUSA_BITS_APPROXIMATIONS_RBFBASIS_HPP_