16 void RBFInterpolation::init(
const Eigen::MatrixXd &fun,
const Eigen::MatrixXd &pts,
const std::string &rbf,
const double eps)
18 assert(pts.rows() >= 0);
20 std::vector<double> pointscl(pts.size());
21 std::vector<double> functioncl(fun.rows());
24 for (
int i = 0; i < pts.rows(); ++i)
26 for (
int j = 0; j < pts.cols(); ++j)
28 pointscl[index++] = pts(i, j);
32 data_.resize(fun.cols());
33 for (
int i = 0; i < fun.cols(); ++i)
37 for (
int j = 0; j < fun.rows(); ++j)
38 functioncl[index] = fun(j, i);
40 rbf_pum::init(pointscl, functioncl, data_[i], verbose_, rbfcl_, opt_, unit_cube_, num_threads_);
43 std::function<double(
double)> tmp;
45 if (rbf ==
"multiquadric")
47 tmp = [eps](
const double r) {
return sqrt((r / eps) * (r / eps) + 1); };
49 else if (rbf ==
"inverse" || rbf ==
"inverse_multiquadric" || rbf ==
"inverse multiquadric")
51 tmp = [eps](
const double r) {
return 1.0 / sqrt((r / eps) * (r / eps) + 1); };
53 else if (rbf ==
"gaussian")
55 tmp = [eps](
const double r) {
return exp(-(r / eps) * (r / eps)); };
57 else if (rbf ==
"linear")
59 tmp = [](
const double r) {
return r; };
61 else if (rbf ==
"cubic")
63 tmp = [](
const double r) {
return r * r * r; };
65 else if (rbf ==
"quintic")
67 tmp = [](
const double r) {
return r * r * r * r * r; };
69 else if (rbf ==
"thin_plate" || rbf ==
"thin-plate")
71 tmp = [](
const double r) {
return abs(r) < 1e-10 ? 0 : (r * r * log(r)); };
75 logger().warn(
"Unable to match {} rbf, falling back to multiquadric", rbf);
78 tmp = [eps](
const double r) {
return sqrt((r / eps) * (r / eps) + 1); };
130 Eigen::MatrixXd res(pts.rows(), data_.size());
132 std::vector<double> pointscl(pts.size());
134 for (
int i = 0; i < pts.rows(); ++i)
136 for (
int j = 0; j < pts.cols(); ++j)
138 pointscl[index++] = pts(i, j);
142 std::vector<double> tmp;
143 for (
size_t i = 0; i < data_.size(); ++i)
145 rbf_pum::interpolate(data_[i], pointscl, tmp, verbose_, rbfcl_, opt_, unit_cube_, num_threads_);
147 for (
size_t j = 0; j < tmp.size(); ++j)
151 assert(pts.cols() ==
centers_.cols());
153 const int m = pts.rows();
155 Eigen::MatrixXd mat(m, n);
156 for (
int i = 0; i < m; ++i)
158 for (
int j = 0; j < n; ++j)
160 mat(i, j) =
rbf_((
centers_.row(j) - pts.row(i)).norm());
164 const Eigen::MatrixXd res = mat *
weights_;