Support b_main with best hyperparameters
This commit is contained in:
@@ -19,7 +19,7 @@ namespace platform {
|
||||
std::ostream_iterator<std::string>(ss, delim.c_str()));
|
||||
return ss.str();
|
||||
}
|
||||
HyperParameters::HyperParameters(const std::vector<std::string>& datasets, const std::string& hyperparameters_file)
|
||||
HyperParameters::HyperParameters(const std::vector<std::string>& datasets, const std::string& hyperparameters_file, bool best)
|
||||
{
|
||||
// Check if file exists
|
||||
std::ifstream file(hyperparameters_file);
|
||||
@@ -28,7 +28,14 @@ namespace platform {
|
||||
}
|
||||
// Check if file is a json
|
||||
json file_hyperparameters = json::parse(file);
|
||||
auto input_hyperparameters = file_hyperparameters["results"];
|
||||
json input_hyperparameters;
|
||||
if (best) {
|
||||
for (const auto& [key, value] : file_hyperparameters.items()) {
|
||||
input_hyperparameters[key] = value[1];
|
||||
}
|
||||
} else {
|
||||
input_hyperparameters = file_hyperparameters["results"];
|
||||
}
|
||||
// Check if hyperparameters are valid
|
||||
for (const auto& dataset : datasets) {
|
||||
if (!input_hyperparameters.contains(dataset)) {
|
||||
|
@@ -10,14 +10,17 @@ namespace platform {
|
||||
class HyperParameters {
|
||||
public:
|
||||
HyperParameters() = default;
|
||||
// Constructor to use command line hyperparameters
|
||||
explicit HyperParameters(const std::vector<std::string>& datasets, const json& hyperparameters_);
|
||||
explicit HyperParameters(const std::vector<std::string>& datasets, const std::string& hyperparameters_file);
|
||||
// Constructor to use hyperparameters file generated by grid or by best results
|
||||
explicit HyperParameters(const std::vector<std::string>& datasets, const std::string& hyperparameters_file, bool best = false);
|
||||
~HyperParameters() = default;
|
||||
bool notEmpty(const std::string& key) const { return !hyperparameters.at(key).empty(); }
|
||||
void check(const std::vector<std::string>& valid, const std::string& fileName);
|
||||
json get(const std::string& fileName);
|
||||
private:
|
||||
std::map<std::string, json> hyperparameters;
|
||||
bool best = false; // Used to separate grid/best hyperparameters as the format of those files are different
|
||||
};
|
||||
} /* namespace platform */
|
||||
#endif
|
Reference in New Issue
Block a user