5std::vector<std::map<std::string, double>>
6createGrid(
const std::map<std::string, std::vector<double>>& param_values)
8 std::vector<std::map<std::string, double>> grid;
10 if (param_values.empty()) {
15 auto it = param_values.begin();
16 for (
double value : it->second) {
17 std::map<std::string, double> point;
18 point[it->first] = value;
19 grid.push_back(point);
23 for (++it; it != param_values.end(); ++it) {
24 std::vector<std::map<std::string, double>> new_grid;
25 for (
const auto& existing_point : grid) {
26 for (
double value : it->second) {
27 auto new_point = existing_point;
28 new_point[it->first] = value;
29 new_grid.push_back(new_point);
32 grid = std::move(new_grid);
6createGrid(
const std::map<std::string, std::vector<double>>& param_values) {
…}
42 auto comp = scorer->getComparator();
44 for (
size_t i = 0; i < cv_result.
results.size(); ++i) {
45 auto result = cv_result.
results[i];
46 int best_alpha_ind =
whichBest(result.mean_scores, comp);
47 double current_score = result.mean_scores(best_alpha_ind);
49 assert(result.alphas(best_alpha_ind) > 0);
51 if (scorer->isWorse(cv_result.
best_score, current_score)) {
56 cv_result.
best_params[
"alpha"] = result.alphas(best_alpha_ind);
Cross-validation functionality for SLOPE models.
Namespace containing SLOPE regression implementation.
void findBestParameters(CvResult &cv_result, const std::unique_ptr< Score > &scorer)
Identifies the best parameters from cross-validation results.
std::vector< std::map< std::string, double > > createGrid(const std::map< std::string, std::vector< double > > ¶m_values)
Creates a grid of parameter combinations from parameter value ranges.
int whichBest(const T &x, const Comparator &comp)
Returns the index of the minimum element in a container.
Contains overall results from a cross-validation process.
double best_score
The score achieved by the optimal hyperparameter configuration.
std::map< std::string, double > best_params
std::vector< GridResult > results
int best_ind
Index of the best performing configuration in the results vector.