Skip to content

Commit

Permalink
refactor: cb_explore_adf_bag.cc make_reduction_learner (#3016)
Browse files Browse the repository at this point in the history
* refactor: cb_explore_adf_bag.cc

* reformat

* remove comment

* reformat

Co-authored-by: root <root@griffinbassman.localdomain>
  • Loading branch information
bassmang and root committed May 21, 2021
1 parent a361623 commit 613c93c
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions vowpalwabbit/cb_explore_adf_bag.cc
Expand Up @@ -12,6 +12,7 @@
#include "gen_cs_example.h"
#include "cb_explore.h"
#include "explore.h"
#include "label_parser.h"
#include <vector>
#include <algorithm>
#include <cmath>
Expand Down Expand Up @@ -178,16 +179,18 @@ VW::LEARNER::base_learner* setup(VW::config::options_i& options, vw& all)
bool with_metrics = options.was_supplied("extra_metrics");

using explore_type = cb_explore_adf_base<cb_explore_adf_bag>;
auto data = scoped_calloc_or_throw<explore_type>(
with_metrics, epsilon, bag_size, greedify, first_only, all.get_random_state());

VW::LEARNER::learner<explore_type, multi_ex>& l = VW::LEARNER::init_learner(data, base, explore_type::learn,
explore_type::predict, problem_multiplier, prediction_type_t::action_probs, all.get_setupfn_name(setup) + "-bag");

l.set_finish_example(finish_bag_example);
l.set_print_example(print_bag_example);
l.set_persist_metrics(explore_type::persist_metrics);
return make_base(l);
auto data =
VW::make_unique<explore_type>(with_metrics, epsilon, bag_size, greedify, first_only, all.get_random_state());
auto* l = make_reduction_learner(
std::move(data), base, explore_type::learn, explore_type::predict, all.get_setupfn_name(setup) + "-bag")
.set_params_per_weight(problem_multiplier)
.set_prediction_type(prediction_type_t::action_probs)
.set_label_type(label_type_t::cb)
.set_finish_example(finish_bag_example)
.set_print_example(print_bag_example)
.set_persist_metrics(explore_type::persist_metrics)
.build();
return make_base(*l);
}

} // namespace bag
Expand Down

0 comments on commit 613c93c

Please sign in to comment.