55 for (
auto& all_level : all_levels)
57 for (
auto& t : all_level) t.delete_v();
60 all_levels.delete_v();
71 for (
unsigned long i : db)
80 for (
size_t i = 0; i < 32; i++)
81 if (eliminations >> i == 0)
83 std::cerr <<
"too many eliminations" << std::endl;
89 auto const first_non_empty_tournament = std::find_if(
90 tournaments.cbegin(), tournaments.cend(), [](
v_array<uint32_t>& tournament) {
return !tournament.empty(); });
91 return first_non_empty_tournament != tournaments.cend();
96 for (
auto const& t : level)
98 for (
auto i : t) std::cout <<
" " << i;
101 std::cout << std::endl;
112 for (uint32_t i = 0; i < max_label; i++)
134 for (
size_t t = 0; t < tournaments.size(); t++)
140 for (
size_t t = 0; t < tournaments.size(); t++)
142 for (
size_t j = 0; j < tournaments[t].size() / 2; j++)
144 uint32_t
id = node++;
145 uint32_t left = tournaments[t][2 * j];
146 uint32_t right = tournaments[t][2 * j + 1];
162 if (tournaments[t].size() == 2 && (t == 0 || tournaments[t - 1].empty()))
165 if (t + 1 < tournaments.size())
166 new_tournaments[t + 1].push_back(
id);
173 if (t + 1 < tournaments.size())
174 new_tournaments[t + 1].push_back(
id);
178 if (tournaments[t].size() % 2 == 1)
179 new_tournaments[t].push_back(tournaments[t].last());
185 e.
last_pair = (uint32_t)((max_label - 1) * eliminations);
195 if (e.
k == (
size_t)1)
198 uint32_t finals_winner = 0;
201 ec.
l.
simple = {FLT_MAX, 0., 0.};
203 for (
size_t i = e.
tree_height - 1; i != (
size_t)0 - 1; i--)
205 if ((finals_winner | (((
size_t)1) << i)) <= e.
errors)
208 uint32_t problem_number = e.
last_pair + (finals_winner | (((uint32_t)1) << i)) - 1;
210 base.
learn(ec, problem_number);
213 finals_winner = finals_winner | (((size_t)1) << i);
247 simple_temp.
label = -1;
249 simple_temp.
label = 1;
253 float old_weight = ec.
weight;
283 std::cout <<
"badness!" << std::endl;
297 simple_temp.
label = -1;
299 simple_temp.
label = 1;
303 uint32_t problem_number = e.
last_pair + j * (1 << (i + 1)) + (1 << i) - 1;
305 base.
learn(ec, problem_number);
323 std::cout <<
"label " << mc.
label <<
" is not in {1," << e.
k <<
"} This won't work right." << std::endl;
334 if (mc.
label != (uint32_t)-1)
342 auto data = scoped_calloc_or_throw<ect>();
345 new_options.
add(
make_option(
"ect", data->k).keep().help(
"Error correcting tournament with <k> labels"))
346 .
add(
make_option(
"error", data->errors).keep().default_value(0).help(
"errors allowed by ECT"))
349 .default_value(
"identity")
351 .help(
"Specify the link function: identity, logistic, glf1 or poisson"));
357 size_t wpp =
create_circuit(*data.get(), data->k, data->errors + 1);
360 if (link ==
"logistic")
361 data->class_boundary = 0.5;
v_array< size_t > down_directions
bool not_empty(v_array< v_array< uint32_t >> const &tournaments)
v_array< v_array< v_array< uint32_t > > > all_levels
void learn(ect &e, single_learner &base, example &ec)
v_array< bool > tournaments_won
void predict(ect &e, single_learner &base, example &ec)
base_learner * make_base(learner< T, E > &base)
virtual void add_and_parse(const option_group_definition &group)=0
single_learner * as_singleline(learner< T, E > *l)
MULTICLASS::label_t multi
void push_back(const T &new_ele)
virtual bool was_supplied(const std::string &key)=0
void print_level(v_array< v_array< uint32_t >> const &level)
v_array< uint32_t > final_nodes
bool exists(v_array< size_t > db)
option_group_definition & add(T &&op)
int add(svm_params ¶ms, svm_example *fec)
size_t create_circuit(ect &e, uint64_t max_label, uint64_t eliminations)
typed_option< T > make_option(std::string name, T &location)
v_array< direction > directions
learner< T, E > & init_multiclass_learner(free_ptr< T > &dat, L *base, void(*learn)(T &, L &, E &), void(*predict)(T &, L &, E &), parser *p, size_t ws, prediction_type::prediction_type_t pred_type=prediction_type::multiclass)
LEARNER::base_learner * setup_base(options_i &options, vw &all)
v_array< size_t > up_directions
void ect_train(ect &e, single_learner &base, example &ec)
void learn(E &ec, size_t i=0)
size_t final_depth(size_t eliminations)
uint32_t ect_predict(ect &e, single_learner &base, example &ec)
base_learner * ect_setup(options_i &options, vw &all)