Skip to content

Commit

Permalink
added early stopping when converging feature generation
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Oct 9, 2024
1 parent cbd5b55 commit 28a8164
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext

__version__ = "0.3.28"
__version__ = "0.3.29"
HERE = Path(__file__).resolve().parent


Expand Down
6 changes: 6 additions & 0 deletions src/generator/feature_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ void FeatureGeneratorImpl::generate_inductively(
utils::g_log << "Started generating composite features. " << std::endl;
int max_complexity = std::max({concept_complexity_limit, role_complexity_limit, boolean_complexity_limit, count_numerical_complexity_limit, distance_numerical_complexity_limit});
for (int target_complexity = 2; target_complexity <= max_complexity; ++target_complexity) { // every composition adds at least one complexity
const auto num_features = data.get_num_features();
if (target_complexity <= concept_complexity_limit) {
if (data.reached_resource_limit()) break;
for (const auto& rule : m_concept_inductive_rules) {
Expand Down Expand Up @@ -195,6 +196,11 @@ void FeatureGeneratorImpl::generate_inductively(
utils::g_log << "Complexity " << target_complexity << ":" << std::endl;
data.print_statistics();
print_statistics();

if (num_features == data.get_num_features()) {
utils::g_log << "Feature generation converged." << std::endl;
break;
}
}
utils::g_log << "Finished generating composite features." << std::endl;
}
Expand Down
6 changes: 5 additions & 1 deletion src/generator/generator_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ struct GeneratorData {
m_feature_limit(feature_limit),
m_timer(time_limit) { }

int get_num_features() {
return std::get<0>(m_generated_features).size() + std::get<1>(m_generated_features).size() + std::get<2>(m_generated_features).size() + std::get<3>(m_generated_features).size();
}

void print_statistics() const {
std::cout << "Total concept elements: " << std::accumulate(m_concepts_by_iteration.begin(), m_concepts_by_iteration.end(), 0, [&](int current_sum, const auto& e){ return current_sum + e.size(); }) << std::endl
<< "Total role elements: " << std::accumulate(m_roles_by_iteration.begin(), m_roles_by_iteration.end(), 0, [&](int current_sum, const auto& e){ return current_sum + e.size(); }) << std::endl
Expand All @@ -53,7 +57,7 @@ struct GeneratorData {
}

bool reached_resource_limit() {
return (static_cast<int>(std::get<0>(m_generated_features).size() + std::get<1>(m_generated_features).size() + std::get<2>(m_generated_features).size() + std::get<3>(m_generated_features).size()) >= m_feature_limit || m_timer.is_expired());
return (get_num_features() >= m_feature_limit || m_timer.is_expired());
}
};

Expand Down

0 comments on commit 28a8164

Please sign in to comment.