Vowpal Wabbit
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ezexample Class Reference

#include <ezexample.h>

Public Member Functions

 ezexample (vw *this_vw, bool multiline=false, vw *this_vw_parser=nullptr)
 
 ezexample (vw *this_vw, example *this_ec, bool multiline=false, vw *this_vw_parser=nullptr)
 
 ~ezexample ()
 
bool ensure_ns_exists (char c)
 
void addns (char c)
 
void remns ()
 
fid addf (char to_ns, fid fint, float v)
 
fid addf (fid fint, float v)
 
void add_other_example_ns (example &other, char other_ns, char to_ns)
 
void add_other_example_ns (example &other, char ns)
 
void add_other_example_ns (ezexample &other, char other_ns, char to_ns)
 
void add_other_example_ns (ezexample &other, char ns)
 
ezexampleset_label (std::string label)
 
void mini_setup_example ()
 
size_t get_num_features ()
 
exampleget ()
 
float predict ()
 
float predict_partial ()
 
void train ()
 
void clear_features ()
 
void finish ()
 
fid hash (std::string fstr)
 
fid hash (char *fstr)
 
fid hash (char c, std::string fstr)
 
fid hash (char c, char *fstr)
 
fid addf (fid fint)
 
fid addf (std::string fstr, float val)
 
fid addf (std::string fstr)
 
fid addf (char ns, fid fint)
 
fid addf (char ns, std::string fstr, float val)
 
fid addf (char ns, std::string fstr)
 
ezexampleoperator() (const vw_namespace &n)
 
ezexampleoperator() (fid fint)
 
ezexampleoperator() (std::string fstr)
 
ezexampleoperator() (const char *fstr)
 
ezexampleoperator() (fid fint, float val)
 
ezexampleoperator() (std::string fstr, float val)
 
ezexampleoperator() (const char *fstr, float val)
 
ezexampleoperator() (char ns, fid fint)
 
ezexampleoperator() (char ns, std::string fstr)
 
ezexampleoperator() (char ns, const char *fstr)
 
ezexampleoperator() (char ns, fid fint, float val)
 
ezexampleoperator() (char ns, std::string fstr, float val)
 
ezexampleoperator() (char ns, const char *fstr, float val)
 
ezexampleoperator() (example &other, char other_ns, char to_ns)
 
ezexampleoperator() (example &other, char ns)
 
ezexampleoperator() (ezexample &other, char other_ns, char to_ns)
 
ezexampleoperator() (ezexample &other, char ns)
 
ezexampleoperator-- ()
 
float operator() ()
 

Private Member Functions

 ezexample (const ezexample &ex)=delete
 
ezexampleoperator= (const ezexample &ex)=delete
 
exampleget_new_example ()
 
void setup_new_ezexample (vw *this_vw, bool multiline, vw *this_vw_parser)
 
void setup_for_predict ()
 

Private Attributes

vwvw_ref
 
vwvw_par_ref
 
bool is_multiline
 
char str [2]
 
exampleec
 
bool we_create_ec
 
std::vector< fidpast_seeds
 
fid current_seed
 
size_t quadratic_features_num
 
float quadratic_features_sqr
 
char current_ns
 
bool ns_exists [256]
 
bool example_changed_since_prediction
 
v_array< example * > example_copies
 

Detailed Description

Definition at line 16 of file ezexample.h.

Constructor & Destructor Documentation

◆ ezexample() [1/3]

ezexample::ezexample ( const ezexample ex)
privatedelete

◆ ezexample() [2/3]

ezexample::ezexample ( vw this_vw,
bool  multiline = false,
vw this_vw_parser = nullptr 
)
inline

Definition at line 93 of file ezexample.h.

References vw::add_constant, and VW::add_constant_feature().

94  {
95  setup_new_ezexample(this_vw, multiline, this_vw_parser);
96  example_copies = v_init<example*>();
97  ec = get_new_example();
98  we_create_ec = true;
99 
100  if (vw_ref->add_constant)
102  }
bool add_constant
Definition: global_data.h:496
v_array< example * > example_copies
Definition: ezexample.h:34
vw * vw_ref
Definition: ezexample.h:19
example * ec
Definition: ezexample.h:24
bool we_create_ec
Definition: ezexample.h:25
void add_constant_feature(vw &vw, example *ec)
Definition: parser.cc:774
example * get_new_example()
Definition: ezexample.h:39
void setup_new_ezexample(vw *this_vw, bool multiline, vw *this_vw_parser)
Definition: ezexample.h:58

◆ ezexample() [3/3]

