28 cb_cs_ld.
costs.delete_v();
35 if (ld.
costs.size() <= 1)
41 for (
auto& cl : ld.
costs)
42 if (cl.cost == FLT_MAX)
48 template <
bool is_learn>
58 gen_cs_example<is_learn>(
c, ec, ld, data.
cb_cs_ld);
69 for (
size_t i = 0; i < ld.costs.size(); i++)
70 ld.costs[i].partial_prediction = data.
cb_cs_ld.
costs[i].partial_prediction;
85 for (
size_t i = 0; i < ld.
event.
costs.size(); i++)
88 ec.pred.multiclass = ec.l.cb_eval.action;
105 std::stringstream outputStringStream;
106 for (
unsigned int i = 0; i < ld.
costs.size(); i++)
110 outputStringStream <<
' ';
134 auto data = scoped_calloc_or_throw<cb>();
135 std::string type_string =
"dr";
140 .
add(
make_option(
"cb", data->cbcs.num_actions).keep().help(
"Use contextual bandit learning with <k> costs"))
141 .
add(
make_option(
"cb_type", type_string).keep().help(
"contextual bandit method to use in {ips,dm,dr}"))
142 .
add(
make_option(
"eval", eval).help(
"Evaluate a policy rather than optimizing."));
151 options.
insert(
"cb_type", type_string);
157 size_t problem_multiplier = 2;
158 if (type_string.compare(
"dr") == 0)
160 else if (type_string.compare(
"dm") == 0)
163 THROW(
"direct method can not be used for evaluation --- it is biased.");
165 problem_multiplier = 1;
167 else if (type_string.compare(
"ips") == 0)
170 problem_multiplier = 1;
174 std::cerr <<
"warning: cb_type must be in {'ips','dm','dr'}; resetting to dr." << std::endl;
180 std::stringstream ss;
181 ss << data->cbcs.num_actions;
182 options.
insert(
"csoaa", ss.str());
COST_SENSITIVE::label pred_scores
void predict(E &ec, size_t i=0)
void finish_example(vw &all, cb &c, example &ec)
void(* delete_label)(void *)
bool know_all_cost_example(CB::label &ld)
label_type::label_type_t label_type
COST_SENSITIVE::label cb_cs_ld
bool(* test_label)(void *)
v_array< int > final_prediction_sink
v_array< cb_class > costs
base_learner * make_base(learner< T, E > &base)
virtual void add_and_parse(const option_group_definition &group)=0
float loss(cbify &data, uint32_t label, uint32_t final_prediction)
void learn_eval(cb &data, single_learner &, example &ec)
float get_cost_estimate(CB::cb_class *observation, uint32_t action, float offset=0.)
CB::cb_class get_observed_cost(multi_ex &examples)
single_learner * as_singleline(learner< T, E > *l)
void print_update(vw &all, bool is_test, example &ec, multi_ex *ec_seq, bool action_scores)
CB::cb_class * known_cost
void set_finish_example(void(*f)(vw &all, T &, E &))
learner< T, E > & init_learner(free_ptr< T > &dat, L *base, void(*learn)(T &, L &, E &), void(*predict)(T &, L &, E &), size_t ws, prediction_type::prediction_type_t pred_type)
base_learner * cb_algs_setup(options_i &options, vw &all)
virtual bool was_supplied(const std::string &key)=0
void predict_eval(cb &, single_learner &, example &)
void(* print_text)(int, std::string, v_array< char >)
void predict_or_learn(cb &data, single_learner &base, example &ec)
LEARNER::single_learner * scorer
void finish_example(vw &, example &)
LEARNER::single_learner * scorer
virtual void insert(const std::string &key, const std::string &value)=0
void update(bool test_example, bool labeled_example, float loss, float weight, size_t num_features)
option_group_definition & add(T &&op)
int add(svm_params ¶ms, svm_example *fec)
typed_option< T > make_option(std::string name, T &location)
void eval_finish_example(vw &all, cb &c, example &ec)
void output_example(vw &all, cb &data, example &ec, CB::label &ld)
LEARNER::base_learner * setup_base(options_i &options, vw &all)
void learn(E &ec, size_t i=0)
void(* print)(int, float, float, v_array< char >)