43 for (
auto& i : feature_space) i.delete_v();
59 for (
auto& cl : ld.
costs)
67 if (val < 0 || floor(val) != val)
68 std::cout <<
"error " << val <<
" is not a valid action " << std::endl;
70 uint32_t value = (uint32_t)val;
73 if (!c.
evals[new_index].seen)
75 c.
evals[new_index].seen =
true;
79 c.
evals[new_index].action = value;
82 template <
bool learn,
bool exclude,
bool is_learn>
91 for (
unsigned char ns : ec.
indices)
97 c.
evals[policy].action = 0;
100 if (exclude ||
learn)
105 for (
unsigned char ns : ec.
indices)
114 uint64_t new_index = ((
f.index() & weight_mask) >> stride_shift) * c.
num_classes + (uint64_t)
f.value();
133 if (exclude ||
learn)
153 std::stringstream ss;
155 for (
size_t i = 0; i < scalars.
size(); i++)
161 for (
size_t i = 0; i < tag.
size(); i++)
168 ssize_t len = ss.str().
size();
171 std::cerr <<
"write error: " << strerror(errno) << std::endl;
200 std::stringstream msg;
203 msg <<
"total: " << c.
total;
229 msg <<
"evals: " << policy <<
":" << pd.
action <<
":" << pd.
cost <<
" ";
238 auto c = scoped_calloc_or_throw<mwt>();
240 bool exclude_eval =
false;
242 new_options.
add(
make_option(
"multiworld_test", s).keep().help(
"Evaluate features as a policies"))
243 .
add(
make_option(
"learn",
c->num_classes).help(
"Do Contextual Bandit learning on <n> classes."))
244 .
add(
make_option(
"exclude_eval", exclude_eval).help(
"Discard mwt policy features before learning"));
250 for (
char i : s)
c->namespaces[(
unsigned char)i] =
true;
254 c->evals.end() =
c->evals.begin() + all.
length();
260 if (
c->num_classes > 0)
266 std::stringstream ss;
267 ss <<
c->num_classes;
268 options.
insert(
"cb", ss.str());
void resize(size_t length)
v_array< namespace_index > indices
v_array< namespace_index > indices
void predict(E &ec, size_t i=0)
void(* delete_prediction)(void *)
uint64_t stride_shift(const stagewise_poly &poly, uint64_t idx)
void push_back(feature_value v, feature_index i)
void print_scalars(int f, v_array< float > &scalars, v_array< char > &tag)
static ssize_t write_file_or_socket(int f, const void *buf, size_t nbytes)
CB::cb_class * get_observed_cost(CB::label &ld)
features feature_space[256]
label_type::label_type_t label_type
v_array< int > final_prediction_sink
the core definition of a set of features.
v_array< cb_class > costs
v_array< uint64_t > policies
size_t bin_text_read_write_fixed_validated(io_buf &io, char *data, size_t len, const char *read_message, bool read, std::stringstream &msg, bool text)
base_learner * make_base(learner< T, E > &base)
void value_policy(mwt &c, float val, uint64_t index)
virtual void add_and_parse(const option_group_definition &group)=0
void set_save_load(void(*sl)(T &, io_buf &, bool, bool))
float loss(cbify &data, uint32_t label, uint32_t final_prediction)
float get_cost_estimate(CB::cb_class *observation, uint32_t action, float offset=0.)
bool observed_cost(CB::cb_class *cl)
void predict_or_learn(mwt &c, single_learner &base, example &ec)
std::array< features, NUM_NAMESPACES > feature_space
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)
void set_finish_example(void(*f)(vw &all, T &, E &))
CB::cb_class * observation
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)
void push_back(const T &new_ele)
base_learner * mwt_setup(options_i &options, vw &all)
void delete_scalars(void *v)
virtual bool was_supplied(const std::string &key)=0
void finish_example(vw &all, mwt &c, example &ec)
void calloc_reserve(v_array< T > &v, size_t length)
void finish_example(vw &, example &)
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)
iterator over values and indicies
void save_load(mwt &c, io_buf &model_file, bool read, bool text)
typed_option< T > make_option(std::string name, T &location)
LEARNER::base_learner * setup_base(options_i &options, vw &all)
void learn(E &ec, size_t i=0)
v_array< policy_data > evals
void learn(bfgs &b, base_learner &base, example &ec)