ezexample::ezexample ( vw this_vw,
example this_ec,
bool  multiline = false,
vw this_vw_parser = nullptr 
)
inline

Definition at line 107 of file ezexample.h.

References VW::hash_space(), and example_predict::indices.

108  {
109  setup_new_ezexample(this_vw, multiline, this_vw_parser);
110 
111  ec = this_ec;
112  we_create_ec = false;
113 
114  for (auto ns : ec->indices) ns_exists[ns] = true;
115  if (current_ns != 0)
116  {
117  str[0] = current_ns;
119  }
120  }
fid current_seed
Definition: ezexample.h:27
v_array< namespace_index > indices
bool ns_exists[256]
Definition: ezexample.h:31
vw * vw_ref
Definition: ezexample.h:19
example * ec
Definition: ezexample.h:24
bool we_create_ec
Definition: ezexample.h:25
char str[2]
Definition: ezexample.h:23
char current_ns
Definition: ezexample.h:30
uint64_t hash_space(vw &all, const std::string &s)
Definition: vw.h:138
void setup_new_ezexample(vw *this_vw, bool multiline, vw *this_vw_parser)
Definition: ezexample.h:58

◆ ~ezexample()

ezexample::~ezexample ( )
inline

Definition at line 122 of file ezexample.h.

References VW::finish_example(), example::in_use, and VW::is_ring_example().

123  {
126  for (auto ecc : example_copies)
127  if (ecc->in_use && VW::is_ring_example(*vw_par_ref, ec))
129  example_copies.clear();
130  free(example_copies.begin());
131  }
bool is_ring_example(vw &all, example *ae)
Definition: parser.cc:1009
vw * vw_par_ref
Definition: ezexample.h:20
v_array< example * > example_copies
Definition: ezexample.h:34
example * ec
Definition: ezexample.h:24
void finish_example(vw &, example &)
Definition: parser.cc:881
bool in_use
Definition: example.h:79

Member Function Documentation

◆ add_other_example_ns() [1/4]

void ezexample::add_other_example_ns ( example other,
char  other_ns,
char  to_ns 
)
inline

Definition at line 198 of file ezexample.h.

References example_predict::feature_space, features::indicies, example::num_features, features::size(), features::sum_feat_sq, example::total_sum_feat_sq, and features::values.

199  {
200  if (ensure_ns_exists(to_ns))
201  return;
202  features& fs = other.feature_space[(int)other_ns];
203  for (size_t i = 0; i < fs.size(); i++) ec->feature_space[(int)to_ns].push_back(fs.values[i], fs.indicies[i]);
205  ec->num_features += fs.size();
207  }
v_array< feature_index > indicies
the core definition of a set of features.
v_array< feature_value > values
bool example_changed_since_prediction
Definition: ezexample.h:32
example * ec
Definition: ezexample.h:24
bool ensure_ns_exists(char c)
Definition: ezexample.h:133
std::array< features, NUM_NAMESPACES > feature_space
size_t size() const
size_t num_features
Definition: example.h:67
float total_sum_feat_sq
Definition: example.h:71
float sum_feat_sq

◆ add_other_example_ns() [2/4]

void ezexample::add_other_example_ns ( example other,
char  ns 
)
inline

Definition at line 208 of file ezexample.h.

209  {
210  add_other_example_ns(other, ns, ns);
211  }
void add_other_example_ns(example &other, char other_ns, char to_ns)
Definition: ezexample.h:198

◆ add_other_example_ns() [3/4]

void ezexample::add_other_example_ns ( ezexample other,
char  other_ns,
char  to_ns 
)
inline

Definition at line 213 of file ezexample.h.

References ec.

214  {
215  add_other_example_ns(*other.ec, other_ns, to_ns);
216  }
example * ec
Definition: ezexample.h:24
void add_other_example_ns(example &other, char other_ns, char to_ns)
Definition: ezexample.h:198

◆ add_other_example_ns() [4/4]

void ezexample::add_other_example_ns ( ezexample other,
char  ns 
)
inline

Definition at line 217 of file ezexample.h.

References add_other_example_ns(), and ec.

Referenced by add_other_example_ns().

217 { add_other_example_ns(*other.ec, ns); }
example * ec
Definition: ezexample.h:24
void add_other_example_ns(example &other, char other_ns, char to_ns)
Definition: ezexample.h:198

◆ addf() [1/8]

fid ezexample::addf ( char  to_ns,
fid  fint,
float  v 
)
inline

Definition at line 181 of file ezexample.h.

References example_predict::feature_space, example::num_features, parameters::stride_shift(), example::total_sum_feat_sq, and vw::weights.

