Vowpal Wabbit
Namespaces | Classes | Typedefs | Functions
VW Namespace Reference

Namespaces

 cb_explore_adf
 
 config
 
 shared_feature_merger
 

Classes

struct  autolink
 
struct  cb_sample_data
 
struct  default_cleanup
 
struct  no_lock_object_pool
 
struct  object_pool
 
struct  primitive_feature_space
 
class  ptr_queue
 
class  SpanningTree
 
class  strict_parse_exception
 
class  topk
 
struct  v_array_allocator
 
struct  v_array_deleter
 
struct  value_object_pool
 
struct  version_struct
 
class  vw_argument_disagreement_exception
 
class  vw_argument_invalid_value_exception
 
class  vw_exception
 
class  vw_unrecognised_option_exception
 

Typedefs

typedef example &(* example_factory_t) (void *)
 
template<typename T >
using v_array_pool = VW::value_object_pool< v_array< T >, v_array_allocator< T >, v_array_deleter< T > >
 

Functions

uint32_t convert (size_t number)
 
void copy_example_label (example *dst, example *src, size_t, void(*copy_label)(void *, void *))
 
void copy_example_metadata (bool, example *dst, example *src)
 
void copy_example_data (bool audit, example *dst, example *src)
 
void copy_example_data (bool audit, example *dst, example *src, size_t label_size, void(*copy_label)(void *, void *))
 
void move_feature_namespace (example *dst, example *src, namespace_index c)
 
featureget_features (vw &all, example *ec, size_t &feature_map_len)
 
void return_features (feature *f)
 
examplealloc_examples (size_t, size_t count=1)
 
void dealloc_example (void(*delete_label)(void *), example &ec, void(*delete_prediction)(void *))
 
void finish_example (vw &, example &)
 
void clean_example (vw &, example &, bool rewind)
 
void finish_example (vw &all, multi_ex &ec_seq)
 
void return_multiple_example (vw &all, v_array< example *> &examples)
 
const char * are_features_compatible (vw &vw1, vw &vw2)
 
void cmd_string_replace_value (std::stringstream *&ss, std::string flag_to_replace, std::string new_value)
 
char ** to_argv_escaped (std::string const &s, int &argc)
 
char ** to_argv (std::string const &s, int &argc)
 
char ** get_argv_from_string (std::string s, int &argc)
 
void free_args (int argc, char *argv[])
 
vwinitialize (options_i &options, io_buf *model, bool skipModelLoad, trace_message_t trace_listener, void *trace_context)
 
vwinitialize (std::string s, io_buf *model, bool skipModelLoad, trace_message_t trace_listener, void *trace_context)
 
vwinitialize_escaped (std::string const &s, io_buf *model, bool skipModelLoad, trace_message_t trace_listener, void *trace_context)
 
vwinitialize (int argc, char *argv[], io_buf *model, bool skipModelLoad, trace_message_t trace_listener, void *trace_context)
 
vwseed_vw_model (vw *vw_model, const std::string extra_args, trace_message_t trace_listener, void *trace_context)
 
void delete_dictionary_entry (substring ss, features *A)
 
void sync_stats (vw &all)
 
void finish (vw &all, bool delete_all)
 
void read_line (vw &all, example *ex, char *line)
 
void read_lines (vw *all, char *line, size_t, v_array< example *> &examples)
 
exampleget_unused_example (vw *all)
 
template<bool audit>
void read_line_json (vw &all, v_array< example *> &examples, char *line, example_factory_t example_factory, void *ex_factory_context)
 
void apply_pdrop (vw &all, float pdrop, v_array< example *> &examples)
 
template<bool audit>
void read_line_decision_service_json (vw &all, v_array< example *> &examples, char *line, size_t length, bool copy_line, example_factory_t example_factory, void *ex_factory_context, DecisionServiceInteraction *data)
 
void save_predictor (vw &all, std::string reg_name)
 
void save_predictor (vw &all, io_buf &buf)
 
void setup_examples (vw &all, v_array< example *> &examples)
 
void setup_example (vw &all, example *ae)
 
examplenew_unused_example (vw &all)
 
exampleread_example (vw &all, char *example_line)
 
exampleread_example (vw &all, std::string example_line)
 
void add_constant_feature (vw &vw, example *ec)
 
void add_label (example *ec, float label, float weight, float base)
 
exampleimport_example (vw &all, const std::string &label, primitive_feature_space *features, size_t len)
 
primitive_feature_spaceexport_example (vw &all, example *ec, size_t &len)
 
void releaseFeatureSpace (primitive_feature_space *features, size_t len)
 
void parse_example_label (vw &all, example &ec, std::string label)
 
void empty_example (vw &, example &ec)
 
exampleget_example (parser *p)
 
float get_topic_prediction (example *ec, size_t i)
 
float get_label (example *ec)
 
float get_importance (example *ec)
 
float get_initial (example *ec)
 
float get_prediction (example *ec)
 
float get_cost_sensitive_prediction (example *ec)
 
v_array< float > & get_cost_sensitive_prediction_confidence_scores (example *ec)
 
uint32_t * get_multilabel_predictions (example *ec, size_t &len)
 
float get_action_score (example *ec, size_t i)
 
size_t get_action_score_length (example *ec)
 
size_t get_tag_length (example *ec)
 
const char * get_tag (example *ec)
 
size_t get_feature_number (example *ec)
 
float get_confidence (example *ec)
 
void start_parser (vw &all)
 
void end_parser (vw &all)
 
bool is_ring_example (vw &all, example *ae)
 
const version_struct version (PACKAGE_VERSION)
 
const std::string git_commit (COMMIT_VERSION)
 
void clear_example_data (example &)
 
uint64_t hash_space (vw &all, const std::string &s)
 
uint64_t hash_space_static (const std::string &s, const std::string &hash)
 
uint64_t hash_feature (vw &all, const std::string &s, uint64_t u)
 
uint64_t hash_feature_static (const std::string &s, uint64_t u, const std::string &h, uint32_t num_bits)
 
uint64_t hash_feature_cstr (vw &all, char *fstr, uint64_t u)
 
float get_weight (vw &all, uint32_t index, uint32_t offset)
 
void set_weight (vw &all, uint32_t index, uint32_t offset, float value)
 
uint32_t num_weights (vw &all)
 
uint32_t get_stride (vw &all)
 
void init_features (primitive_feature_space &fs, size_t features_count)
 
void set_feature (primitive_feature_space &fs, size_t index, uint64_t feature_hash, float value)
 
void validate_version (vw &all)
 
void validate_min_max_label (vw &all)
 
void validate_default_bits (vw &all, uint32_t local_num_bits)
 
void validate_num_bits (vw &all)
 

Typedef Documentation

◆ example_factory_t

typedef example&(* VW::example_factory_t) (void *)

Definition at line 76 of file parse_primitives.h.

◆ v_array_pool

template<typename T >
using VW::v_array_pool = typedef VW::value_object_pool<v_array<T>, v_array_allocator<T>, v_array_deleter<T> >

Definition at line 21 of file v_array_pool.h.

Function Documentation

◆ add_constant_feature()

void VW::add_constant_feature ( vw vw,
example ec 
)

Definition at line 774 of file parser.cc.

References vw::audit, constant, constant_namespace, example_predict::feature_space, vw::hash_inv, example_predict::indices, example::num_features, v_array< T >::push_back(), and example::total_sum_feat_sq.

Referenced by ezexample::ezexample(), and setup_example().

775 {
777  ec->feature_space[constant_namespace].push_back(1, constant);
778  ec->total_sum_feat_sq++;
779  ec->num_features++;
780  if (vw.audit || vw.hash_inv)
781  ec->feature_space[constant_namespace].space_names.push_back(audit_strings_ptr(new audit_strings("", "Constant")));
782 }
v_array< namespace_index > indices
std::shared_ptr< audit_strings > audit_strings_ptr
Definition: feature_group.h:23
bool hash_inv
Definition: global_data.h:541
std::array< features, NUM_NAMESPACES > feature_space
void push_back(const T &new_ele)
Definition: v_array.h:107
size_t num_features
Definition: example.h:67
constexpr uint64_t constant
Definition: constant.h:11
float total_sum_feat_sq
Definition: example.h:71
bool audit
Definition: global_data.h:486
constexpr unsigned char constant_namespace
Definition: constant.h:22
std::pair< std::string, std::string > audit_strings
Definition: feature_group.h:22

◆ add_label()

void VW::add_label ( example ec,
float  label,
float  weight,
float  base 
)

Definition at line 784 of file parser.cc.

References label_data::initial, example::l, label_data::label, polylabel::simple, and example::weight.

Referenced by VW_AddLabel().

785 {
786  ec->l.simple.label = label;
787  ec->l.simple.initial = base;
788  ec->weight = weight;
789 }
float label
Definition: simple_label.h:14
label_data simple
Definition: example.h:28
float initial
Definition: simple_label.h:16
float weight
polylabel l
Definition: example.h:57
float weight
Definition: example.h:62

◆ alloc_examples()

example * VW::alloc_examples ( size_t  ,
size_t  count = 1 
)

Definition at line 204 of file example.cc.

References example_predict::ft_offset, and example::in_use.

Referenced by add_to_vali(), baseline_setup(), ExpReplay::expreplay_setup(), init_adf_data(), EntityRelationTask::initialize(), DepParserTask::initialize(), SequenceTask_DemoLDF::initialize(), and parse_dictionary_argument().

205 {
206  example* ec = calloc_or_throw<example>(count);
207  if (ec == nullptr)
208  return nullptr;
209  for (size_t i = 0; i < count; i++)
210  {
211  ec[i].in_use = true;
212  ec[i].ft_offset = 0;
213  // std::cerr << " alloc_example.indices.begin()=" << ec->indices.begin() << " end=" << ec->indices.end() << " //
214  // ld = " << ec->ld << "\t|| me = " << ec << std::endl;
215  }
216  return ec;
217 }
bool in_use
Definition: example.h:79

◆ apply_pdrop()

void VW::apply_pdrop ( vw all,
float  pdrop,
v_array< example *> &  examples 
)
inline

Definition at line 1374 of file parse_example_json.h.

References label_type::cb, label_type::ccb, and vw::label_type.

Referenced by read_line_decision_service_json().

1375 {
1377  {
1378  for (auto& e : examples)
1379  {
1380  e->l.cb.weight = 1 - pdrop;
1381  }
1382  }
1383  else if (all.label_type == label_type::label_type_t::ccb)
1384  {
1385  for (auto& e : examples)
1386  {
1387  e->l.conditional_contextual_bandit.weight = 1 - pdrop;
1388  }
1389  }
1390 }
label_type::label_type_t label_type
Definition: global_data.h:550

◆ are_features_compatible()

const char * VW::are_features_compatible ( vw vw1,
vw vw2 
)

Definition at line 501 of file parse_args.cc.

References vw::add_constant, vw::affix_features, vw::dictionary_path, parser::hasher, vw::ignore, vw::ignore_linear, vw::ignore_some, vw::ignore_some_linear, vw::interactions, vw::limit, vw::ngram, vw::num_bits, vw::p, vw::permutations, vw::redefine, vw::redefine_some, vw::skips, and vw::spelling_features.

