Skip to content

Commit

Permalink
Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gAldeia committed Oct 21, 2024
1 parent e754c78 commit 6b4ebc0
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 84 deletions.
2 changes: 1 addition & 1 deletion src/bandit/bandit_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/data/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float, vector<int>> 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);
Expand Down
73 changes: 0 additions & 73 deletions src/vary/variation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,79 +760,6 @@ void Variation<T>::vary(Population<T>& pop, int island,
}
};

template<ProgramType T>
vector<float> Variation<T>::calculate_rewards(Population<T>& 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<float> 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<T>& ind = *pop.individuals.at(
indices.at(indices.size()/2 + i) );

vector<float> 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<T>::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 <Brush::ProgramType T>
void Variation<T>::update_ss()
{
Expand Down
9 changes: 0 additions & 9 deletions src/vary/variation.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,6 @@ class Variation {
*/
void vary(Population<T>& pop, int island, const vector<size_t>& 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<float> calculate_rewards(Population<T>& pop, int island);

/**
* Updates the probability distribution sampling for variation and nodes based on the given rewards.
*
Expand Down

0 comments on commit 6b4ebc0

Please sign in to comment.