182  {
183  if (to_ns == 0)
184  return 0;
185  if (ensure_ns_exists(to_ns))
186  return 0;
187 
188  ec->feature_space[(int)to_ns].push_back(v, fint << vw_ref->weights.stride_shift());
189  ec->total_sum_feat_sq += v * v;
190  ec->num_features++;
192  return fint;
193  }
parameters weights
Definition: global_data.h:537
bool example_changed_since_prediction
Definition: ezexample.h:32
vw * vw_ref
Definition: ezexample.h:19
example * ec
Definition: ezexample.h:24
bool ensure_ns_exists(char c)
Definition: ezexample.h:133
std::array< features, NUM_NAMESPACES > feature_space
size_t num_features
Definition: example.h:67
float total_sum_feat_sq
Definition: example.h:71
uint32_t stride_shift()

◆ addf() [2/8]

fid ezexample::addf ( fid  fint,
float  v 
)
inline

Definition at line 195 of file ezexample.h.

References addf().

Referenced by addf().

195 { return addf(current_ns, fint, v); }
fid addf(char to_ns, fid fint, float v)
Definition: ezexample.h:181
char current_ns
Definition: ezexample.h:30

◆ addf() [3/8]

fid ezexample::addf ( fid  fint)
inline

Definition at line 329 of file ezexample.h.

References addf().

Referenced by addf().

329 { return addf(fint, 1.0); }
fid addf(char to_ns, fid fint, float v)
Definition: ezexample.h:181

◆ addf() [4/8]

fid ezexample::addf ( std::string  fstr,
float  val 
)
inline

Definition at line 330 of file ezexample.h.

References addf().

Referenced by addf().

330 { return addf(hash(fstr), val); }
fid addf(char to_ns, fid fint, float v)
Definition: ezexample.h:181
fid hash(std::string fstr)
Definition: ezexample.h:316

◆ addf() [5/8]

fid ezexample::addf ( std::string  fstr)
inline

Definition at line 331 of file ezexample.h.

References addf().

Referenced by addf().

331 { return addf(hash(fstr), 1.0); }
fid addf(char to_ns, fid fint, float v)
Definition: ezexample.h:181
fid hash(std::string fstr)
Definition: ezexample.h:316

◆ addf() [6/8]

fid ezexample::addf ( char  ns,
fid  fint 
)
inline

Definition at line 333 of file ezexample.h.

References addf().

Referenced by addf().

333 { return addf(ns, fint, 1.0); }
fid addf(char to_ns, fid fint, float v)
Definition: ezexample.h:181

◆ addf() [7/8]

fid ezexample::addf ( char  ns,
std::string  fstr,
float  val 
)
inline

Definition at line 334 of file ezexample.h.

References addf().

Referenced by addf().

334 { return addf(ns, hash(ns, fstr), val); }
fid addf(char to_ns, fid fint, float v)
Definition: ezexample.h:181
fid hash(std::string fstr)
Definition: ezexample.h:316

◆ addf() [8/8]

fid ezexample::addf ( char  ns,
std::string  fstr 
)
inline

Definition at line 335 of file ezexample.h.

References addf().

Referenced by addf().

335 { return addf(ns, hash(ns, fstr), 1.0); }
fid addf(char to_ns, fid fint, float v)
Definition: ezexample.h:181
fid hash(std::string fstr)
Definition: ezexample.h:316

◆ addns()

void ezexample::addns ( char  c)
inline

Definition at line 144 of file ezexample.h.

References c, example_predict::feature_space, and VW::hash_space().

145  {
146  if (ensure_ns_exists(c))
147  return;
148 
149  ec->feature_space[(int)c].clear();
150  past_seeds.push_back(current_seed);
151  current_ns = c;
152  str[0] = c;
154  }
fid current_seed
Definition: ezexample.h:27
vw * vw_ref
Definition: ezexample.h:19
std::vector< fid > past_seeds
Definition: ezexample.h:26
example * ec
Definition: ezexample.h:24
bool ensure_ns_exists(char c)
Definition: ezexample.h:133
std::array< features, NUM_NAMESPACES > feature_space
char str[2]
Definition: ezexample.h:23
char current_ns
Definition: ezexample.h:30
uint64_t hash_space(vw &all, const std::string &s)
Definition: vw.h:138
constexpr uint64_t c
Definition: rand48.cc:12

◆ clear_features()

void ezexample::clear_features ( )
inline

Definition at line 291 of file ezexample.h.