502 {
503  if (vw1.p->hasher != vw2.p->hasher)
504  return "hasher";
505 
506  if (!std::equal(vw1.spelling_features.begin(), vw1.spelling_features.end(), vw2.spelling_features.begin()))
507  return "spelling_features";
508 
509  if (!std::equal(vw1.affix_features.begin(), vw1.affix_features.end(), vw2.affix_features.begin()))
510  return "affix_features";
511 
512  if (!std::equal(vw1.ngram.begin(), vw1.ngram.end(), vw2.ngram.begin()))
513  return "ngram";
514 
515  if (!std::equal(vw1.skips.begin(), vw1.skips.end(), vw2.skips.begin()))
516  return "skips";
517 
518  if (!std::equal(vw1.limit.begin(), vw1.limit.end(), vw2.limit.begin()))
519  return "limit";
520 
521  if (vw1.num_bits != vw2.num_bits)
522  return "num_bits";
523 
524  if (vw1.permutations != vw2.permutations)
525  return "permutations";
526 
527  if (vw1.interactions.size() != vw2.interactions.size())
528  return "interactions size";
529 
530  if (vw1.ignore_some != vw2.ignore_some)
531  return "ignore_some";
532 
533  if (vw1.ignore_some && !std::equal(vw1.ignore.begin(), vw1.ignore.end(), vw2.ignore.begin()))
534  return "ignore";
535 
536  if (vw1.ignore_some_linear != vw2.ignore_some_linear)
537  return "ignore_some_linear";
538 
539  if (vw1.ignore_some_linear &&
540  !std::equal(vw1.ignore_linear.begin(), vw1.ignore_linear.end(), vw2.ignore_linear.begin()))
541  return "ignore_linear";
542 
543  if (vw1.redefine_some != vw2.redefine_some)
544  return "redefine_some";
545 
546  if (vw1.redefine_some && !std::equal(vw1.redefine.begin(), vw1.redefine.end(), vw2.redefine.begin()))
547  return "redefine";
548 
549  if (vw1.add_constant != vw2.add_constant)
550  return "add_constant";
551 
552  if (vw1.dictionary_path.size() != vw2.dictionary_path.size())
553  return "dictionary_path size";
554 
555  if (!std::equal(vw1.dictionary_path.begin(), vw1.dictionary_path.end(), vw2.dictionary_path.begin()))
556  return "dictionary_path";
557 
558  for (auto i = std::begin(vw1.interactions), j = std::begin(vw2.interactions); i != std::end(vw1.interactions);
559  ++i, ++j)
560  if (*i != *j)
561  return "interaction mismatch";
562 
563  return nullptr;
564 }
std::array< uint32_t, NUM_NAMESPACES > skips
Definition: global_data.h:472
bool ignore_some_linear
Definition: global_data.h:464
std::array< bool, NUM_NAMESPACES > spelling_features
Definition: global_data.h:477
std::array< uint32_t, NUM_NAMESPACES > ngram
Definition: global_data.h:471
bool add_constant
Definition: global_data.h:496
bool redefine_some
Definition: global_data.h:467
hash_func_t hasher
Definition: parser.h:73
std::array< uint64_t, NUM_NAMESPACES > affix_features
Definition: global_data.h:476
uint32_t num_bits
Definition: global_data.h:398
std::array< bool, NUM_NAMESPACES > ignore
Definition: global_data.h:463
parser * p
Definition: global_data.h:377
std::array< uint32_t, NUM_NAMESPACES > limit
Definition: global_data.h:474
bool ignore_some
Definition: global_data.h:462
std::array< bool, NUM_NAMESPACES > ignore_linear
Definition: global_data.h:465
std::array< unsigned char, NUM_NAMESPACES > redefine
Definition: global_data.h:468
std::vector< std::string > dictionary_path
Definition: global_data.h:478
std::vector< std::string > interactions
Definition: global_data.h:457
bool permutations
Definition: global_data.h:454

◆ clean_example()

void VW::clean_example ( vw all,
example ec,
bool  rewind 
)

Definition at line 867 of file parser.cc.

References parser::begin_parsed_examples, empty_example(), parser::example_pool, example::in_use, vw::p, and VW::object_pool< T, TInitializer, TCleanup >::return_object().

Referenced by dealloc_example(), finish_example(), and return_multiple_example().

868 {
869  if (rewind)
870  {
871  assert(all.p->begin_parsed_examples > 0);
872  all.p->begin_parsed_examples--;
873  }
874 
875  empty_example(all, ec);
876  assert(ec.in_use);
877  ec.in_use = false;
878  all.p->example_pool.return_object(&ec);
879 }
VW::object_pool< example, example_initializer > example_pool
Definition: parser.h:66
uint64_t begin_parsed_examples
Definition: parser.h:81
parser * p
Definition: global_data.h:377
void empty_example(vw &, example &ec)
Definition: parser.cc:857
bool in_use
Definition: example.h:79
void return_object(T *obj)
Definition: object_pool.h:174

◆ clear_example_data()

void VW::clear_example_data ( example )

◆ cmd_string_replace_value()

void VW::cmd_string_replace_value ( std::stringstream *&  ss,
std::string  flag_to_replace,
std::string  new_value 
)

Definition at line 1570 of file parse_args.cc.

1571 {
1572  flag_to_replace.append(
1573  " "); // add a space to make sure we obtain the right flag in case 2 flags start with the same set of characters
1574  std::string cmd = ss->str();
1575  size_t pos = cmd.find(flag_to_replace);
1576  if (pos == std::string::npos)
1577  // flag currently not present in command std::string, so just append it to command std::string
1578  *ss << " " << flag_to_replace << new_value;
1579  else
1580  {
1581  // flag is present, need to replace old value with new value
1582 
1583  // compute position after flag_to_replace
1584  pos += flag_to_replace.size();
1585 
1586  // now pos is position where value starts
1587  // find position of next space
1588  size_t pos_after_value = cmd.find(" ", pos);
1589  if (pos_after_value == std::string::npos)
1590  {
1591  // we reach the end of the std::string, so replace the all characters after pos by new_value
1592  cmd.replace(pos, cmd.size() - pos, new_value);
1593  }
1594  else
1595  {
1596  // replace characters between pos and pos_after_value by new_value
1597  cmd.replace(pos, pos_after_value - pos, new_value);
1598  }
1599 
1600  ss->str(cmd);
1601  }
1602 }

◆ convert()

uint32_t VW::convert ( size_t  number)

Definition at line 211 of file cache.cc.

References THROW.

Referenced by CCB::cache_label(), and utf16_to_utf8().

212 {
213  if (number > UINT32_MAX)
214  {
215  THROW("size_t value is out of bounds of uint32_t.")
216  }
217  return static_cast<uint32_t>(number);
218 }
#define THROW(args)
Definition: vw_exception.h:181

◆ copy_example_data() [1/2]

void VW::copy_example_data ( bool  audit,
example dst,
example src 
)

Definition at line 72 of file example.cc.

References c, copy_array(), copy_example_metadata(), example_predict::feature_space, example_predict::indices, example_predict::interactions, example::num_features, and example::total_sum_feat_sq.

Referenced by add_to_vali(), memory_tree_ns::copy_example_data(), copy_example_data(), copy_example_to_adf(), EntityRelationTask::predict_entity(), ExpReplay::predict_or_learn(), EntityRelationTask::predict_relation(), SequenceTask_DemoLDF::run(), Search::search_predict(), Search::predictor::set_input_at(), and ezexample::train().

73 {
74  // std::cerr << "copy_example_data dst = " << dst << std::endl;
75  copy_example_metadata(audit, dst, src);
76 
77  // copy feature data
78  copy_array(dst->indices, src->indices);
79  for (namespace_index c : src->indices) dst->feature_space[c].deep_copy_from(src->feature_space[c]);
80  // copy_array(dst->atomics[i], src->atomics[i]);
81  dst->num_features = src->num_features;
83  dst->interactions = src->interactions;
84 }
v_array< namespace_index > indices
void copy_example_metadata(bool, example *dst, example *src)
Definition: example.cc:48
void copy_array(v_array< T > &dst, const v_array< T > &src)
Definition: v_array.h:185
std::vector< std::string > * interactions
std::array< features, NUM_NAMESPACES > feature_space
size_t num_features
Definition: example.h:67
unsigned char namespace_index
float total_sum_feat_sq
Definition: example.h:71
constexpr uint64_t c
Definition: rand48.cc:12

◆ copy_example_data() [2/2]

void VW::copy_example_data ( bool  audit,
example dst,
example src,
size_t  label_size,
void(*)(void *, void *)  copy_label 
)

Definition at line 86 of file example.cc.

References copy_example_data(), copy_example_label(), and CB::copy_label().

87 {
88  copy_example_data(audit, dst, src);
89  copy_example_label(dst, src, label_size, copy_label);
90 }
void copy_label(void *dst, void *src)
Definition: cb.cc:104
void copy_example_data(bool audit, example *dst, example *src, size_t label_size, void(*copy_label)(void *, void *))
Definition: example.cc:86
void copy_example_label(example *dst, example *src, size_t, void(*copy_label)(void *, void *))
Definition: example.cc:40

◆ copy_example_label()

void VW::copy_example_label ( example dst,
example src,
size_t  ,
void(*)(void *, void *)  copy_label 
)

Definition at line 40 of file example.cc.

References CB::copy_label(), and example::l.

Referenced by copy_example_data().

41 {
42  if (copy_label)
43  copy_label(&dst->l, &src->l); // TODO: we really need to delete_label on dst :(
44  else
45  dst->l = src->l;
46 }
void copy_label(void *dst, void *src)
Definition: cb.cc:104
polylabel l
Definition: example.h:57

◆ copy_example_metadata()

void VW::copy_example_metadata ( bool  ,
example dst,
example src 
)

Definition at line 48 of file example.cc.

References example::confidence, copy_array(), features::deep_copy_from(), example::end_pass, example::example_counter, example_predict::ft_offset, example::in_use, example::loss, example::partial_prediction, example::passthrough, example::sorted, example::tag, example::test_only, and example::weight.

Referenced by copy_example_data(), predict_or_learn(), and sensitivity().

49 {
50  copy_array(dst->tag, src->tag);
51  dst->example_counter = src->example_counter;
52 
53  dst->ft_offset = src->ft_offset;
54 
56  if (src->passthrough == nullptr)
57  dst->passthrough = nullptr;
58  else
59  {
60  dst->passthrough = new features;
62  }
63  dst->loss = src->loss;
64  dst->weight = src->weight;
65  dst->confidence = src->confidence;
66  dst->test_only = src->test_only;
67  dst->end_pass = src->end_pass;
68  dst->sorted = src->sorted;
69  dst->in_use = src->in_use;
70 }
v_array< char > tag
Definition: example.h:63
size_t example_counter
Definition: example.h:64
void deep_copy_from(const features &src)
void copy_array(v_array< T > &dst, const v_array< T > &src)
Definition: v_array.h:185
bool sorted
Definition: example.h:78
the core definition of a set of features.
float confidence
Definition: example.h:72
float partial_prediction
Definition: example.h:68
float loss
Definition: example.h:70
bool in_use
Definition: example.h:79
features * passthrough
Definition: example.h:74
float weight
Definition: example.h:62
bool end_pass
Definition: example.h:77
bool test_only
Definition: example.h:76

