14 name =
"fair_lexicase";
34 unsigned int N =
pop.individuals.at(0).error.size();
36 unsigned int P =
pop.individuals.size();
38 vector<size_t> starting_pool;
39 for (
int i = 0;
i <
pop.individuals.size(); ++
i)
41 starting_pool.push_back(
i);
43 assert(starting_pool.size() == P);
46 vector<size_t> selected(P,0);
47 #pragma omp parallel for
48 for (
unsigned int i = 0;
i<P; ++
i)
50 vector<size_t> pool = starting_pool;
51 vector<size_t> winner;
54 vector<size_t> shuff_idx;
55 map<int,vector<float>> protect_levels;
56 vector<float> used_levels;
60 shuff_idx.resize(d.
cases.size());
61 std::iota(shuff_idx.begin(),shuff_idx.end(),0);
63 r.
shuffle(shuff_idx.begin(),shuff_idx.end());
102 for (
auto pl : protect_levels)
104 groups.push_back(pl.first);
106 x_idx = ArrayXb::Constant(d.
X.cols(),
true);
109 vector<size_t> choice_idxs(groups.size());
110 std::iota(choice_idxs.begin(),choice_idxs.end(),0);
112 int g = groups.at(idx);
115 vector<float> lvls =
unique(VectorXf(d.
X.row(g)));
117 for (
int i = lvls.size()-1;
i --> 0; )
120 if (!
in(protect_levels.at(g),lvls.at(
i)))
121 lvls.erase(lvls.begin() +
i);
126 for (
int i = 0;
i < protect_levels.at(g).size(); ++
i)
128 if (protect_levels[g].at(
i) == level)
130 protect_levels[g].erase(
131 protect_levels[g].begin() +
i);
136 x_idx = (d.
X.row(g).array() == level);
140 x_idx : d.
cases.at(shuff_idx[h]));
142 ArrayXf fitness(pool.size());
143 for (
size_t j = 0; j<pool.size(); ++j)
148 fitness(j) = case_idx.select(
149 pop.individuals.at(pool[j]).error,
155 fitness(j) = fabs(
pop.individuals.at(pool[j]).error.sum()
157 pop.individuals.at(pool[j]).error,
162 float epsilon =
mad(fitness);
166 float minfit = std::numeric_limits<float>::max();
169 for (
size_t j = 0; j<pool.size(); ++j)
171 if (fitness(j) < minfit)
176 for (
size_t j = 0; j<pool.size(); ++j)
178 if (fitness(j) <= minfit+epsilon)
179 winner.push_back(pool[j]);
186 pass = (winner.size()>1
187 && h<shuff_idx.size());
189 if(winner.size() == 0)
204 assert(winner.size()>0);
209 if (selected.size() !=
pop.individuals.size())
211 std::cout <<
"selected: " ;
212 for (
auto s: selected) std::cout << s <<
" "; std::cout <<
"\n";
224 return vector<size_t>();
data holding X, y, and Z data
map< int, vector< float > > protect_levels
T random_choice(const vector< T > &v)
void shuffle(RandomAccessIterator first, RandomAccessIterator last)
Eigen::Array< bool, Eigen::Dynamic, 1 > ArrayXb
#define THROW_LENGTH_ERROR(err)
#define THROW_RUNTIME_ERROR(err)
float mad(const ArrayXf &x)
median absolute deviation
bool in(const vector< T > v, const T &i)
check if element is in vector.
vector< T > unique(vector< T > w)
returns unique elements in vector
holds the hyperparameters for Feat.
Defines a population of programs and functions for constructing them.
vector< size_t > survive(Population &pop, const Parameters ¶ms, const Data &d)
lexicase survival
vector< size_t > select(Population &pop, const Parameters ¶ms, const Data &d)
function returns a set of selected indices