292  {
293  for (size_t i = 0; i < 256; i++)
294  {
295  if (current_ns == 0)
296  break;
297  remns();
298  }
299  }
void remns()
Definition: ezexample.h:156
char current_ns
Definition: ezexample.h:30

◆ ensure_ns_exists()

bool ezexample::ensure_ns_exists ( char  c)
inline

Definition at line 133 of file ezexample.h.

References vw::ignore, vw::ignore_some, example_predict::indices, and v_array< T >::push_back().

134  {
135  if (vw_ref->ignore_some && vw_ref->ignore[(int)c])
136  return true;
137  if (ns_exists[(int)c])
138  return false;
139  ec->indices.push_back((size_t)c);
140  ns_exists[(int)c] = true;
141  return false;
142  }
v_array< namespace_index > indices
bool ns_exists[256]
Definition: ezexample.h:31
vw * vw_ref
Definition: ezexample.h:19
std::array< bool, NUM_NAMESPACES > ignore
Definition: global_data.h:463
example * ec
Definition: ezexample.h:24
bool ignore_some
Definition: global_data.h:462
void push_back(const T &new_ele)
Definition: v_array.h:107
constexpr uint64_t c
Definition: rand48.cc:12

◆ finish()

void ezexample::finish ( )
inline

Definition at line 301 of file ezexample.h.

References VW::empty_example(), VW::finish_example(), vw::learn(), and VW::read_example().

302  {
303  static example* empty_example = is_multiline ? VW::read_example(*vw_par_ref, (char*)"") : nullptr;
304  if (is_multiline)
305  {
306  vw_ref->learn(*empty_example);
307  for (auto ecc : example_copies)
308  if (ecc->in_use)
310  example_copies.clear();
311  }
312  }
void learn(example &)
Definition: global_data.cc:137
vw * vw_par_ref
Definition: ezexample.h:20
v_array< example * > example_copies
Definition: ezexample.h:34
vw * vw_ref
Definition: ezexample.h:19
bool is_multiline
Definition: ezexample.h:21
void empty_example(vw &, example &ec)
Definition: parser.cc:857
void finish_example(vw &, example &)
Definition: parser.cc:881
example * read_example(vw &all, char *example_line)
Definition: parser.cc:761

◆ get()

example* ezexample::get ( )
inline

Definition at line 249 of file ezexample.h.

250  {
253  return ec;
254  }
bool example_changed_since_prediction
Definition: ezexample.h:32
example * ec
Definition: ezexample.h:24
void mini_setup_example()
Definition: ezexample.h:226

◆ get_new_example()

example* ezexample::get_new_example ( )
inlineprivate

Definition at line 39 of file ezexample.h.

References v_array< T >::clear(), example::confidence, label_parser::default_label, example_predict::feature_space, example_predict::ft_offset, example_predict::indices, example::l, example::loss, parser::lp, VW::new_unused_example(), example::num_features, vw::p, example::partial_prediction, example::passthrough, example::tag, example::total_sum_feat_sq, and example::updated_prediction.

40  {
42  vw_par_ref->p->lp.default_label(&new_ec->l);
43  new_ec->tag.clear();
44  new_ec->indices.clear();
45  for (auto& i : new_ec->feature_space) i.clear();
46 
47  new_ec->ft_offset = 0;
48  new_ec->num_features = 0;
49  new_ec->partial_prediction = 0.;
50  new_ec->updated_prediction = 0.;
51  new_ec->passthrough = nullptr;
52  new_ec->loss = 0.;
53  new_ec->total_sum_feat_sq = 0.;
54  new_ec->confidence = 0.;
55  return new_ec;
56  }
v_array< char > tag
Definition: example.h:63
v_array< namespace_index > indices
vw * vw_par_ref
Definition: ezexample.h:20
void(* default_label)(void *)
Definition: label_parser.h:12
float confidence
Definition: example.h:72
float partial_prediction
Definition: example.h:68
float updated_prediction
Definition: example.h:69
parser * p
Definition: global_data.h:377
std::array< features, NUM_NAMESPACES > feature_space
void clear()
Definition: v_array.h:88
size_t num_features
Definition: example.h:67
float loss
Definition: example.h:70
polylabel l
Definition: example.h:57
float total_sum_feat_sq
Definition: example.h:71
features * passthrough
Definition: example.h:74
example * new_unused_example(vw &all)
Definition: parser.cc:753
label_parser lp
Definition: parser.h:102

◆ get_num_features()

size_t ezexample::get_num_features ( )
inline

Definition at line 247 of file ezexample.h.

References example::num_features.

