29 unsigned int N =
pop.individuals.at(0).error.size();
31 unsigned int P =
pop.individuals.size();
33 ArrayXf epsilon = ArrayXf::Zero(N);
37 || params.
scorer_.compare(
"multi_log")==0)
40 for (
int i = 0;
i<epsilon.size(); ++
i)
42 VectorXf case_errors(
pop.individuals.size());
43 for (
int j = 0; j<
pop.individuals.size(); ++j)
45 case_errors(j) =
pop.individuals.at(j).error(
i);
47 epsilon(
i) =
mad(case_errors);
52 vector<size_t> starting_pool;
53 for (
int i = 0;
i <
pop.individuals.size(); ++
i)
55 starting_pool.push_back(
i);
57 assert(starting_pool.size() == P);
59 vector<size_t> selected(P,0);
60 #pragma omp parallel for
61 for (
unsigned int i = 0;
i<P; ++
i)
68 vector<size_t> choices(N);
69 std::iota(choices.begin(), choices.end(),0);
71 for (
unsigned i = 0;
i<N; ++
i)
73 vector<size_t> choice_idxs(N-
i);
74 std::iota(choice_idxs.begin(),choice_idxs.end(),0);
77 cases.push_back(choices.at(idx));
78 choices.erase(choices.begin() + idx);
79 sample_weights.erase(sample_weights.begin() + idx);
85 std::iota(cases.begin(),cases.end(),0);
86 r.
shuffle(cases.begin(),cases.end());
88 vector<size_t> pool = starting_pool;
89 vector<size_t> winner;
98 float minfit = std::numeric_limits<float>::max();
101 for (
size_t j = 0; j<pool.size(); ++j)
102 if (
pop.individuals.at(pool[j]).error(cases[h]) < minfit)
103 minfit =
pop.individuals.at(pool[j]).error(cases[h]);
106 for (
size_t j = 0; j<pool.size(); ++j)
107 if (
pop.individuals.at(pool[j]).error(cases[h])
108 <= minfit+epsilon[cases[h]])
109 winner.push_back(pool[j]);
113 pass = (winner.size()>1 && h<cases.size());
115 if(winner.size() == 0)
117 if(h >= cases.size())
128 assert(winner.size()>0);
133 if (selected.size() !=
pop.individuals.size())
135 std::cout <<
"selected: " ;
136 for (
auto s: selected) std::cout << s <<
" "; std::cout <<
"\n";
148 return vector<size_t>();
data holding X, y, and Z data
T random_choice(const vector< T > &v)
void shuffle(RandomAccessIterator first, RandomAccessIterator last)
#define THROW_LENGTH_ERROR(err)
#define THROW_RUNTIME_ERROR(err)
float mad(const ArrayXf &x)
median absolute deviation
holds the hyperparameters for Feat.
bool classification
flag to conduct classification rather than
vector< float > class_weights
weights for each class
vector< float > sample_weights
weights for each sample
string scorer_
actual loss function used, determined by scorer
Defines a population of programs and functions for constructing them.
vector< size_t > select(Population &pop, const Parameters ¶ms, const Data &d)
function returns a set of selected indices from pop
vector< size_t > survive(Population &pop, const Parameters ¶ms, const Data &d)
lexicase survival