◆ dealloc_example()

void VW::dealloc_example ( void(*)(void *)  delete_label,
example ec,
void(*)(void *)  delete_prediction 
)

Definition at line 219 of file example.cc.

References clean_example(), CB::delete_label(), v_array< T >::delete_v(), features::delete_v(), example_predict::feature_space, finish_example(), example_predict::indices, example::l, example::passthrough, example::pred, and example::tag.

Referenced by memory_tree_ns::diag_kronecker_product_test(), EntityRelationTask::finish(), DepParserTask::finish(), SequenceTask_DemoLDF::finish(), Search::predictor::free_ec(), memory_tree_ns::free_example(), free_parser(), parse_dictionary_argument(), baseline::~baseline(), cbify::~cbify(), ExpReplay::expreplay< lp >::~expreplay(), nn::~nn(), Search::search::~search(), and warm_cb::~warm_cb().

220 {
221  if (delete_label)
222  delete_label(&ec.l);
223 
224  if (delete_prediction)
225  delete_prediction(&ec.pred);
226 
227  ec.tag.delete_v();
228 
229  if (ec.passthrough)
230  {
231  ec.passthrough->delete_v();
232  delete ec.passthrough;
233  }
234 
235  for (auto& j : ec.feature_space) j.delete_v();
236 
237  ec.indices.delete_v();
238 }
v_array< char > tag
Definition: example.h:63
v_array< namespace_index > indices
void delete_v()
void delete_label(void *v)
Definition: cb.cc:98
std::array< features, NUM_NAMESPACES > feature_space
polylabel l
Definition: example.h:57
features * passthrough
Definition: example.h:74
polyprediction pred
Definition: example.h:60
void delete_v()
Definition: v_array.h:98

◆ delete_dictionary_entry()

void VW::delete_dictionary_entry ( substring  ss,
features A 
)

Definition at line 1797 of file parse_args.cc.

References substring::begin, and features::delete_v().

Referenced by finish().

1798 {
1799  free(ss.begin);
1800  A->delete_v();
1801  delete A;
1802 }
char * begin
Definition: hashstring.h:9
void delete_v()

◆ empty_example()

void VW::empty_example ( vw ,
example ec 
)

Definition at line 857 of file parser.cc.

Referenced by clean_example(), ezexample::finish(), and ezexample::setup_for_predict().

858 {
859  for (features& fs : ec) fs.clear();
860 
861  ec.indices.clear();
862  ec.tag.clear();
863  ec.sorted = false;
864  ec.end_pass = false;
865 }
the core definition of a set of features.

◆ end_parser()

void VW::end_parser ( vw all)

Definition at line 1007 of file parser.cc.

References vw::parse_thread.

Referenced by main(), VW_EndParser(), and VW_Finish_Passes().

1007 { all.parse_thread.join(); }
std::thread parse_thread
Definition: global_data.h:378

◆ export_example()

primitive_feature_space * VW::export_example ( vw all,
example ec,
size_t &  len 
)

Definition at line 812 of file parser.cc.

References f, example_predict::feature_space, VW::primitive_feature_space::fs, example_predict::indices, VW::primitive_feature_space::len, VW::primitive_feature_space::name, v_array< T >::size(), stride_shift(), parameters::stride_shift(), feature::weight_index, and vw::weights.

Referenced by VW_ExportExample().

813 {
814  len = ec->indices.size();
815  primitive_feature_space* fs_ptr = new primitive_feature_space[len];
816 
817  int fs_count = 0;
818 
819  for (size_t idx = 0; idx < len; ++idx)
820  {
821  namespace_index i = ec->indices[idx];
822  fs_ptr[fs_count].name = i;
823  fs_ptr[fs_count].len = ec->feature_space[i].size();
824  fs_ptr[fs_count].fs = new feature[fs_ptr[fs_count].len];
825 
826  uint32_t stride_shift = all.weights.stride_shift();
827  int f_count = 0;
828  for (features::iterator& f : ec->feature_space[i])
829  {
830  feature t = {f.value(), f.index()};
832  fs_ptr[fs_count].fs[f_count] = t;
833  f_count++;
834  }
835  fs_count++;
836  }
837  return fs_ptr;
838 }
v_array< namespace_index > indices
parameters weights
Definition: global_data.h:537
uint64_t stride_shift(const stagewise_poly &poly, uint64_t idx)
uint64_t weight_index
Definition: feature_group.h:28
size_t size() const
Definition: v_array.h:68
std::array< features, NUM_NAMESPACES > feature_space
unsigned char namespace_index
iterator over values and indicies
uint32_t stride_shift()
float f
Definition: cache.cc:40

◆ finish()

void VW::finish ( vw all,
bool  delete_all 
)

Definition at line 1823 of file parse_args.cc.

References vw::all_reduce, v_array< T >::clear(), io_buf::close_file_or_socket(), vw::current_pass, delete_dictionary_entry(), v_array< T >::delete_v(), shared_data::example_number, vw::final_prediction_sink, vw::final_regressor_name, finalize_regressor(), finalize_source(), LEARNER::learner< T, E >::finish(), free_it(), free_parser(), get_best_constant(), shared_data::holdout_best_loss, shared_data::holdout_multiclass_log_loss, vw::holdout_set_off, vw::l, shared_data::ldict, vw::loaded_dictionaries, vw::loss, shared_data::multiclass_log_loss, vw::options, vw::p, parser::parse_name, shared_data::queries, vw::quiet, shared_data::report_multiclass_log_loss, vw::sd, parameters::seeded(), vw::should_delete_options, v_array< T >::size(), shared_data::sum_loss, shared_data::total_features, vw::trace_message, VW::config::options_i::was_supplied(), shared_data::weighted_examples(), shared_data::weighted_labeled_examples, shared_data::weighted_labels, vw::weights, and namedlabels::~namedlabels().

Referenced by audit_regressor_setup(), enable_sources(), initialize(), main(), parse_args(), and VW_Finish().

1824 {
1825  // also update VowpalWabbit::PerformanceStatistics::get() (vowpalwabbit.cpp)
1826  if (!all.quiet && !all.options->was_supplied("audit_regressor"))
1827  {
1828  all.trace_message.precision(6);
1829  all.trace_message << std::fixed;
1830  all.trace_message << endl << "finished run";
1831  if (all.current_pass == 0 || all.current_pass == 1)
1832  all.trace_message << endl << "number of examples = " << all.sd->example_number;
1833  else
1834  {
1835  all.trace_message << endl << "number of examples per pass = " << all.sd->example_number / all.current_pass;
1836  all.trace_message << endl << "passes used = " << all.current_pass;
1837  }
1838  all.trace_message << endl << "weighted example sum = " << all.sd->weighted_examples();
1839  all.trace_message << endl << "weighted label sum = " << all.sd->weighted_labels;
1840  all.trace_message << endl << "average loss = ";
1841  if (all.holdout_set_off)
1842  if (all.sd->weighted_labeled_examples > 0)
1844  else
1845  all.trace_message << "n.a.";
1846  else if ((all.sd->holdout_best_loss == FLT_MAX) || (all.sd->holdout_best_loss == FLT_MAX * 0.5))
1847  all.trace_message << "undefined (no holdout)";
1848  else
1849  all.trace_message << all.sd->holdout_best_loss << " h";
1850  if (all.sd->report_multiclass_log_loss)
1851  {
1852  if (all.holdout_set_off)
1853  all.trace_message << endl
1854  << "average multiclass log loss = "
1856  else
1857  all.trace_message << endl
1858  << "average multiclass log loss = "
1860  }
1861 
1862  float best_constant;
1863  float best_constant_loss;
1864  if (get_best_constant(all, best_constant, best_constant_loss))
1865  {
1866  all.trace_message << endl << "best constant = " << best_constant;
1867  if (best_constant_loss != FLT_MIN)
1868  all.trace_message << endl << "best constant's loss = " << best_constant_loss;
1869  }
1870 
1871  all.trace_message << endl << "total feature number = " << all.sd->total_features;
1872  if (all.sd->queries > 0)
1873  all.trace_message << endl << "total queries = " << all.sd->queries;
1874  all.trace_message << endl;
1875  }
1876 
1877  // implement finally.
1878  // finalize_regressor can throw if it can't write the file.
1879  // we still want to free up all the memory.
1880  vw_exception finalize_regressor_exception(__FILE__, __LINE__, "empty");
1881  bool finalize_regressor_exception_thrown = false;
1882  try
1883  {
1885  }
1886  catch (vw_exception& e)
1887  {
1888  finalize_regressor_exception = e;
1889  finalize_regressor_exception_thrown = true;
1890  }
1891 
1892  if (all.l != nullptr)
1893  {
1894  all.l->finish();
1895  free_it(all.l);
1896  }
1897 
1898  // Check if options object lifetime is managed internally.
1899  if (all.should_delete_options)
1900  delete all.options;
1901 
1902  // TODO: migrate all finalization into parser destructor
1903  if (all.p != nullptr)
1904  {
1905  free_parser(all);
1906  finalize_source(all.p);
1907  all.p->parse_name.clear();
1908  all.p->parse_name.delete_v();
1909  delete all.p;
1910  }
1911 
1912  bool seeded;
1913  if (all.weights.seeded() > 0)
1914  seeded = true;
1915  else
1916  seeded = false;
1917  if (!seeded)
1918  {
1919  if (all.sd->ldict)
1920  {
1921  all.sd->ldict->~namedlabels();
1922  free(all.sd->ldict);
1923  }
1924  free(all.sd);
1925  }
1926  for (size_t i = 0; i < all.final_prediction_sink.size(); i++)
1927  if (all.final_prediction_sink[i] != 1)
1930  for (size_t i = 0; i < all.loaded_dictionaries.size(); i++)
1931  {
1932  // Warning C6001 is triggered by the following:
1933  // (a) dictionary_info.name is allocated using 'calloc_or_throw<char>(strlen(s)+1)' and (b) freed using
1934  // 'free(all.loaded_dictionaries[i].name)'
1935  //
1936  // When the call to allocation is replaced by (a) 'new char[strlen(s)+1]' and deallocated using (b) 'delete []', the
1937  // warning goes away. Disable SDL warning.
1938  // #pragma warning(disable:6001)
1939  free_it(all.loaded_dictionaries[i].name);
1940  //#pragma warning(default:6001)
1941 
1942  all.loaded_dictionaries[i].dict->iter(delete_dictionary_entry);
1943  all.loaded_dictionaries[i].dict->delete_v();
1944  free_it(all.loaded_dictionaries[i].dict);
1945  }
1946  delete all.loss;
1947 
1948  delete all.all_reduce;
1949 
1950  if (delete_all)
1951  delete &all;
1952 
1953  if (finalize_regressor_exception_thrown)
1954  throw finalize_regressor_exception;
1955 }
bool report_multiclass_log_loss
Definition: global_data.h:166
double sum_loss
Definition: global_data.h:145
void delete_dictionary_entry(substring ss, features *A)
Definition: parse_args.cc:1797
parameters weights
Definition: global_data.h:537
loss_function * loss
Definition: global_data.h:523
void finalize_source(parser *p)
Definition: parser.cc:206
VW::config::options_i * options
Definition: global_data.h:428
void finish()
Definition: learner.h:266
v_array< int > final_prediction_sink
Definition: global_data.h:518
namedlabels * ldict
Definition: global_data.h:153
double holdout_multiclass_log_loss
Definition: global_data.h:168
std::vector< dictionary_info > loaded_dictionaries
Definition: global_data.h:483
double holdout_best_loss
Definition: global_data.h:161
bool quiet
Definition: global_data.h:487
void finalize_regressor(vw &all, std::string reg_name)
bool holdout_set_off
Definition: global_data.h:499
v_array< substring > parse_name
Definition: parser.h:100
static void close_file_or_socket(int f)
Definition: io_buf.cc:152
size_t size() const
Definition: v_array.h:68
void free_it(void *ptr)
Definition: memory.h:94
parser * p
Definition: global_data.h:377
double multiclass_log_loss
Definition: global_data.h:167
AllReduce * all_reduce
Definition: global_data.h:381
bool get_best_constant(vw &all, float &best_constant, float &best_constant_loss)
Definition: best_constant.cc:3
shared_data * sd
Definition: global_data.h:375
void clear()
Definition: v_array.h:88
vw_ostream trace_message
Definition: global_data.h:424
virtual bool was_supplied(const std::string &key)=0
double weighted_labels
Definition: global_data.h:144
uint64_t current_pass
Definition: global_data.h:396
uint64_t example_number
Definition: global_data.h:137
bool should_delete_options
Definition: global_data.h:427
LEARNER::base_learner * l
Definition: global_data.h:383
void free_parser(vw &all)
Definition: parser.cc:976
double weighted_labeled_examples
Definition: global_data.h:141
uint64_t seeded()
void delete_v()
Definition: v_array.h:98
std::string final_regressor_name
Definition: global_data.h:535
double weighted_examples()
Definition: global_data.h:188
size_t queries
Definition: global_data.h:135
uint64_t total_features
Definition: global_data.h:138