247 { return ec->num_features; }
example * ec
Definition: ezexample.h:24
size_t num_features
Definition: example.h:67

◆ hash() [1/4]

fid ezexample::hash ( std::string  fstr)
inline

Definition at line 316 of file ezexample.h.

References VW::hash_feature().

316 { return VW::hash_feature(*vw_ref, fstr, current_seed); }
fid current_seed
Definition: ezexample.h:27
vw * vw_ref
Definition: ezexample.h:19
uint64_t hash_feature(vw &all, const std::string &s, uint64_t u)
Definition: vw.h:153

◆ hash() [2/4]

fid ezexample::hash ( char *  fstr)
inline

Definition at line 317 of file ezexample.h.

References VW::hash_feature_cstr().

317 { return VW::hash_feature_cstr(*vw_ref, fstr, current_seed); }
fid current_seed
Definition: ezexample.h:27
vw * vw_ref
Definition: ezexample.h:19
uint64_t hash_feature_cstr(vw &all, char *fstr, uint64_t u)
Definition: vw.h:169

◆ hash() [3/4]

fid ezexample::hash ( char  c,
std::string  fstr 
)
inline

Definition at line 318 of file ezexample.h.

References c, VW::hash_feature(), and VW::hash_space().

319  {
320  str[0] = c;
321  return VW::hash_feature(*vw_ref, fstr, VW::hash_space(*vw_ref, str));
322  }
vw * vw_ref
Definition: ezexample.h:19
char str[2]
Definition: ezexample.h:23
uint64_t hash_feature(vw &all, const std::string &s, uint64_t u)
Definition: vw.h:153
uint64_t hash_space(vw &all, const std::string &s)
Definition: vw.h:138
constexpr uint64_t c
Definition: rand48.cc:12

◆ hash() [4/4]

fid ezexample::hash ( char  c,
char *  fstr 
)
inline

Definition at line 323 of file ezexample.h.

References c, VW::hash_feature_cstr(), and VW::hash_space().

324  {
325  str[0] = c;
327  }
vw * vw_ref
Definition: ezexample.h:19
uint64_t hash_feature_cstr(vw &all, char *fstr, uint64_t u)
Definition: vw.h:169
char str[2]
Definition: ezexample.h:23
uint64_t hash_space(vw &all, const std::string &s)
Definition: vw.h:138
constexpr uint64_t c
Definition: rand48.cc:12

◆ mini_setup_example()

void ezexample::mini_setup_example ( )
inline

Definition at line 226 of file ezexample.h.

References example_predict::feature_space, label_parser::get_weight, example::l, parser::lp, example::num_features, vw::p, vw::pairs, example::partial_prediction, example::total_sum_feat_sq, and example::weight.

227  {
228  ec->partial_prediction = 0.;
229  ec->weight = vw_par_ref->p->lp.get_weight(&ec->l);
230 
233 
236 
237  for (auto const& pair : vw_ref->pairs)
238  {
239  quadratic_features_num += ec->feature_space[(int)pair[0]].size() * ec->feature_space[(int)pair[1]].size();
241  ec->feature_space[(int)pair[0]].sum_feat_sq * ec->feature_space[(int)pair[1]].sum_feat_sq;
242  }
245  }
std::vector< std::string > pairs
Definition: global_data.h:459
vw * vw_par_ref
Definition: ezexample.h:20
float partial_prediction
Definition: example.h:68
vw * vw_ref
Definition: ezexample.h:19
example * ec
Definition: ezexample.h:24
parser * p
Definition: global_data.h:377
std::array< features, NUM_NAMESPACES > feature_space
float(* get_weight)(void *)
Definition: label_parser.h:17
size_t num_features
Definition: example.h:67
float quadratic_features_sqr
Definition: ezexample.h:29
polylabel l
Definition: example.h:57
float total_sum_feat_sq
Definition: example.h:71
size_t quadratic_features_num
Definition: ezexample.h:28
float weight
Definition: example.h:62
label_parser lp
Definition: parser.h:102

◆ operator()() [1/18]

ezexample& ezexample::operator() ( const vw_namespace n)
inline

Definition at line 337 of file ezexample.h.

References vw_namespace::namespace_letter.

338  {
340  return *this;
341  }
char namespace_letter
Definition: ezexample.h:10
void addns(char c)
Definition: ezexample.h:144

◆ operator()() [2/18]

ezexample& ezexample::operator() ( fid  fint)
inline

Definition at line 343 of file ezexample.h.

344  {
345  addf(fint, 1.0);
346  return *this;
347  }
fid addf(char to_ns, fid fint, float v)
Definition: ezexample.h:181

