From 6b4ebc05587f71893866911ee323daf2d82e8068 Mon Sep 17 00:00:00 2001 From: gAldeia Date: Mon, 21 Oct 2024 08:41:45 -0300 Subject: [PATCH] Comments --- src/bandit/bandit_operator.h | 2 +- src/data/data.cpp | 2 +- src/vary/variation.cpp | 73 ------------------------------------ src/vary/variation.h | 9 ----- 4 files changed, 2 insertions(+), 84 deletions(-) diff --git a/src/bandit/bandit_operator.h b/src/bandit/bandit_operator.h index 563b87c6..8f918709 100644 --- a/src/bandit/bandit_operator.h +++ b/src/bandit/bandit_operator.h @@ -2,7 +2,7 @@ #define BANDIT_OPERATOR_H #include "../init.h" -#include "../data/data.h" +// #include "../data/data.h" #include "../types.h" #include "../params.h" #include "../program/tree_node.h" diff --git a/src/data/data.cpp b/src/data/data.cpp index 3c52ddee..92c5327a 100644 --- a/src/data/data.cpp +++ b/src/data/data.cpp @@ -247,7 +247,7 @@ void Dataset::init() [&](int element) { return element; }); } else if (classification && true) // figuring out training and validation data indexes - { // Stratified split for classification problems. TODO: parameters to change stratify behavior? (false by default) + { // Stratified split for classification problems. TODO: parameters to change stratify behavior? (and set false by default) std::map> class_indices; // TODO: I think I can remove many std:: from the code.. for (size_t i = 0; i < n_samples; ++i) { class_indices[y[i]].push_back(i); diff --git a/src/vary/variation.cpp b/src/vary/variation.cpp index 12e56f80..fe885c4e 100644 --- a/src/vary/variation.cpp +++ b/src/vary/variation.cpp @@ -760,79 +760,6 @@ void Variation::vary(Population& pop, int island, } }; -template -vector Variation::calculate_rewards(Population& pop, int island) -{ - // get island indexes - // go to the offspring of the island - // find which objectives we are using - // calculate the rewards based on variation of the objectives (must take into account the weights) - // define which criteria for rewards we are going to use (dominates, improved at least one without changing the other, etc) - // return the rewards vector, which will be used to update the bandits - - vector rewards; - rewards.resize(0); - - // this is done assuming index of offspring is valid and the second half - // of indices is the offspring. This is done in vary() function. - auto indices = pop.get_island_indexes(island); - - for (unsigned i = 0 ; i < indices.size()/2; ++i) - { - if (pop.individuals.at(indices.at(indices.size()/2 + i)) == nullptr) - { - HANDLE_ERROR_THROW("bad loop index in calculate_rewards"); - } - - const Individual& ind = *pop.individuals.at( - indices.at(indices.size()/2 + i) ); - - vector deltas(ind.get_objectives().size(), 0.0f); - - float delta = 0.0f; - float weight = 0.0f; - - for (const auto& obj : ind.get_objectives()) - { - // TODO: make this a function? I think this code below is repeated in other places - // multiply by the weight so it is a maximization problem regardless of obj - if (obj.compare(parameters.scorer)==0) - delta = ind.fitness.get_loss()-ind.fitness.get_prev_loss(); - else if (obj.compare("complexity")==0) - delta = ind.fitness.get_complexity()-ind.fitness.get_prev_complexity(); - else if (obj.compare("linear_complexity")==0) - delta = ind.fitness.get_linear_complexity()-ind.fitness.get_prev_linear_complexity(); - else if (obj.compare("size")==0) - delta = ind.fitness.get_size()-ind.fitness.get_prev_size(); - else if (obj.compare("depth")==0) - delta = ind.fitness.get_depth()-ind.fitness.get_prev_depth(); - else - HANDLE_ERROR_THROW(obj+" is not a known objective"); - - auto it = Individual::weightsMap.find(obj); - weight = it->second; - - deltas.push_back(delta*weight); - } - - // calculate the rewards based on the objectives - bool allPositive = true; - for (float d : deltas) { - if (d < 0) { - allPositive = false; - break; - } - } - - if (allPositive) - rewards.push_back(1.0); - else - rewards.push_back(0.0); - } - - return rewards; -}; - template void Variation::update_ss() { diff --git a/src/vary/variation.h b/src/vary/variation.h index 9c2f1594..093b93d3 100644 --- a/src/vary/variation.h +++ b/src/vary/variation.h @@ -181,15 +181,6 @@ class Variation { */ void vary(Population& pop, int island, const vector& parents); - /** - * Calculates the rewards for the given population and island. - * - * @param pop The population to calculate rewards for. - * @param island The island index. - * @return A vector of rewards for the population. - */ - vector calculate_rewards(Population& pop, int island); - /** * Updates the probability distribution sampling for variation and nodes based on the given rewards. *