◆ finish_example() [1/2]

void VW::finish_example ( vw ,
example  
)

Definition at line 881 of file parser.cc.

References clean_example(), is_ring_example(), parser::output_done, parser::output_lock, and vw::p.

Referenced by audit_regressor_setup(), LEARNER::multi_example_handler< context_type >::complete_multi_ex(), dealloc_example(), LEARNER::drain_examples(), LEARNER::end_pass(), CB_ALGS::eval_finish_example(), ezexample::finish(), CB_ALGS::finish_example(), MULTICLASS::finish_example(), finish_example(), MWT::finish_example(), finish_example(), CB_EXPLORE::finish_example(), COST_SENSITIVE::finish_example(), finish_example_scores(), VW::cb_explore_adf::cb_explore_adf_base< ExploreType >::finish_multiline_example(), EXPLORE_EVAL::finish_multiline_example(), finish_multiline_example(), CB_ADF::finish_multiline_example(), CCB::finish_multiline_example(), CSOAA::finish_multiline_example(), Search::finish_multiline_example(), lda_setup(), learn(), multilabel_oaa_setup(), return_active_example(), return_confidence_example(), return_example(), no_label::return_no_label_example(), return_simple_example(), LEARNER::save(), sender_setup(), topk_setup(), VW_FinishExample(), and ezexample::~ezexample().

882 {
883  // only return examples to the pool that are from the pool and not externally allocated
884  if (!is_ring_example(all, &ec))
885  return;
886 
887  clean_example(all, ec, false);
888 
889  {
890  std::lock_guard<std::mutex> lock(all.p->output_lock);
891  all.p->output_done.notify_one();
892  }
893 }
void clean_example(vw &, example &, bool rewind)
Definition: parser.cc:867
bool is_ring_example(vw &all, example *ae)
Definition: parser.cc:1009
std::mutex output_lock
Definition: parser.h:87
parser * p
Definition: global_data.h:377
std::condition_variable output_done
Definition: parser.h:88

◆ finish_example() [2/2]

void VW::finish_example ( vw all,
multi_ex ec_seq 
)

Definition at line 243 of file example.cc.

References finish_example().

244 {
245  if (!ec_seq.empty())
246  for (example* ecc : ec_seq)
247  if (ecc->in_use)
248  VW::finish_example(all, *ecc);
249 }
void finish_example(vw &, example &)
Definition: parser.cc:881

◆ free_args()

void VW::free_args ( int  argc,
char *  argv[] 
)

Definition at line 1648 of file parse_args.cc.

Referenced by initialize(), and initialize_escaped().

1649 {
1650  for (int i = 0; i < argc; i++) free(argv[i]);
1651  free(argv);
1652 }

◆ get_action_score()

float VW::get_action_score ( example ec,
size_t  i 
)

Definition at line 932 of file parser.cc.

References polyprediction::a_s, example::pred, and v_array< T >::size().

Referenced by VW_GetActionScore().

933 {
934  ACTION_SCORE::action_scores scores = ec->pred.a_s;
935 
936  if (i < scores.size())
937  {
938  return scores[i].score;
939  }
940  else
941  {
942  return 0.0;
943  }
944 }
ACTION_SCORE::action_scores a_s
Definition: example.h:47
size_t size() const
Definition: v_array.h:68
polyprediction pred
Definition: example.h:60

◆ get_action_score_length()

size_t VW::get_action_score_length ( example ec)

Definition at line 946 of file parser.cc.

References polyprediction::a_s, example::pred, and v_array< T >::size().

Referenced by VW_GetActionScoreLength().

946 { return ec->pred.a_s.size(); }
ACTION_SCORE::action_scores a_s
Definition: example.h:47
size_t size() const
Definition: v_array.h:68
polyprediction pred
Definition: example.h:60

◆ get_argv_from_string()

char ** VW::get_argv_from_string ( std::string  s,
int &  argc 
)

Definition at line 1646 of file parse_args.cc.

References to_argv().

Referenced by main().

1646 { return to_argv(s, argc); }
char ** to_argv(std::string const &s, int &argc)
Definition: parse_args.cc:1623

◆ get_confidence()

float VW::get_confidence ( example ec)

Definition at line 954 of file parser.cc.

References example::confidence.

Referenced by VW_GetConfidence().

954 { return ec->confidence; }
float confidence
Definition: example.h:72

◆ get_cost_sensitive_prediction()

float VW::get_cost_sensitive_prediction ( example ec)

Definition at line 921 of file parser.cc.

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

Referenced by VW_GetCostSensitivePrediction(), and VW_PredictCostSensitive().

921 { return (float)ec->pred.multiclass; }
uint32_t multiclass
Definition: example.h:49
polyprediction pred
Definition: example.h:60

◆ get_cost_sensitive_prediction_confidence_scores()

v_array< float > & VW::get_cost_sensitive_prediction_confidence_scores ( example ec)

Definition at line 923 of file parser.cc.

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

923 { return ec->pred.scalars; }
polyprediction pred
Definition: example.h:60
v_array< float > scalars
Definition: example.h:46

◆ get_example()

example * VW::get_example ( parser p)

Definition at line 909 of file parser.cc.

References VW::ptr_queue< T >::pop(), and parser::ready_parsed_examples.

Referenced by LEARNER::drain_examples(), LEARNER::ready_examples_queue::pop(), and VW_GetExample().

909 { return p->ready_parsed_examples.pop(); }
VW::ptr_queue< example > ready_parsed_examples
Definition: parser.h:67
T * pop()
Definition: queue.h:27

◆ get_feature_number()

size_t VW::get_feature_number ( example ec)

Definition at line 952 of file parser.cc.

References example::num_features.

Referenced by VW_GetFeatureNumber().

952 { return ec->num_features; }
size_t num_features
Definition: example.h:67

◆ get_features()

feature * VW::get_features ( vw all,
example ec,
size_t &  feature_map_len 
)

Definition at line 125 of file example.cc.

References v_array< T >::begin(), features_and_source::feature_map, features_and_source::mask, parameters::mask(), v_array< T >::size(), features_and_source::stride_shift, parameters::stride_shift(), and vw::weights.

Referenced by VW_GetFeatures().

126 {
128  fs.stride_shift = all.weights.stride_shift();
129  fs.mask = (uint64_t)all.weights.mask() >> all.weights.stride_shift();
130  fs.feature_map = v_init<feature>();
131  GD::foreach_feature<features_and_source, uint64_t, vec_store>(all, *ec, fs);
132 
133  feature_map_len = fs.feature_map.size();
134  return fs.feature_map.begin();
135 }
parameters weights
Definition: global_data.h:537
v_array< feature > feature_map
Definition: example.cc:113
T *& begin()
Definition: v_array.h:42
size_t size() const
Definition: v_array.h:68
uint32_t stride_shift
Definition: example.cc:114
uint32_t stride_shift()
uint64_t mask()

◆ get_importance()

float VW::get_importance ( example ec)

Definition at line 915 of file parser.cc.

References example::weight.

Referenced by VW_GetImportance().

915 { return ec->weight; }
float weight
Definition: example.h:62

◆ get_initial()

float VW::get_initial ( example ec)

Definition at line 917 of file parser.cc.

References label_data::initial, example::l, and polylabel::simple.

Referenced by VW_GetInitial().

917 { return ec->l.simple.initial; }
label_data simple
Definition: example.h:28
float initial
Definition: simple_label.h:16
polylabel l
Definition: example.h:57

◆ get_label()

float VW::get_label ( example ec)

Definition at line 913 of file parser.cc.

References example::l, label_data::label, and polylabel::simple.

Referenced by VW_GetLabel().

913 { return ec->l.simple.label; }
float label
Definition: simple_label.h:14
label_data simple
Definition: example.h:28
polylabel l
Definition: example.h:57

◆ get_multilabel_predictions()

uint32_t * VW::get_multilabel_predictions ( example ec,
size_t &  len 
)

Definition at line 925 of file parser.cc.

References v_array< T >::begin(), MULTILABEL::labels::label_v, polyprediction::multilabels, example::pred, and v_array< T >::size().

Referenced by VW_GetMultilabelPredictions().

926 {
927  MULTILABEL::labels labels = ec->pred.multilabels;
928  len = labels.label_v.size();
929  return labels.label_v.begin();
930 }
T *& begin()
Definition: v_array.h:42
size_t size() const
Definition: v_array.h:68
MULTILABEL::labels multilabels
Definition: example.h:50
v_array< uint32_t > label_v
Definition: multilabel.h:16
polyprediction pred
Definition: example.h:60

◆ get_prediction()

float VW::get_prediction ( example ec)

Definition at line 919 of file parser.cc.

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

Referenced by receive_result(), VW_GetPrediction(), VW_Learn(), and VW_Predict().

919 { return ec->pred.scalar; }
float scalar
Definition: example.h:45
polyprediction pred
Definition: example.h:60

◆ get_stride()

uint32_t VW::get_stride ( vw all)
inline

Definition at line 189 of file vw.h.

References parameters::stride(), and vw::weights.

Referenced by VW_Get_Stride().

189 { return all.weights.stride(); }
parameters weights
Definition: global_data.h:537
uint32_t stride()

◆ get_tag()

const char * VW::get_tag ( example ec)

Definition at line 950 of file parser.cc.

References v_array< T >::begin(), and example::tag.