◆ operator()() [3/18]

ezexample& ezexample::operator() ( std::string  fstr)
inline

Definition at line 348 of file ezexample.h.

349  {
350  addf(fstr, 1.0);
351  return *this;
352  }
fid addf(char to_ns, fid fint, float v)
Definition: ezexample.h:181

◆ operator()() [4/18]

ezexample& ezexample::operator() ( const char *  fstr)
inline

Definition at line 353 of file ezexample.h.

354  {
355  addf(fstr, 1.0);
356  return *this;
357  }
fid addf(char to_ns, fid fint, float v)
Definition: ezexample.h:181

◆ operator()() [5/18]

ezexample& ezexample::operator() ( fid  fint,
float  val 
)
inline

Definition at line 358 of file ezexample.h.

359  {
360  addf(fint, val);
361  return *this;
362  }
fid addf(char to_ns, fid fint, float v)
Definition: ezexample.h:181

◆ operator()() [6/18]

ezexample& ezexample::operator() ( std::string  fstr,
float  val 
)
inline

Definition at line 363 of file ezexample.h.

364  {
365  addf(fstr, val);
366  return *this;
367  }
fid addf(char to_ns, fid fint, float v)
Definition: ezexample.h:181

◆ operator()() [7/18]

ezexample& ezexample::operator() ( const char *  fstr,
float  val 
)
inline

Definition at line 368 of file ezexample.h.

369  {
370  addf(fstr, val);
371  return *this;
372  }
fid addf(char to_ns, fid fint, float v)
Definition: ezexample.h:181

◆ operator()() [8/18]

ezexample& ezexample::operator() ( char  ns,
fid  fint 
)
inline

Definition at line 374 of file ezexample.h.

375  {
376  addf(ns, fint, 1.0);
377  return *this;
378  }
fid addf(char to_ns, fid fint, float v)
Definition: ezexample.h:181

◆ operator()() [9/18]

ezexample& ezexample::operator() ( char  ns,
std::string  fstr 
)
inline

Definition at line 379 of file ezexample.h.

380  {
381  addf(ns, fstr, 1.0);
382  return *this;
383  }
fid addf(char to_ns, fid fint, float v)
Definition: ezexample.h:181

◆ operator()() [10/18]

ezexample& ezexample::operator() ( char  ns,
const char *  fstr 
)
inline

Definition at line 384 of file ezexample.h.

385  {
386  addf(ns, fstr, 1.0);
387  return *this;
388  }
fid addf(char to_ns, fid fint, float v)
Definition: ezexample.h:181

◆ operator()() [11/18]

ezexample& ezexample::operator() ( char  ns,
fid  fint,
float  val 
)
inline

Definition at line 389 of file ezexample.h.

390  {
391  addf(ns, fint, val);
392  return *this;
393  }
fid addf(char to_ns, fid fint, float v)
Definition: ezexample.h:181

◆ operator()() [12/18]

ezexample& ezexample::operator() ( char  ns,
std::string  fstr,
float  val 
)
inline

Definition at line 394 of file ezexample.h.

395  {
396  addf(ns, fstr, val);
397  return *this;
398  }
fid addf(char to_ns, fid fint, float v)
Definition: ezexample.h:181

◆ operator()() [13/18]

ezexample& ezexample::operator() ( char  ns,
const char *  fstr,
float  val 
)
inline

Definition at line 399 of file ezexample.h.

400  {
401  addf(ns, fstr, val);
402  return *this;
403  }
fid addf(char to_ns, fid fint, float v)
Definition: ezexample.h:181

◆ operator()() [14/18]

ezexample& ezexample::operator() ( example other,
char  other_ns,
char  to_ns 
)
inline

Definition at line 405 of file ezexample.h.

406  {
407  add_other_example_ns(other, other_ns, to_ns);
408  return *this;
409  }
void add_other_example_ns(example &other, char other_ns, char to_ns)
Definition: ezexample.h:198

◆ operator()() [15/18]

ezexample& ezexample::operator() ( example other,
char  ns 
)
inline

Definition at line 410 of file ezexample.h.

411  {
412  add_other_example_ns(other, ns);
413  return *this;
414  }
void add_other_example_ns(example &other, char other_ns, char to_ns)
Definition: ezexample.h:198

◆ operator()() [16/18]

ezexample& ezexample::operator() ( ezexample other,
char  other_ns,
char  to_ns 
)
inline

Definition at line 415 of file ezexample.h.

