Fix maxModels mistake in BoostAODE if !repeatSp

Throw exception if wrong hyperparmeter is supplied
This commit is contained in:
Ricardo Montañana Gómez 2023-08-22 21:55:17 +02:00
parent 35432b6294
commit 1c1385b768
Signed by: rmontanana
GPG Key ID: 46064262FD9A7ADE

View File

@ -10,6 +10,13 @@ namespace bayesnet {
}
void BoostAODE::setHyperparameters(nlohmann::json& hyperparameters)
{
// Check if hyperparameters are valid
auto validKeys = { "repeatSparent", "maxModels", "ascending" };
for (const auto& item : hyperparameters.items()) {
if (find(validKeys.begin(), validKeys.end(), item.key()) == validKeys.end()) {
throw invalid_argument("Hyperparameter " + item.key() + " is not valid");
}
}
if (hyperparameters.contains("repeatSparent")) {
repeatSparent = hyperparameters["repeatSparent"];
}
@ -74,7 +81,7 @@ namespace bayesnet {
// Step 3.4: Store classifier and its accuracy to weigh its future vote
models.push_back(std::move(model));
significanceModels.push_back(significance);
exitCondition = n_models == maxModels;
exitCondition = n_models == maxModels && repeatSparent;
}
if (featuresUsed.size() != features.size()) {
cout << "Warning: BoostAODE did not use all the features" << endl;