Referenced by VW_GetTag().

950 { return ec->tag.begin(); }
v_array< char > tag
Definition: example.h:63
T *& begin()
Definition: v_array.h:42

◆ get_tag_length()

size_t VW::get_tag_length ( example ec)

Definition at line 948 of file parser.cc.

References v_array< T >::size(), and example::tag.

Referenced by VW_GetTagLength().

948 { return ec->tag.size(); }
v_array< char > tag
Definition: example.h:63
size_t size() const
Definition: v_array.h:68

◆ get_topic_prediction()

float VW::get_topic_prediction ( example ec,
size_t  i 
)

Definition at line 911 of file parser.cc.

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

Referenced by VW_GetTopicPrediction().

911 { return ec->pred.scalars[i]; }
polyprediction pred
Definition: example.h:60
v_array< float > scalars
Definition: example.h:46

◆ get_unused_example()

example & VW::get_unused_example ( vw all)

Definition at line 664 of file parser.cc.

References parser::begin_parsed_examples, parser::example_pool, VW::object_pool< T, TInitializer, TCleanup >::get_object(), example::in_use, and vw::p.

Referenced by import_example(), line_to_examples_json(), new_unused_example(), parse_dispatch(), parse_line_json(), prepare_for_learner(), read_example(), and read_lines().

665 {
666  parser* p = all->p;
667  auto ex = p->example_pool.get_object();
668  ex->in_use = true;
670  return *ex;
671 }
VW::object_pool< example, example_initializer > example_pool
Definition: parser.h:66
uint64_t begin_parsed_examples
Definition: parser.h:81
parser * p
Definition: global_data.h:377
bool in_use
Definition: example.h:79
Definition: parser.h:38

◆ get_weight()

float VW::get_weight ( vw all,
uint32_t  index,
uint32_t  offset 
)
inline

Definition at line 177 of file vw.h.

References parameters::stride_shift(), and vw::weights.

Referenced by SVRG::learn(), and VW_Get_Weight().

178 {
179  return (&all.weights[((uint64_t)index) << all.weights.stride_shift()])[offset];
180 }
parameters weights
Definition: global_data.h:537
uint32_t stride_shift()

◆ git_commit()

const std::string VW::git_commit ( COMMIT_VERSION  )

Referenced by parse_diagnostics().

◆ hash_feature()

uint64_t VW::hash_feature ( vw all,
const std::string &  s,
uint64_t  u 
)
inline

Definition at line 153 of file vw.h.

References substring::begin, substring::end, parser::hasher, vw::p, and vw::parse_mask.

Referenced by Namespace< audit >::AddFeature(), DefaultState< audit >::Float(), ezexample::hash(), CCB::inject_slot_id(), and VW_HashFeatureA().

154 {
155  substring ss;
156  ss.begin = (char*)s.c_str();
157  ss.end = ss.begin + s.length();
158  return all.p->hasher(ss, u) & all.parse_mask;
159 }
char * end
Definition: hashstring.h:10
char * begin
Definition: hashstring.h:9
hash_func_t hasher
Definition: parser.h:73
parser * p
Definition: global_data.h:377
uint64_t parse_mask
Definition: global_data.h:453

◆ hash_feature_cstr()

uint64_t VW::hash_feature_cstr ( vw all,
char *  fstr,
uint64_t  u 
)
inline

Definition at line 169 of file vw.h.

References substring::begin, substring::end, parser::hasher, vw::p, and vw::parse_mask.

Referenced by ezexample::hash().

170 {
171  substring ss;
172  ss.begin = fstr;
173  ss.end = ss.begin + strlen(fstr);
174  return all.p->hasher(ss, u) & all.parse_mask;
175 }
char * end
Definition: hashstring.h:10
char * begin
Definition: hashstring.h:9
hash_func_t hasher
Definition: parser.h:73
parser * p
Definition: global_data.h:377
uint64_t parse_mask
Definition: global_data.h:453

◆ hash_feature_static()

uint64_t VW::hash_feature_static ( const std::string &  s,
uint64_t  u,
const std::string &  h,
uint32_t  num_bits 
)
inline

Definition at line 160 of file vw.h.

References substring::begin, substring::end, and getHasher().

Referenced by VW_HashFeatureStaticA().

161 {
162  substring ss;
163  ss.begin = (char*)s.c_str();
164  ss.end = ss.begin + s.length();
165  size_t parse_mark = (1 << num_bits) - 1;
166  return getHasher(h)(ss, u) & parse_mark;
167 }
char * end
Definition: hashstring.h:10
char * begin
Definition: hashstring.h:9
hash_func_t getHasher(const std::string &s)

◆ hash_space()

uint64_t VW::hash_space ( vw all,
const std::string &  s 
)
inline

Definition at line 138 of file vw.h.

References substring::begin, substring::end, vw::hash_seed, parser::hasher, and vw::p.

Referenced by ezexample::addns(), CCB::ccb_explore_adf_setup(), ezexample::ezexample(), ezexample::hash(), Context< audit >::PushNamespace(), and VW_HashSpaceA().

139 {
140  substring ss;
141  ss.begin = (char*)s.c_str();
142  ss.end = ss.begin + s.length();
143  return all.p->hasher(ss, all.hash_seed);
144 }
char * end
Definition: hashstring.h:10
char * begin
Definition: hashstring.h:9
hash_func_t hasher
Definition: parser.h:73
parser * p
Definition: global_data.h:377
uint32_t hash_seed
Definition: global_data.h:401

◆ hash_space_static()

uint64_t VW::hash_space_static ( const std::string &  s,
const std::string &  hash 
)
inline

Definition at line 145 of file vw.h.

References substring::begin, substring::end, and getHasher().

Referenced by VW_HashSpaceStaticA().

146 {
147  substring ss;
148  ss.begin = (char*)s.c_str();
149  ss.end = ss.begin + s.length();
150  return getHasher(hash)(ss, 0);
151 }
char * end
Definition: hashstring.h:10
char * begin
Definition: hashstring.h:9
hash_func_t getHasher(const std::string &s)

◆ import_example()

example * VW::import_example ( vw all,
const std::string &  label,
primitive_feature_space features,
size_t  len 
)

Definition at line 791 of file parser.cc.

References label_parser::default_label, parser::end_parsed_examples, example_predict::feature_space, VW::primitive_feature_space::fs, get_unused_example(), example_predict::indices, example::l, VW::primitive_feature_space::len, parser::lp, VW::primitive_feature_space::name, vw::p, parse_example_label(), v_array< T >::push_back(), setup_example(), feature::weight_index, and feature::x.

Referenced by VW_ImportExample().

792 {
793  example* ret = &get_unused_example(&all);
794  all.p->lp.default_label(&ret->l);
795 
796  if (label.length() > 0)
797  parse_example_label(all, *ret, label);
798 
799  for (size_t i = 0; i < len; i++)
800  {
801  unsigned char index = features[i].name;
802  ret->indices.push_back(index);
803  for (size_t j = 0; j < features[i].len; j++)
804  ret->feature_space[index].push_back(features[i].fs[j].x, features[i].fs[j].weight_index);
805  }
806 
807  setup_example(all, ret);
808  all.p->end_parsed_examples++;
809  return ret;
810 }
v_array< namespace_index > indices
void parse_example_label(vw &all, example &ec, std::string label)
Definition: parser.cc:846
void setup_example(vw &all, example *ae)
Definition: parser.cc:678
void(* default_label)(void *)
Definition: label_parser.h:12
the core definition of a set of features.
parser * p
Definition: global_data.h:377
std::array< features, NUM_NAMESPACES > feature_space
void push_back(const T &new_ele)
Definition: v_array.h:107
polylabel l
Definition: example.h:57
uint64_t end_parsed_examples
Definition: parser.h:82
example & get_unused_example(vw *all)
Definition: parser.cc:664
label_parser lp
Definition: parser.h:102

◆ init_features()

void VW::init_features ( primitive_feature_space fs,
size_t  features_count 
)
inline

Definition at line 191 of file vw.h.

References VW::primitive_feature_space::fs, and VW::primitive_feature_space::len.

Referenced by VW_InitFeatures().

192 {
193  fs.fs = new feature[features_count];
194  fs.len = features_count;
195 }

◆ initialize() [1/3]

vw * VW::initialize ( options_i options,
io_buf model,
bool  skipModelLoad,
trace_message_t  trace_listener,
void *  trace_context 
)

Definition at line 1654 of file parse_args.cc.

References VW::config::options_i::check_unregistered(), finish(), VW::config::options_i::get_typed_option(), VW::config::options_i::help(), LEARNER::learner< T, E >::init_driver(), vw::initial_regressors, vw::l, load_header_merge_options(), parse_args(), parse_dictionary_argument(), parse_modules(), parse_sources(), vw::per_feature_regularizer_input, read_regressor_file(), vw::trace_message, and VW::config::options_i::was_supplied().

Referenced by initialize(), initialize_escaped(), seed_vw_model(), setup(), VW_InitializeA(), and VW_InitializeWithModel().

1656 {
1657  vw& all = parse_args(options, trace_listener, trace_context);
1658 
1659  try
1660  {
1661  // if user doesn't pass in a model, read from options
1662  io_buf localModel;
1663  if (!model)
1664  {
1665  std::vector<std::string> all_initial_regressor_files(all.initial_regressors);
1666  if (options.was_supplied("input_feature_regularizer"))
1667  {
1668  all_initial_regressor_files.push_back(all.per_feature_regularizer_input);
1669  }
1670  read_regressor_file(all, all_initial_regressor_files, localModel);
1671  model = &localModel;
1672  }
1673 
1674  // Loads header of model files and loads the command line options into the options object.
1675  load_header_merge_options(options, all, *model);
1676 
1677  std::vector<std::string> dictionary_nses;
1678  parse_modules(options, all, dictionary_nses);
1679 
1680  parse_sources(options, all, *model, skipModelLoad);
1681 
1682  // we must delay so parse_mask is fully defined.
1683  for (size_t id = 0; id < dictionary_nses.size(); id++) parse_dictionary_argument(all, dictionary_nses[id]);
1684 
1685  options.check_unregistered();
1686 
1687  // upon direct query for help -- spit it out to stdout;
1688  if (options.get_typed_option<bool>("help").value())
1689  {
1690  cout << options.help();
1691  exit(0);
1692  }
1693 
1694  all.l->init_driver();
1695 
1696  return &all;
1697  }
1698  catch (std::exception& e)
1699  {
1700  all.trace_message << "Error: " << e.what() << endl;
1701  finish(all);
1702  throw;
1703  }
1704  catch (...)
1705  {
1706  finish(all);
1707  throw;
1708  }
1709 }
void finish(vw &all, bool delete_all)
Definition: parse_args.cc:1823
void parse_dictionary_argument(vw &all, std::string str)
Definition: parse_args.cc:158
vw & parse_args(options_i &options, trace_message_t trace_listener, void *trace_context)
Definition: parse_args.cc:1308
void parse_modules(options_i &options, vw &all, std::vector< std::string > &dictionary_nses)
Definition: parse_args.cc:1523
vw_ostream trace_message
Definition: global_data.h:424
Definition: io_buf.h:54
std::vector< std::string > initial_regressors
Definition: global_data.h:436
void parse_sources(options_i &options, vw &all, io_buf &model, bool skipModelLoad)
Definition: parse_args.cc:1551
options_i & load_header_merge_options(options_i &options, vw &all, io_buf &model)
Definition: parse_args.cc:1417
void read_regressor_file(vw &all, std::vector< std::string > all_intial, io_buf &io_temp)
LEARNER::base_learner * l
Definition: global_data.h:383
std::string per_feature_regularizer_input
Definition: global_data.h:440
void init_driver()
Definition: learner.h:298

