3 #include "../vowpalwabbit/parser.h" 4 #include "../vowpalwabbit/vw.h" 61 vw_par_ref = (this_vw_parser ==
nullptr) ? this_vw : this_vw_parser;
62 is_multiline = multiline;
69 quadratic_features_num = 0;
70 quadratic_features_sqr = 0.;
72 for (
bool& ns_exist : ns_exists) ns_exist =
false;
74 example_changed_since_prediction =
true;
80 if (example_changed_since_prediction)
85 vw_ref->
learn(*empty_example);
86 example_changed_since_prediction =
false;
93 ezexample(
vw* this_vw,
bool multiline =
false,
vw* this_vw_parser =
nullptr)
95 setup_new_ezexample(this_vw, multiline, this_vw_parser);
96 example_copies = v_init<example*>();
97 ec = get_new_example();
109 setup_new_ezexample(this_vw, multiline, this_vw_parser);
112 we_create_ec =
false;
114 for (
auto ns : ec->
indices) ns_exists[ns] =
true;
126 for (
auto ecc : example_copies)
129 example_copies.clear();
130 free(example_copies.begin());
137 if (ns_exists[(
int)c])
140 ns_exists[(int)c] =
true;
146 if (ensure_ns_exists(c))
150 past_seeds.push_back(current_seed);
165 if (ns_exists[(
int)current_ns])
171 ns_exists[(int)current_ns] =
false;
174 current_seed = past_seeds.back();
175 past_seeds.pop_back();
177 example_changed_since_prediction =
true;
185 if (ensure_ns_exists(to_ns))
191 example_changed_since_prediction =
true;
200 if (ensure_ns_exists(to_ns))
206 example_changed_since_prediction =
true;
210 add_other_example_ns(other, ns, ns);
215 add_other_example_ns(*other.
ec, other_ns, to_ns);
222 example_changed_since_prediction =
true;
234 quadratic_features_num = 0;
235 quadratic_features_sqr = 0.;
237 for (
auto const& pair : vw_ref->
pairs)
240 quadratic_features_sqr +=
251 if (example_changed_since_prediction)
252 mini_setup_example();
270 if (example_changed_since_prediction)
272 mini_setup_example();
273 example_changed_since_prediction =
false;
282 example* copy = get_new_example();
286 vw_ref->
learn(*copy);
293 for (
size_t i = 0; i < 256; i++)
306 vw_ref->
learn(*empty_example);
307 for (
auto ecc : example_copies)
310 example_copies.clear();
330 inline fid addf(std::string fstr,
float val) {
return addf(hash(fstr), val); }
331 inline fid addf(std::string fstr) {
return addf(hash(fstr), 1.0); }
334 inline fid addf(
char ns, std::string fstr,
float val) {
return addf(ns, hash(ns, fstr), val); }
335 inline fid addf(
char ns, std::string fstr) {
return addf(ns, hash(ns, fstr), 1.0); }
407 add_other_example_ns(other, other_ns, to_ns);
412 add_other_example_ns(other, ns);
417 add_other_example_ns(other, other_ns, to_ns);
422 add_other_example_ns(other, ns);
ezexample & operator()(char ns, fid fint)
v_array< namespace_index > indices
fid addf(std::string fstr)
bool is_ring_example(vw &all, example *ae)
void parse_example_label(vw &all, example &ec, std::string label)
void(* copy_label)(void *, void *)
ezexample & operator()(char ns, const char *fstr, float val)
std::vector< std::string > pairs
fid hash(char c, std::string fstr)
void copy_example_data(bool audit, example *dst, example *src)
ezexample & operator()(ezexample &other, char ns)
ezexample & operator()(char ns, std::string fstr, float val)
v_array< feature_index > indicies
vw_namespace(const char c)
ezexample(vw *this_vw, example *this_ec, bool multiline=false, vw *this_vw_parser=nullptr)
void(* default_label)(void *)
fid addf(char ns, fid fint)
v_array< example * > example_copies
the core definition of a set of features.
void add_other_example_ns(ezexample &other, char other_ns, char to_ns)
v_array< feature_value > values
ezexample & operator()(char ns, std::string fstr)
ezexample & operator()(char ns, fid fint, float val)
ezexample & operator()(std::string fstr, float val)
bool example_changed_since_prediction
ezexample & operator()(const char *fstr, float val)
std::array< bool, NUM_NAMESPACES > ignore
std::vector< fid > past_seeds
ezexample & operator()(fid fint, float val)
fid hash(char c, char *fstr)
bool ensure_ns_exists(char c)
std::array< features, NUM_NAMESPACES > feature_space
ezexample & operator()(char ns, const char *fstr)
fid addf(fid fint, float v)
float(* get_weight)(void *)
void push_back(const T &new_ele)
fid addf(char to_ns, fid fint, float v)
uint64_t hash_feature_cstr(vw &all, char *fstr, uint64_t u)
ezexample & operator()(example &other, char ns)
void mini_setup_example()
ezexample & operator()(fid fint)
void empty_example(vw &, example &ec)
void add_constant_feature(vw &vw, example *ec)
ezexample & operator()(const vw_namespace &n)
ezexample & operator()(std::string fstr)
ezexample & set_label(std::string label)
void finish_example(vw &, example &)
size_t get_num_features()
ezexample & operator()(ezexample &other, char other_ns, char to_ns)
fid addf(char ns, std::string fstr, float val)
float quadratic_features_sqr
ezexample & operator()(const char *fstr)
example * read_example(vw &all, char *example_line)
example * new_unused_example(vw &all)
ezexample(vw *this_vw, bool multiline=false, vw *this_vw_parser=nullptr)
uint64_t hash_feature(vw &all, const std::string &s, uint64_t u)
uint64_t hash_space(vw &all, const std::string &s)
void predict(bfgs &b, base_learner &, example &ec)
void add_other_example_ns(example &other, char ns)
size_t quadratic_features_num
ezexample & operator()(example &other, char other_ns, char to_ns)
fid addf(std::string fstr, float val)
fid addf(char ns, std::string fstr)
void add_other_example_ns(ezexample &other, char ns)
example * get_new_example()
void setup_new_ezexample(vw *this_vw, bool multiline, vw *this_vw_parser)
fid hash(std::string fstr)
void add_other_example_ns(example &other, char other_ns, char to_ns)