38 void SetSamples(
const std::vector<std::vector<double>> &x,
const std::vector<double> &y)
40 assert(x.size() == y.size());
43 if (x.empty() || y.empty())
46 assert(x[0].size() >= 2);
48 leafInterpolator.reset();
52 dimension = x[0].size();
57 std::vector<std::vector<double>> xv;
59 for (
size_t i = 0; i < x.size(); ++i)
62 leafInterpolator = std::make_unique<BivariateHermiteInterpolation>();
63 leafInterpolator->SetTrueInterpolation(trueInterpolation);
64 leafInterpolator->SetSamples(xv, y);
69 std::vector<std::vector<double>> subX;
70 std::vector<double> subY;
72 auto flushGroup = [&]() {
75 children.emplace_back(std::make_unique<MultivariateHermiteInterpolation>());
76 children.back()->SetTrueInterpolation(trueInterpolation);
77 children.back()->SetSamples(subX, subY);
82 xValues.push_back(x[0][0]);
83 for (
size_t i = 0; i < x.size(); ++i)
85 assert(x[i].size() == dimension);
87 if (x[i][0] != xValues.back())
90 xValues.push_back(x[i][0]);
93 subX.emplace_back(x[i].begin() + 1, x[i].end());
99 double Predict(
const std::vector<double> &x)
const
101 assert(x.size() == dimension);
103 if (dimension < 2 || x.size() != dimension)
106 if (leafInterpolator)
107 return leafInterpolator->Predict(x);
109 const std::vector<double> tail(x.begin() + 1, x.end());
111 std::vector<double> vals;
112 vals.reserve(children.size());
113 for (
size_t i = 0; i < children.size(); ++i)
114 vals.push_back(children[i]->Predict(tail));
120 const double val = firstInterpolator.
Predict(x[0]);
122 if (trueInterpolation)
125 const auto m = 1E-12;