Initialize worse_model_count if model accuracy is better in BoostAODE

This commit is contained in:
Ricardo Montañana Gómez 2024-03-11 21:30:01 +01:00
parent 7c98ba9bea
commit 1986d05c34
Signed by: rmontanana
GPG Key ID: 46064262FD9A7ADE
3 changed files with 8 additions and 5 deletions

View File

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Sample app now is a separate target in the Makefile and shows how to use the library with a sample dataset - Sample app now is a separate target in the Makefile and shows how to use the library with a sample dataset
- The worse model count in BoostAODE is reset to 0 every time a new model produces better accuracy, so the tolerance of the model is meant to be the number of **consecutive** models that produce worse accuracy.
## [1.0.4] 2024-03-06 ## [1.0.4] 2024-03-06

View File

@ -1,7 +1,7 @@
# BayesNet # BayesNet
<a href="#"><img src="https://img.shields.io/badge/c++-%2300599C.svg?style=flat&logo=c%2B%2B&logoColor=white"></img></a> ![C++](https://img.shields.io/badge/c++-%2300599C.svg?style=flat&logo=c%2B%2B&logoColor=white)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](<https://opensource.org/licenses/MIT>)
![Gitea Release](https://img.shields.io/gitea/v/release/rmontanana/bayesnet?gitea_url=https://gitea.rmontanana.es:3000) ![Gitea Release](https://img.shields.io/gitea/v/release/rmontanana/bayesnet?gitea_url=https://gitea.rmontanana.es:3000)
![Gitea Last Commit](https://img.shields.io/gitea/last-commit/rmontanana/bayesnet?gitea_url=https://gitea.rmontanana.es:3000&logo=gitea) ![Gitea Last Commit](https://img.shields.io/gitea/last-commit/rmontanana/bayesnet?gitea_url=https://gitea.rmontanana.es:3000&logo=gitea)

View File

@ -216,7 +216,7 @@ namespace bayesnet {
double priorAccuracy = 0.0; double priorAccuracy = 0.0;
double delta = 1.0; double delta = 1.0;
double convergence_threshold = 1e-4; double convergence_threshold = 1e-4;
int count = 0; // number of times the accuracy is lower than the convergence_threshold int worse_model_count = 0; // number of times the accuracy is lower than the convergence_threshold
// Step 0: Set the finish condition // Step 0: Set the finish condition
// if not repeatSparent a finish condition is run out of features // if not repeatSparent a finish condition is run out of features
// n_models == maxModels // n_models == maxModels
@ -274,11 +274,13 @@ namespace bayesnet {
delta = accuracy - priorAccuracy; delta = accuracy - priorAccuracy;
} }
if (delta < convergence_threshold) { if (delta < convergence_threshold) {
count++; worse_model_count++;
} else {
worse_model_count = 0; // Reset the counter if the model performs better
} }
priorAccuracy = accuracy; priorAccuracy = accuracy;
} }
exitCondition = n_models >= maxModels && repeatSparent || count > tolerance; exitCondition = n_models >= maxModels && repeatSparent || worse_model_count > tolerance;
} }
if (featuresUsed.size() != features.size()) { if (featuresUsed.size() != features.size()) {
notes.push_back("Used features in train: " + std::to_string(featuresUsed.size()) + " of " + std::to_string(features.size())); notes.push_back("Used features in train: " + std::to_string(featuresUsed.size()) + " of " + std::to_string(features.size()));