416  {
417  add_other_example_ns(other, other_ns, to_ns);
418  return *this;
419  }
void add_other_example_ns(example &other, char other_ns, char to_ns)
Definition: ezexample.h:198

◆ operator()() [17/18]

ezexample& ezexample::operator() ( ezexample other,
char  ns 
)
inline

Definition at line 420 of file ezexample.h.

421  {
422  add_other_example_ns(other, ns);
423  return *this;
424  }
void add_other_example_ns(example &other, char other_ns, char to_ns)
Definition: ezexample.h:198

◆ operator()() [18/18]

float ezexample::operator() ( )
inline

Definition at line 432 of file ezexample.h.

References predict().

432 { return predict(); }
float predict()
Definition: ezexample.h:256

◆ operator--()

ezexample& ezexample::operator-- ( )
inline

Definition at line 426 of file ezexample.h.

427  {
428  remns();
429  return *this;
430  }
void remns()
Definition: ezexample.h:156

◆ operator=()

ezexample& ezexample::operator= ( const ezexample ex)
privatedelete

◆ predict()

float ezexample::predict ( )
inline

Definition at line 256 of file ezexample.h.

References example::pred, and polyprediction::scalar.

257  {
259  return ec->pred.scalar;
260  }
float scalar
Definition: example.h:45
example * ec
Definition: ezexample.h:24
void setup_for_predict()
Definition: ezexample.h:77
polyprediction pred
Definition: example.h:60

◆ predict_partial()

float ezexample::predict_partial ( )
inline

Definition at line 262 of file ezexample.h.

References example::partial_prediction.

263  {
265  return ec->partial_prediction;
266  }
float partial_prediction
Definition: example.h:68
example * ec
Definition: ezexample.h:24
void setup_for_predict()
Definition: ezexample.h:77

◆ remns()

void ezexample::remns ( )
inline

Definition at line 156 of file ezexample.h.

References v_array< T >::empty(), example_predict::feature_space, example_predict::indices, example::num_features, v_array< T >::pop(), and example::total_sum_feat_sq.

157  {
158  if (ec->indices.empty())
159  {
160  current_seed = 0;
161  current_ns = 0;
162  }
163  else
164  {
165  if (ns_exists[(int)current_ns])
166  {
167  ec->total_sum_feat_sq -= ec->feature_space[(int)current_ns].sum_feat_sq;
168  ec->feature_space[(int)current_ns].clear();
169  ec->num_features -= ec->feature_space[(int)current_ns].size();
170 
171  ns_exists[(int)current_ns] = false;
172  }
173 
174  current_seed = past_seeds.back();
175  past_seeds.pop_back();
176  ec->indices.pop();
178  }
179  }
fid current_seed
Definition: ezexample.h:27
v_array< namespace_index > indices
T pop()
Definition: v_array.h:58
bool ns_exists[256]
Definition: ezexample.h:31
bool example_changed_since_prediction
Definition: ezexample.h:32
std::vector< fid > past_seeds
Definition: ezexample.h:26
example * ec
Definition: ezexample.h:24
std::array< features, NUM_NAMESPACES > feature_space
size_t num_features
Definition: example.h:67
char current_ns
Definition: ezexample.h:30
float total_sum_feat_sq
Definition: example.h:71
bool empty() const
Definition: v_array.h:59

◆ set_label()

ezexample& ezexample::set_label ( std::string  label)
inline

Definition at line 219 of file ezexample.h.

References VW::parse_example_label().

220  {
223  return *this;
224  }
void parse_example_label(vw &all, example &ec, std::string label)
Definition: parser.cc:846
vw * vw_par_ref
Definition: ezexample.h:20
bool example_changed_since_prediction
Definition: ezexample.h:32
example * ec
Definition: ezexample.h:24

◆ setup_for_predict()

void ezexample::setup_for_predict ( )
inlineprivate

Definition at line 77 of file ezexample.h.

References VW::empty_example(), vw::learn(), and VW::read_example().

78  {
79  static example* empty_example = is_multiline ? VW::read_example(*vw_par_ref, (char*)"") : nullptr;
81  {
83  vw_ref->learn(*ec);
84  if (is_multiline)
85  vw_ref->learn(*empty_example);
87  }
88  }
void learn(example &)
Definition: global_data.cc:137
vw * vw_par_ref
Definition: ezexample.h:20
bool example_changed_since_prediction
Definition: ezexample.h:32
vw * vw_ref
Definition: ezexample.h:19
bool is_multiline
Definition: ezexample.h:21
example * ec
Definition: ezexample.h:24
void mini_setup_example()
Definition: ezexample.h:226
void empty_example(vw &, example &ec)
Definition: parser.cc:857
example * read_example(vw &all, char *example_line)
Definition: parser.cc:761

