52 template <
bool is_learn>
63 if (ld.
costs.size() == 0 ||
64 (ld.
costs.size() == 1 &&
65 ld.
costs[0].cost != FLT_MAX))
89 cs_ld.
costs.push_back(wc);
94 for (
auto& cl : ld.
costs)
99 wc.
x = CB_ALGS::get_cost_pred<is_learn>(c.
scorer, c.
known_cost, ec, cl.action, 0);
100 if (wc.
x < min || (wc.
x == min && cl.action < argmin))
116 cs_ld.
costs.push_back(wc);
123 template <
bool is_learn>
143 cs_ld.
costs.push_back(wc);
146 template <
bool is_learn>
151 if (ld.
costs.size() == 0)
155 cs_ld.
costs.push_back(temp);
157 else if (ld.
costs.size() == 0 || (ld.
costs.size() == 1 && ld.
costs[0].cost != FLT_MAX))
160 for (uint32_t i = 1; i <= c.
num_actions; i++) gen_cs_label<is_learn>(c, ec, cs_ld, i);
163 for (
auto& cl : ld.
costs) gen_cs_label<is_learn>(
c, ec, cs_ld, cl.action);
166 template <
bool is_learn>
175 gen_cs_example_dm<is_learn>(
c, ec, cs_ld);
178 gen_cs_example_dr<is_learn>(
c, ec, ld, cs_ld);
181 THROW(
"Unknown cb_type specified for contextual bandit learning: " << c.cb_type);
196 template <
bool is_learn>
201 cs_labels.
costs.clear();
202 for (
size_t i = 0; i < examples.size(); i++)
216 wc.
x = CB_ALGS::get_cost_pred<is_learn>(c.
scorer, &(c.
known_cost), *(examples[i]), 0, 2);
220 wc.
x = CB_ALGS::get_cost_pred<is_learn>(c.
scorer,
nullptr, *(examples[i]), 0, 2);
227 cs_labels.
costs.push_back(wc);
231 template <
bool is_learn>
240 gen_cs_example_dr<is_learn>(
c, ec_seq, cs_labels);
246 THROW(
"Unknown cb_type specified for contextual bandit learning: " << c.cb_type);
250 template <
bool is_learn>
255 if (prepped_cs_labels.
size() < cs_labels.
costs.size() + 1)
257 prepped_cs_labels.
resize(cs_labels.
costs.size() + 1);
263 uint64_t saved_offset = examples[0]->ft_offset;
265 for (
auto ec : examples)
268 prepped_cs_labels[index].costs.
clear();
270 ec->l.cs = prepped_cs_labels[index++];
271 ec->ft_offset = offset;
277 base.
learn(examples, (int32_t)
id);
279 base.
predict(examples, (int32_t)
id);
284 for (
size_t i = 0; i < examples.size(); ++i)
286 examples[i]->l.cb = cb_labels[i];
287 examples[i]->ft_offset = saved_offset;
void gen_cs_example_sm(multi_ex &, uint32_t chosen_action, float sign_offset, ACTION_SCORE::action_scores action_vals, COST_SENSITIVE::label &cs_labels)
void resize(size_t length)
void call_cs_ldf(LEARNER::multi_learner &base, multi_ex &examples, v_array< CB::label > &cb_labels, COST_SENSITIVE::label &cs_labels, v_array< COST_SENSITIVE::label > &prepped_cs_labels, uint64_t offset, size_t id=0)
bool example_is_newline_not_header(example const &ec)
COST_SENSITIVE::label pred_scores
void gen_cs_label(cb_to_cs &c, example &ec, COST_SENSITIVE::label &cs_ld, uint32_t action, float clip_p=0.f)
void predict(E &ec, size_t i=0)
cb_class * get_observed_cost(CB::label &ld)
v_array< cb_class > costs
void gen_cs_example_dm(multi_ex &examples, COST_SENSITIVE::label &cs_labels)
void gen_cs_example_dr(cb_to_cs &c, example &ec, CB::label &ld, COST_SENSITIVE::label &cs_ld, float=0.f)
CB::cb_class * known_cost
void push_back(const T &new_ele)
float avg_loss_regressors
LEARNER::single_learner * scorer
void gen_cs_example_ips(multi_ex &examples, COST_SENSITIVE::label &cs_labels, float clip_p)
void gen_cs_example(cb_to_cs &c, example &ec, CB::label &ld, COST_SENSITIVE::label &cs_ld)
std::vector< example * > multi_ex
float safe_probability(float prob)
void gen_cs_example_mtr(cb_to_cs_adf &c, multi_ex &ec_seq, COST_SENSITIVE::label &cs_labels)
LEARNER::single_learner * scorer
void learn(E &ec, size_t i=0)
void gen_cs_test_example(multi_ex &examples, COST_SENSITIVE::label &cs_labels)
COST_SENSITIVE::label pred_scores