36 void SetSamples(
const std::vector<std::vector<double>>& x,
const std::vector<double>& y)
38 assert(x.size() == y.size());
41 if (x.empty() || y.empty())
return;
43 assert(x[0].size() >= 2);
45 leafInterpolator.reset();
49 dimension = x[0].size();
54 std::vector<std::vector<double>> xv;
56 for (
size_t i = 0; i < x.size(); ++i)
59 leafInterpolator = std::make_unique<BivariateHermiteInterpolation>();
60 leafInterpolator->SetTrueInterpolation(trueInterpolation);
61 leafInterpolator->SetSamples(xv, y);
66 std::vector<std::vector<double>> subX;
67 std::vector<double> subY;
69 auto flushGroup = [&]() {
72 children.emplace_back(std::make_unique<MultivariateHermiteInterpolation>());
73 children.back()->SetTrueInterpolation(trueInterpolation);
74 children.back()->SetSamples(subX, subY);
79 xValues.push_back(x[0][0]);
80 for (
size_t i = 0; i < x.size(); ++i)
82 assert(x[i].size() == dimension);
84 if (x[i][0] != xValues.back())
87 xValues.push_back(x[i][0]);
90 subX.emplace_back(x[i].begin() + 1, x[i].end());
96 double Predict(
const std::vector<double>& x)
const
98 assert(x.size() == dimension);
100 if (dimension < 2 || x.size() != dimension)
103 if (leafInterpolator)
104 return leafInterpolator->Predict(x);
106 const std::vector<double> tail(x.begin() + 1, x.end());
108 std::vector<double> vals;
109 vals.reserve(children.size());
110 for (
size_t i = 0; i < children.size(); ++i)
111 vals.push_back(children[i]->Predict(tail));
117 const double val = firstInterpolator.
Predict(x[0]);
119 if (trueInterpolation)
122 const auto m = 1E-12;