◆ initialize() [2/3]

vw * VW::initialize ( std::string  s,
io_buf model,
bool  skipModelLoad,
trace_message_t  trace_listener,
void *  trace_context 
)

Definition at line 1711 of file parse_args.cc.

References free_args(), initialize(), and to_argv().

1712 {
1713  int argc = 0;
1714  char** argv = to_argv(s, argc);
1715  vw* ret = nullptr;
1716 
1717  try
1718  {
1719  ret = initialize(argc, argv, model, skipModelLoad, trace_listener, trace_context);
1720  }
1721  catch (...)
1722  {
1723  free_args(argc, argv);
1724  throw;
1725  }
1726 
1727  free_args(argc, argv);
1728  return ret;
1729 }
void free_args(int argc, char *argv[])
Definition: parse_args.cc:1648
char ** to_argv(std::string const &s, int &argc)
Definition: parse_args.cc:1623
vw * initialize(int argc, char *argv[], io_buf *model, bool skipModelLoad, trace_message_t trace_listener, void *trace_context)
Definition: parse_args.cc:1752

◆ initialize() [3/3]

vw * VW::initialize ( int  argc,
char *  argv[],
io_buf model,
bool  skipModelLoad,
trace_message_t  trace_listener,
void *  trace_context 
)

Definition at line 1752 of file parse_args.cc.

References initialize(), and vw::should_delete_options.

1754 {
1755  options_i* options = new config::options_boost_po(argc, argv);
1756  vw* all = initialize(*options, model, skipModelLoad, trace_listener, trace_context);
1757 
1758  // When VW is deleted the options object will be cleaned up too.
1759  all->should_delete_options = true;
1760  return all;
1761 }
bool should_delete_options
Definition: global_data.h:427
vw * initialize(int argc, char *argv[], io_buf *model, bool skipModelLoad, trace_message_t trace_listener, void *trace_context)
Definition: parse_args.cc:1752

◆ initialize_escaped()

vw * VW::initialize_escaped ( std::string const &  s,
io_buf model,
bool  skipModelLoad,
trace_message_t  trace_listener,
void *  trace_context 
)

Definition at line 1731 of file parse_args.cc.

References free_args(), initialize(), and to_argv_escaped().

Referenced by VW_InitializeEscapedA(), and VW_InitializeWithModelEscaped().

1733 {
1734  int argc = 0;
1735  char** argv = to_argv_escaped(s, argc);
1736  vw* ret = nullptr;
1737 
1738  try
1739  {
1740  ret = initialize(argc, argv, model, skipModelLoad, trace_listener, trace_context);
1741  }
1742  catch (...)
1743  {
1744  free_args(argc, argv);
1745  throw;
1746  }
1747 
1748  free_args(argc, argv);
1749  return ret;
1750 }
void free_args(int argc, char *argv[])
Definition: parse_args.cc:1648
char ** to_argv_escaped(std::string const &s, int &argc)
Definition: parse_args.cc:1604
vw * initialize(int argc, char *argv[], io_buf *model, bool skipModelLoad, trace_message_t trace_listener, void *trace_context)
Definition: parse_args.cc:1752

◆ is_ring_example()

bool VW::is_ring_example ( vw all,
example ae 
)

Definition at line 1009 of file parser.cc.

References parser::example_pool, VW::object_pool< T, TInitializer, TCleanup >::is_from_pool(), and vw::p.

Referenced by finish_example(), and ezexample::~ezexample().

1009 { return all.p->example_pool.is_from_pool(ae); }
VW::object_pool< example, example_initializer > example_pool
Definition: parser.h:66
parser * p
Definition: global_data.h:377
bool is_from_pool(T *obj) const
Definition: object_pool.h:190

◆ move_feature_namespace()

void VW::move_feature_namespace ( example dst,
example src,
namespace_index  c 
)

Definition at line 92 of file example.cc.

References v_array< T >::begin(), c, v_array< T >::end(), example_predict::feature_space, recall_tree_ns::find(), example_predict::indices, example::num_features, v_array< T >::push_back(), and example::total_sum_feat_sq.

Referenced by predict_or_learn().

93 {
94  if (std::find(src->indices.begin(), src->indices.end(), c) == src->indices.end())
95  return; // index not present in src
96  if (std::find(dst->indices.begin(), dst->indices.end(), c) == dst->indices.end())
97  dst->indices.push_back(c);
98 
99  auto& fdst = dst->feature_space[c];
100  auto& fsrc = src->feature_space[c];
101 
102  src->num_features -= fsrc.size();
103  src->total_sum_feat_sq -= fsrc.sum_feat_sq;
104  std::swap(fdst, fsrc);
105  dst->num_features += fdst.size();
106  dst->total_sum_feat_sq += fdst.sum_feat_sq;
107 }
v_array< namespace_index > indices
T *& begin()
Definition: v_array.h:42
std::array< features, NUM_NAMESPACES > feature_space
void push_back(const T &new_ele)
Definition: v_array.h:107
size_t num_features
Definition: example.h:67
T *& end()
Definition: v_array.h:43
node_pred * find(recall_tree &b, uint32_t cn, example &ec)
Definition: recall_tree.cc:126
float total_sum_feat_sq
Definition: example.h:71
constexpr uint64_t c
Definition: rand48.cc:12

◆ new_unused_example()

example * VW::new_unused_example ( vw all)

Definition at line 753 of file parser.cc.

References parser::begin_parsed_examples, label_parser::default_label, example::example_counter, get_unused_example(), example::l, parser::lp, and vw::p.

Referenced by ezexample::get_new_example().

754 {
755  example* ec = &get_unused_example(&all);
756  all.p->lp.default_label(&ec->l);
757  all.p->begin_parsed_examples++;
758  ec->example_counter = (size_t)all.p->begin_parsed_examples;
759  return ec;
760 }
size_t example_counter
Definition: example.h:64
void(* default_label)(void *)
Definition: label_parser.h:12
uint64_t begin_parsed_examples
Definition: parser.h:81
parser * p
Definition: global_data.h:377
polylabel l
Definition: example.h:57
example & get_unused_example(vw *all)
Definition: parser.cc:664
label_parser lp
Definition: parser.h:102

◆ num_weights()

uint32_t VW::num_weights ( vw all)
inline

Definition at line 187 of file vw.h.

References vw::length().

Referenced by SVRG::learn(), vw_slim::vw_predict< W >::load(), and VW_Num_Weights().

187 { return (uint32_t)all.length(); }
size_t length()
Definition: global_data.h:513

◆ parse_example_label()

void VW::parse_example_label ( vw all,
example ec,
std::string  label 
)

Definition at line 846 of file parser.cc.

References v_array< T >::clear(), v_array< T >::delete_v(), example::l, parser::lp, vw::p, label_parser::parse_label, vw::sd, and tokenize().

Referenced by import_example(), ezexample::set_label(), LabelState< audit >::String(), and VW_AddStringLabel().

847 {
848  v_array<substring> words = v_init<substring>();
849  char* cstr = (char*)label.c_str();
850  substring str = {cstr, cstr + label.length()};
851  tokenize(' ', str, words);
852  all.p->lp.parse_label(all.p, all.sd, &ec.l, words);
853  words.clear();
854  words.delete_v();
855 }
parser * p
Definition: global_data.h:377
shared_data * sd
Definition: global_data.h:375
void clear()
Definition: v_array.h:88
void tokenize(char delim, substring s, ContainerT &ret, bool allow_empty=false)
void(* parse_label)(parser *, shared_data *, void *, v_array< substring > &)
Definition: label_parser.h:13
polylabel l
Definition: example.h:57
void delete_v()
Definition: v_array.h:98
label_parser lp
Definition: parser.h:102

◆ read_example() [1/2]

example * VW::read_example ( vw all,
char *  example_line 
)

Definition at line 761 of file parser.cc.

References parser::end_parsed_examples, get_unused_example(), vw::p, read_line(), and setup_example().

Referenced by ezexample::finish(), read_example(), ezexample::setup_for_predict(), and VW_ReadExampleA().

762 {
763  example* ret = &get_unused_example(&all);
764 
765  VW::read_line(all, ret, example_line);
766  setup_example(all, ret);
767  all.p->end_parsed_examples++;
768 
769  return ret;
770 }
void read_line(vw &all, example *ex, char *line)
void setup_example(vw &all, example *ae)
Definition: parser.cc:678
parser * p
Definition: global_data.h:377
uint64_t end_parsed_examples
Definition: parser.h:82
example & get_unused_example(vw *all)
Definition: parser.cc:664

◆ read_example() [2/2]

example * VW::read_example ( vw all,
std::string  example_line 
)

Definition at line 772 of file parser.cc.

References read_example().

772 { return read_example(all, (char*)example_line.c_str()); }
example * read_example(vw &all, std::string example_line)
Definition: parser.cc:772

◆ read_line()

void VW::read_line ( vw all,
example ex,
char *  line 
)

Definition at line 487 of file parse_example.cc.

References substring::begin, substring::end, and substring_to_example().

Referenced by parse_dictionary_argument(), read_example(), and read_lines().

488 {
489  substring ss = {line, line + strlen(line)};
490  while ((ss.end >= ss.begin) && (*(ss.end - 1) == '\n')) ss.end--;
491  substring_to_example(&all, ex, ss);
492 }
char * end
Definition: hashstring.h:10
char * begin
Definition: hashstring.h:9
void substring_to_example(vw *all, example *ae, substring example)

◆ read_line_decision_service_json()

template<bool audit>
void VW::read_line_decision_service_json ( vw all,
v_array< example *> &  examples,
char *  line,
size_t  length,
bool  copy_line,
example_factory_t  example_factory,
void *  ex_factory_context,
DecisionServiceInteraction data 
)

Definition at line 1393 of file parse_example_json.h.

References apply_pdrop(), VWReaderHandler< audit >::ctx, VWReaderHandler< audit >::current_state(), VWReaderHandler< audit >::error(), json_parser< audit >::handler, VWReaderHandler< audit >::init(), BaseState< audit >::name, DecisionServiceInteraction::probabilityOfDrop, json_parser< audit >::reader, and THROW.