◆ setup_new_ezexample()

void ezexample::setup_new_ezexample ( vw this_vw,
bool  multiline,
vw this_vw_parser 
)
inlineprivate

Definition at line 58 of file ezexample.h.

59  {
60  vw_ref = this_vw;
61  vw_par_ref = (this_vw_parser == nullptr) ? this_vw : this_vw_parser;
62  is_multiline = multiline;
63 
64  str[0] = 0;
65  str[1] = 0;
66  current_seed = 0;
67  current_ns = 0;
68 
71 
72  for (bool& ns_exist : ns_exists) ns_exist = false;
73 
75  }
fid current_seed
Definition: ezexample.h:27
vw * vw_par_ref
Definition: ezexample.h:20
bool ns_exists[256]
Definition: ezexample.h:31
bool example_changed_since_prediction
Definition: ezexample.h:32
vw * vw_ref
Definition: ezexample.h:19
bool is_multiline
Definition: ezexample.h:21
char str[2]
Definition: ezexample.h:23
char current_ns
Definition: ezexample.h:30
float quadratic_features_sqr
Definition: ezexample.h:29
size_t quadratic_features_num
Definition: ezexample.h:28

◆ train()

void ezexample::train ( )
inline

Definition at line 268 of file ezexample.h.

References vw::audit, VW::copy_example_data(), label_parser::copy_label, example::in_use, label_parser::label_size, vw::learn(), parser::lp, vw::p, and v_array< T >::push_back().

269  {
271  {
274  }
275 
276  if (!is_multiline)
277  {
278  vw_ref->learn(*ec);
279  }
280  else // is multiline
281  { // we need to make a copy
282  example* copy = get_new_example();
283  assert(ec->in_use);
285  assert(copy->in_use);
286  vw_ref->learn(*copy);
288  }
289  }
void learn(example &)
Definition: global_data.cc:137
void(* copy_label)(void *, void *)
Definition: label_parser.h:18
vw * vw_par_ref
Definition: ezexample.h:20
void copy_example_data(bool audit, example *dst, example *src)
Definition: example.cc:72
v_array< example * > example_copies
Definition: ezexample.h:34
bool example_changed_since_prediction
Definition: ezexample.h:32
vw * vw_ref
Definition: ezexample.h:19
bool is_multiline
Definition: ezexample.h:21
example * ec
Definition: ezexample.h:24
parser * p
Definition: global_data.h:377
void push_back(const T &new_ele)
Definition: v_array.h:107
void mini_setup_example()
Definition: ezexample.h:226
bool in_use
Definition: example.h:79
size_t label_size
Definition: label_parser.h:23
bool audit
Definition: global_data.h:486
example * get_new_example()
Definition: ezexample.h:39
label_parser lp
Definition: parser.h:102

Member Data Documentation

◆ current_ns

char ezexample::current_ns
private

Definition at line 30 of file ezexample.h.

◆ current_seed

fid ezexample::current_seed
private

Definition at line 27 of file ezexample.h.

◆ ec

example* ezexample::ec
private

Definition at line 24 of file ezexample.h.

Referenced by add_other_example_ns().

◆ example_changed_since_prediction

bool ezexample::example_changed_since_prediction
private

Definition at line 32 of file ezexample.h.

◆ example_copies

v_array<example*> ezexample::example_copies
private

Definition at line 34 of file ezexample.h.

◆ is_multiline

bool ezexample::is_multiline
private

Definition at line 21 of file ezexample.h.

◆ ns_exists

bool ezexample::ns_exists[256]
private

Definition at line 31 of file ezexample.h.

◆ past_seeds

std::vector<fid> ezexample::past_seeds
private

Definition at line 26 of file ezexample.h.

◆ quadratic_features_num

size_t ezexample::quadratic_features_num
private

Definition at line 28 of file ezexample.h.

◆ quadratic_features_sqr

float ezexample::quadratic_features_sqr
private

Definition at line 29 of file ezexample.h.

◆ str

char ezexample::str[2]
private

Definition at line 23 of file ezexample.h.

◆ vw_par_ref

vw* ezexample::vw_par_ref
private

Definition at line 20 of file ezexample.h.

◆ vw_ref

vw* ezexample::vw_ref
private

Definition at line 19 of file ezexample.h.

◆ we_create_ec

bool ezexample::we_create_ec
private

Definition at line 25 of file ezexample.h.


The documentation for this class was generated from the following file: