22 static constexpr index_t chunk_size = 1024;
27 n_poly_basis_(
model.poly_basis_size()),
28 n_points_(points.rows()),
30 evaluator_ = std::make_unique<rbf_evaluator<>>(
model, points_);
34 : model_(
model), n_poly_basis_(
model.poly_basis_size()) {
35 evaluator_ = std::make_unique<rbf_evaluator<>>(
model, tree_height, bbox);
38 template <
class Derived,
class Derived2>
39 std::pair<bool, double> converged(
const Eigen::MatrixBase<Derived>& values,
40 const Eigen::MatrixBase<Derived2>& weights,
41 double absolute_tolerance)
const {
42 RSMESH_ASSERT(values.rows() == n_points_);
43 RSMESH_ASSERT(weights.rows() == n_points_ + n_poly_basis_);
45 evaluator_->set_weights(weights);
47 auto nugget = model_.nugget();
49 auto max_residual = 0.0;
50 for (index_t i = 0; i < n_points_ / chunk_size + 1; i++) {
51 auto begin = i * chunk_size;
52 auto end = std::min(n_points_, begin + chunk_size);
57 evaluator_->set_field_points(points_.middleRows(begin, end - begin));
58 valuesd fit = evaluator_->evaluate() + weights.segment(begin, end - begin) * nugget;
60 for (index_t j = 0; j < end - begin; j++) {
61 auto res = std::abs(values(begin + j) - fit(j));
62 if (res >= absolute_tolerance) {
66 max_residual = std::max(max_residual, res);
70 return {
true, max_residual};
74 n_points_ = points.rows();
77 evaluator_->set_source_points(points);
82 const index_t n_poly_basis_;
87 std::unique_ptr<rbf_evaluator<>> evaluator_;