1395 {
1396  std::vector<char> line_vec;
1397  if (copy_line)
1398  {
1399  line_vec.insert(line_vec.end(), line, line + length);
1400  line = &line_vec.front();
1401  }
1402 
1403  InsituStringStream ss(line);
1405 
1406  VWReaderHandler<audit>& handler = parser.handler;
1407  handler.init(&all, &examples, &ss, line + length, example_factory, ex_factory_context);
1408  handler.ctx.SetStartStateToDecisionService(data);
1409 
1410  ParseResult result =
1411  parser.reader.template Parse<kParseInsituFlag, InsituStringStream, VWReaderHandler<audit>>(ss, handler);
1412 
1413  apply_pdrop(all, data->probabilityOfDrop, examples);
1414 
1415  if (!result.IsError())
1416  return;
1417 
1418  BaseState<audit>* current_state = handler.current_state();
1419 
1420  THROW("JSON parser error at " << result.Offset() << ": " << GetParseError_En(result.Code())
1421  << ". "
1422  "Handler: "
1423  << handler.error().str()
1424  << "State: " << (current_state ? current_state->name : "null"));
1425 } // namespace VW
void init(vw *all, v_array< example *> *examples, rapidjson::InsituStringStream *stream, const char *stream_end, VW::example_factory_t example_factory, void *example_factory_context)
VWReaderHandler< audit > handler
rapidjson::Reader reader
const char * name
BaseState< audit > * current_state()
std::stringstream & error()
void apply_pdrop(vw &all, float pdrop, v_array< example *> &examples)
Definition: parser.h:38
Context< audit > ctx
#define THROW(args)
Definition: vw_exception.h:181

◆ read_line_json()

template<bool audit>
void VW::read_line_json ( vw all,
v_array< example *> &  examples,
char *  line,
example_factory_t  example_factory,
void *  ex_factory_context 
)

Definition at line 1348 of file parse_example_json.h.

References VWReaderHandler< audit >::current_state(), VWReaderHandler< audit >::error(), json_parser< audit >::handler, VWReaderHandler< audit >::init(), BaseState< audit >::name, json_parser< audit >::reader, and THROW.

1350 {
1351  // string line_copy(line);
1352  // destructive parsing
1353  InsituStringStream ss(line);
1355 
1356  VWReaderHandler<audit>& handler = parser.handler;
1357  handler.init(&all, &examples, &ss, line + strlen(line), example_factory, ex_factory_context);
1358 
1359  ParseResult result =
1360  parser.reader.template Parse<kParseInsituFlag, InsituStringStream, VWReaderHandler<audit>>(ss, handler);
1361  if (!result.IsError())
1362  return;
1363 
1364  BaseState<audit>* current_state = handler.current_state();
1365 
1366  THROW("JSON parser error at " << result.Offset() << ": " << GetParseError_En(result.Code())
1367  << ". "
1368  "Handler: "
1369  << handler.error().str()
1370  << "State: " << (current_state ? current_state->name : "null")); // <<
1371  // "Line: '"<< line_copy << "'");
1372 }
void init(vw *all, v_array< example *> *examples, rapidjson::InsituStringStream *stream, const char *stream_end, VW::example_factory_t example_factory, void *example_factory_context)
VWReaderHandler< audit > handler
rapidjson::Reader reader
const char * name
BaseState< audit > * current_state()
std::stringstream & error()
Definition: parser.h:38
#define THROW(args)
Definition: vw_exception.h:181

◆ read_lines()

void VW::read_lines ( vw all,
char *  line,
size_t  ,
v_array< example *> &  examples 
)

Definition at line 494 of file parse_example.cc.

References get_unused_example(), v_array< T >::push_back(), read_line(), v_array< T >::size(), and split().

Referenced by enable_sources().

495 {
496  auto lines = split(line, "\n");
497  for (size_t i = 0; i < lines.size(); i++)
498  {
499  // Check if a new empty example needs to be added.
500  if (examples.size() < i + 1)
501  {
502  examples.push_back(&VW::get_unused_example(all));
503  }
504  read_line(*all, examples[i], const_cast<char*>(lines[i].c_str()));
505  }
506 }
void read_line(vw &all, example *ex, char *line)
size_t size() const
Definition: v_array.h:68
void push_back(const T &new_ele)
Definition: v_array.h:107
std::vector< std::string > split(char *phrase, const std::string &delimiter)
example & get_unused_example(vw *all)
Definition: parser.cc:664

◆ releaseFeatureSpace()

void VW::releaseFeatureSpace ( primitive_feature_space features,
size_t  len 
)

Definition at line 840 of file parser.cc.

Referenced by VW_ReleaseFeatureSpace().

841 {
842  for (size_t i = 0; i < len; i++) delete[] features[i].fs;
843  delete (features);
844 }
the core definition of a set of features.

◆ return_features()

void VW::return_features ( feature f)

Definition at line 137 of file example.cc.

References free_it().

Referenced by VW_ReturnFeatures().

137 { free_it(f); }
void free_it(void *ptr)
Definition: memory.h:94

◆ return_multiple_example()

void VW::return_multiple_example ( vw all,
v_array< example *> &  examples 
)

Definition at line 251 of file example.cc.

References clean_example().

Referenced by line_to_examples_json(), and parse_line_json().

252 {
253  for (auto ec : examples)
254  {
255  clean_example(all, *ec, true);
256  }
257  examples.clear();
258 }
void clean_example(vw &, example &, bool rewind)
Definition: parser.cc:867

◆ save_predictor() [1/2]

void VW::save_predictor ( vw all,
std::string  reg_name 
)

Definition at line 642 of file parse_regressor.cc.

References dump_regressor().

Referenced by predict_or_learn(), VW_CopyModelData(), and VW_SaveModel().

642 { dump_regressor(all, reg_name, false); }
void dump_regressor(vw &all, io_buf &buf, bool as_text)

◆ save_predictor() [2/2]

void VW::save_predictor ( vw all,
io_buf buf 
)

Definition at line 644 of file parse_regressor.cc.

References dump_regressor().

644 { dump_regressor(all, buf, false); }
void dump_regressor(vw &all, io_buf &buf, bool as_text)

◆ seed_vw_model()

vw * VW::seed_vw_model ( vw vw_model,
const std::string  extra_args,
trace_message_t  trace_listener,
void *  trace_context 
)

Definition at line 1765 of file parse_args.cc.

References VW::config::options_serializer_boost_po::add(), free_it(), VW::config::options_i::get_all_options(), initialize(), vw::options, vw::sd, parameters::shallow_copy(), VW::config::options_serializer_boost_po::str(), VW::config::options_i::was_supplied(), and vw::weights.

Referenced by VW_SeedWithModel().

1766 {
1767  options_serializer_boost_po serializer;
1768  for (auto const& option : vw_model->options->get_all_options())
1769  {
1770  if (vw_model->options->was_supplied(option->m_name))
1771  {
1772  // ignore no_stdin since it will be added by vw::initialize, and ignore -i since we don't want to reload the
1773  // model.
1774  if (option->m_name == "no_stdin" || option->m_name == "initial_regressor")
1775  {
1776  continue;
1777  }
1778 
1779  serializer.add(*option);
1780  }
1781  }
1782 
1783  auto serialized_options = serializer.str();
1784  serialized_options = serialized_options + " " + extra_args;
1785 
1786  vw* new_model =
1787  VW::initialize(serialized_options.c_str(), nullptr, true /* skipModelLoad */, trace_listener, trace_context);
1788  free_it(new_model->sd);
1789 
1790  // reference model states stored in the specified VW instance
1791  new_model->weights.shallow_copy(vw_model->weights); // regressor
1792  new_model->sd = vw_model->sd; // shared data
1793 
1794  return new_model;
1795 }
parameters weights
Definition: global_data.h:537
VW::config::options_i * options
Definition: global_data.h:428
void free_it(void *ptr)
Definition: memory.h:94
virtual std::vector< std::shared_ptr< base_option > > get_all_options()=0
shared_data * sd
Definition: global_data.h:375
virtual bool was_supplied(const std::string &key)=0
vw * initialize(options_i &options, io_buf *model, bool skipModelLoad, trace_message_t trace_listener, void *trace_context)
Definition: parse_args.cc:1654
virtual void add(base_option &option) override
void shallow_copy(const parameters &input)

◆ set_feature()

void VW::set_feature ( primitive_feature_space fs,
size_t  index,
uint64_t  feature_hash,
float  value 
)
inline

Definition at line 197 of file vw.h.

References VW::primitive_feature_space::fs, feature::weight_index, and feature::x.

Referenced by VW_SetFeature().

198 {
199  fs.fs[index].weight_index = feature_hash;
200  fs.fs[index].x = value;
201 }

◆ set_weight()

void VW::set_weight ( vw all,
uint32_t  index,
uint32_t  offset,
float  value 
)
inline

Definition at line 182 of file vw.h.

References parameters::stride_shift(), and vw::weights.

Referenced by SVRG::learn(), GD::save_load(), and VW_Set_Weight().

183 {
184  (&all.weights[((uint64_t)index) << all.weights.stride_shift()])[offset] = value;
185 }
parameters weights
Definition: global_data.h:537
uint32_t stride_shift()

◆ setup_example()

void VW::setup_example ( vw all,
example ae 
)

Definition at line 678 of file parser.cc.

References vw::add_constant, add_constant_feature(), v_array< T >::begin(), cache_features(), label_parser::cache_label, parser::emptylines_separate_examples, v_array< T >::end(), parser::end_parsed_examples, INTERACTIONS::eval_count_of_generated_ft(), example::example_counter, example_is_newline(), feature_limit(), example_predict::feature_space, generateGrams(), label_parser::get_weight, vw::holdout_after, vw::holdout_period, vw::holdout_set_off, vw::ignore, vw::ignore_some, parser::in_pass_counter, example_predict::indices, vw::interactions, is_test_only(), example::l, vw::limit_strings, example::loss, parser::lp, vw::ngram_strings, example::num_features, parser::output, vw::p, vw::parse_mask, example::partial_prediction, parser::sort_features, example::sorted, parameters::stride_shift(), label_parser::test_label, example::test_only, example::total_sum_feat_sq, unique_sort_features(), example::weight, vw::weights, vw::wpp, and parser::write_cache.

Referenced by import_example(), read_example(), and setup_examples().

