Eigen::VectorXd _inner_search(const F& f, size_t depth, const Eigen::VectorXd& current) const { size_t dim = current.size(); double step_size = 1.0 / (double)Params::opt_gridsearch::bins(); double upper_lim = 1.0 + step_size; double best_fit = -std::numeric_limits<double>::max(); Eigen::VectorXd current_result(dim); for (double x = 0; x < upper_lim; x += step_size) { Eigen::VectorXd new_point = current; new_point[depth] = x; double val; if (depth == dim - 1) { val = eval(f, new_point); if (val > best_fit) { best_fit = val; current_result = new_point; } } else { Eigen::VectorXd temp_result = _inner_search(f, depth + 1, new_point); val = eval(f, temp_result); if (val > best_fit) { best_fit = val; current_result = temp_result; } } } return current_result; }
Eigen::VectorXd explore(int dim, const AcquisitionFunction& acqui, const Eigen::VectorXd& current, Eigen::VectorXd& result) const { double best_fit = -std::numeric_limits<double>::max(); Eigen::VectorXd current_result(result.size()); for (double x = 0; x <= 1; x += 1 / (double)nb_pts) { Eigen::VectorXd point = current; point[dim] = x; double val; if (dim == current.size() - 1) { val = acqui(point); if (val > best_fit) { best_fit = val; current_result = point; } } else { Eigen::VectorXd temp_result = current_result; std::tie(temp_result, val) = explore(dim + 1, acqui, point, temp_result); if (val > best_fit) { best_fit = val; current_result = temp_result; } } } return current_result; }