679 {
680  if (all.p->sort_features && ae->sorted == false)
682 
683  if (all.p->write_cache)
684  {
685  all.p->lp.cache_label(&ae->l, *(all.p->output));
686  cache_features(*(all.p->output), ae, all.parse_mask);
687  }
688 
689  ae->partial_prediction = 0.;
690  ae->num_features = 0;
691  ae->total_sum_feat_sq = 0;
692  ae->loss = 0.;
693 
694  ae->example_counter = (size_t)(all.p->end_parsed_examples);
696  all.p->in_pass_counter++;
697 
699  all.p->emptylines_separate_examples ? (all.holdout_period - 1) : 0);
700  ae->test_only |= all.p->lp.test_label(&ae->l);
701 
703  all.p->in_pass_counter++;
704 
705  ae->weight = all.p->lp.get_weight(&ae->l);
706 
707  if (all.ignore_some)
708  for (unsigned char* i = ae->indices.begin(); i != ae->indices.end(); i++)
709  if (all.ignore[*i])
710  {
711  // delete namespace
712  ae->feature_space[*i].clear();
713  memmove(i, i + 1, (ae->indices.end() - (i + 1)) * sizeof(*i));
714  ae->indices.end()--;
715  i--;
716  }
717 
718  if (!all.ngram_strings.empty())
719  generateGrams(all, ae);
720 
721  if (all.add_constant) // add constant feature
722  VW::add_constant_feature(all, ae);
723 
724  if (!all.limit_strings.empty())
725  feature_limit(all, ae);
726 
727  uint64_t multiplier = (uint64_t)all.wpp << all.weights.stride_shift();
728 
729  if (multiplier != 1) // make room for per-feature information.
730  for (features& fs : *ae)
731  for (auto& j : fs.indicies) j *= multiplier;
732  ae->num_features = 0;
733  ae->total_sum_feat_sq = 0;
734  for (features& fs : *ae)
735  {
736  ae->num_features += fs.size();
737  ae->total_sum_feat_sq += fs.sum_feat_sq;
738  }
739 
740  // Set the interactions for this example to the global set.
741  ae->interactions = &all.interactions;
742 
743  size_t new_features_cnt;
744  float new_features_sum_feat_sq;
745  INTERACTIONS::eval_count_of_generated_ft(all, *ae, new_features_cnt, new_features_sum_feat_sq);
746  ae->num_features += new_features_cnt;
747  ae->total_sum_feat_sq += new_features_sum_feat_sq;
748 }
uint32_t holdout_after
Definition: global_data.h:502
v_array< namespace_index > indices
size_t example_counter
Definition: example.h:64
parameters weights
Definition: global_data.h:537
void unique_sort_features(uint64_t parse_mask, example *ae)
Definition: unique_sort.cc:33
std::vector< std::string > ngram_strings
Definition: global_data.h:469
void eval_count_of_generated_ft(vw &all, example &ec, size_t &new_features_cnt, float &new_features_value)
bool add_constant
Definition: global_data.h:496
bool sorted
Definition: example.h:78
bool(* test_label)(void *)
Definition: label_parser.h:22
the core definition of a set of features.
void generateGrams(vw &all, example *&ex)
Definition: parser.cc:630
float partial_prediction
Definition: example.h:68
std::vector< std::string > limit_strings
Definition: global_data.h:473
bool holdout_set_off
Definition: global_data.h:499
int example_is_newline(example const &ec)
Definition: example.h:104
std::array< bool, NUM_NAMESPACES > ignore
Definition: global_data.h:463
T *& begin()
Definition: v_array.h:42
bool is_test_only(uint32_t counter, uint32_t period, uint32_t after, bool holdout_off, uint32_t target_modulus)
Definition: parser.cc:70
parser * p
Definition: global_data.h:377
std::array< features, NUM_NAMESPACES > feature_space
bool ignore_some
Definition: global_data.h:462
float(* get_weight)(void *)
Definition: label_parser.h:17
size_t num_features
Definition: example.h:67
void(* cache_label)(void *, io_buf &cache)
Definition: label_parser.h:14
void add_constant_feature(vw &vw, example *ec)
Definition: parser.cc:774
uint32_t wpp
Definition: global_data.h:432
T *& end()
Definition: v_array.h:43
float loss
Definition: example.h:70
void feature_limit(vw &all, example *ex)
Definition: parser.cc:651
polylabel l
Definition: example.h:57
uint64_t parse_mask
Definition: global_data.h:453
float total_sum_feat_sq
Definition: example.h:71
void cache_features(io_buf &cache, example *ae, uint64_t mask)
Definition: cache.cc:203
io_buf * output
Definition: parser.h:75
uint64_t end_parsed_examples
Definition: parser.h:82
std::vector< std::string > interactions
Definition: global_data.h:457
uint32_t stride_shift()
bool sort_features
Definition: parser.h:77
float weight
Definition: example.h:62
uint32_t in_pass_counter
Definition: parser.h:83
bool emptylines_separate_examples
Definition: parser.h:84
bool write_cache
Definition: parser.h:76
uint32_t holdout_period
Definition: global_data.h:501
label_parser lp
Definition: parser.h:102
bool test_only
Definition: example.h:76

◆ setup_examples()

void VW::setup_examples ( vw all,
v_array< example *> &  examples 
)

Definition at line 673 of file parser.cc.

References setup_example().

Referenced by parse_dispatch().

674 {
675  for (example* ae : examples) setup_example(all, ae);
676 }
void setup_example(vw &all, example *ae)
Definition: parser.cc:678

◆ start_parser()

void VW::start_parser ( vw all)

Definition at line 974 of file parser.cc.

References main_parse_loop(), and vw::parse_thread.

Referenced by main(), VW_Finish_Passes(), and VW_StartParser().

974 { all.parse_thread = std::thread(main_parse_loop, &all); }
void main_parse_loop(vw *all)
Definition: parser.cc:905
std::thread parse_thread
Definition: global_data.h:378

◆ sync_stats()

void VW::sync_stats ( vw all)

Definition at line 1804 of file parse_args.cc.

References accumulate_scalar(), vw::all_reduce, shared_data::example_number, loss(), vw::sd, shared_data::sum_loss, shared_data::total_features, shared_data::weighted_labeled_examples, shared_data::weighted_labels, and shared_data::weighted_unlabeled_examples.

Referenced by main().

1805 {
1806  if (all.all_reduce != nullptr)
1807  {
1808  float loss = (float)all.sd->sum_loss;
1809  all.sd->sum_loss = (double)accumulate_scalar(all, loss);
1810  float weighted_labeled_examples = (float)all.sd->weighted_labeled_examples;
1811  all.sd->weighted_labeled_examples = (double)accumulate_scalar(all, weighted_labeled_examples);
1812  float weighted_labels = (float)all.sd->weighted_labels;
1813  all.sd->weighted_labels = (double)accumulate_scalar(all, weighted_labels);
1814  float weighted_unlabeled_examples = (float)all.sd->weighted_unlabeled_examples;
1815  all.sd->weighted_unlabeled_examples = (double)accumulate_scalar(all, weighted_unlabeled_examples);
1816  float example_number = (float)all.sd->example_number;
1817  all.sd->example_number = (uint64_t)accumulate_scalar(all, example_number);
1818  float total_features = (float)all.sd->total_features;
1819  all.sd->total_features = (uint64_t)accumulate_scalar(all, total_features);
1820  }
1821 }
double sum_loss
Definition: global_data.h:145
double weighted_unlabeled_examples
Definition: global_data.h:143
float loss(cbify &data, uint32_t label, uint32_t final_prediction)
Definition: cbify.cc:60
AllReduce * all_reduce
Definition: global_data.h:381
shared_data * sd
Definition: global_data.h:375
double weighted_labels
Definition: global_data.h:144
uint64_t example_number
Definition: global_data.h:137
float accumulate_scalar(vw &all, float local_sum)
Definition: accumulate.cc:44
double weighted_labeled_examples
Definition: global_data.h:141
uint64_t total_features
Definition: global_data.h:138

◆ to_argv()

char ** VW::to_argv ( std::string const &  s,
int &  argc 
)

Definition at line 1623 of file parse_args.cc.

References c, and tokenize().

Referenced by get_argv_from_string(), and initialize().

1624 {
1625  char* c = calloc_or_throw<char>(s.length() + 3);
1626  c[0] = 'b';
1627  c[1] = ' ';
1628  strcpy(c + 2, s.c_str());
1629  substring ss = {c, c + s.length() + 2};
1630  std::vector<substring> foo;
1631  tokenize(' ', ss, foo);
1632 
1633  char** argv = calloc_or_throw<char*>(foo.size());
1634  for (size_t i = 0; i < foo.size(); i++)
1635  {
1636  *(foo[i].end) = '\0';
1637  argv[i] = calloc_or_throw<char>(foo[i].end - foo[i].begin + 1);
1638  sprintf(argv[i], "%s", foo[i].begin);
1639  }
1640 
1641  argc = (int)foo.size();
1642  free(c);
1643  return argv;
1644 }
void tokenize(char delim, substring s, ContainerT &ret, bool allow_empty=false)
constexpr uint64_t c
Definition: rand48.cc:12

◆ to_argv_escaped()

char ** VW::to_argv_escaped ( std::string const &  s,
int &  argc 
)

Definition at line 1604 of file parse_args.cc.

References escaped_tokenize().

Referenced by initialize_escaped().

1605 {
1606  substring ss = {const_cast<char*>(s.c_str()), const_cast<char*>(s.c_str() + s.length())};
1607  std::vector<substring> tokens = escaped_tokenize(' ', ss);
1608  char** argv = calloc_or_throw<char*>(tokens.size() + 1);
1609  argv[0] = calloc_or_throw<char>(2);
1610  argv[0][0] = 'b';
1611  argv[0][1] = '\0';
1612 
1613  for (size_t i = 0; i < tokens.size(); i++)
1614  {
1615  argv[i + 1] = calloc_or_throw<char>(tokens[i].end - tokens[i].begin + 1);
1616  sprintf(argv[i + 1], "%s", tokens[i].begin);
1617  }
1618 
1619  argc = static_cast<int>(tokens.size() + 1);
1620  return argv;
1621 }
std::vector< substring > escaped_tokenize(char delim, substring s, bool allow_empty)

◆ validate_default_bits()

void VW::validate_default_bits ( vw all,
uint32_t  local_num_bits 
)

Definition at line 26 of file vw_validate.cc.

References vw::default_bits, vw::num_bits, and THROW.

Referenced by save_load_header().

27 {
28  if (all.default_bits != true && all.num_bits != local_num_bits)
29  THROW("-b bits mismatch: command-line " << all.num_bits << " != " << local_num_bits << " stored in model");
30 }
uint32_t num_bits
Definition: global_data.h:398
bool default_bits
Definition: global_data.h:399
#define THROW(args)
Definition: vw_exception.h:181

◆ validate_min_max_label()

void VW::validate_min_max_label ( vw all)

Definition at line 20 of file vw_validate.cc.

References shared_data::max_label, shared_data::min_label, vw::sd, and THROW.

21 {
22  if (all.sd->max_label < all.sd->min_label)
23  THROW("Max label cannot be less than min label.");
24 }
shared_data * sd
Definition: global_data.h:375
float min_label
Definition: global_data.h:150
float max_label
Definition: global_data.h:151
#define THROW(args)
Definition: vw_exception.h:181

◆ validate_num_bits()

void VW::validate_num_bits ( vw all)

Definition at line 32 of file vw_validate.cc.

References vw::num_bits, and THROW.

Referenced by parse_feature_tweaks(), and save_load_header().

33 {
34  if (all.num_bits > sizeof(size_t) * 8 - 3)
35  THROW("Only " << sizeof(size_t) * 8 - 3 << " or fewer bits allowed. If this is a serious limit, speak up.");
36 }
uint32_t num_bits
Definition: global_data.h:398
#define THROW(args)
Definition: vw_exception.h:181

◆ validate_version()

void VW::validate_version ( vw all)

Definition at line 12 of file vw_validate.cc.

References LAST_COMPATIBLE_VERSION, vw::model_file_ver, THROW, and VW::version_struct::to_string().

Referenced by save_load_header().

13 {
15  THROW("Model has possibly incompatible version! " << all.model_file_ver.to_string());
16  if (all.model_file_ver > PACKAGE_VERSION)
17  std::cerr << "Warning: model version is more recent than VW version. This may not work." << std::endl;
18 }
VW::version_struct model_file_ver
Definition: global_data.h:419
#define LAST_COMPATIBLE_VERSION
Definition: vw_versions.h:10
std::string to_string() const
Definition: version.cc:97
#define THROW(args)
Definition: vw_exception.h:181

◆ version()

const version_struct VW::version ( PACKAGE_VERSION  )