Vowpal Wabbit
Namespaces | Classes | Enumerations | Functions
vw_slim Namespace Reference

Namespaces

 internal
 

Classes

class  example_predict_builder
 
class  feature_offset_guard
 
class  model_parser
 
class  namespace_copy_guard
 
class  stride_shift_guard
 
class  vw_predict
 Vowpal Wabbit slim predictor. Supports: regression, multi-class classification and contextual bandits. More...
 

Enumerations

enum  vw_predict_exploration { epsilon_greedy, softmax, bag }
 Exploration algorithm specified by the model. More...
 

Functions

void find_opt (std::string const &command_line_args, std::string arg_name, std::vector< std::string > &out_values)
 
std::vector< std::string > find_opt (std::string const &command_line_args, std::string arg_name)
 
bool find_opt_float (std::string const &command_line_args, std::string arg_name, float &value)
 
bool find_opt_int (std::string const &command_line_args, std::string arg_name, int &value)
 
uint64_t ceil_log_2 (uint64_t v)
 
template<typename T , typename S , S(*)(const char *) F>
bool find_opt_parse (std::string const &command_line_args, std::string arg_name, T &value)
 

Enumeration Type Documentation

◆ vw_predict_exploration

Exploration algorithm specified by the model.

Enumerator
epsilon_greedy 
softmax 
bag 

Definition at line 170 of file vw_slim_predict.h.

Function Documentation

◆ ceil_log_2()

uint64_t vw_slim::ceil_log_2 ( uint64_t  v)

Definition at line 8 of file vw_slim_predict.cc.

Referenced by vw_slim::vw_predict< W >::load().

9 {
10  if (v == 0)
11  return 0;
12  else
13  return 1 + ceil_log_2(v >> 1);
14 }
uint64_t ceil_log_2(uint64_t v)
Definition: gd.cc:1111

◆ find_opt() [1/2]

void vw_slim::find_opt ( std::string const &  command_line_args,
std::string  arg_name,
std::vector< std::string > &  out_values 
)

Definition at line 9 of file opts.cc.

Referenced by find_opt(), find_opt_parse(), vw_slim::vw_predict< W >::load(), and TEST().

10 {
11  // append space to search for '--quadratic '
12  arg_name += ' ';
13 
14  // support -q ab -v -q cd
15  for (size_t start = 0; start < command_line_args.size();)
16  {
17  auto idx = command_line_args.find(arg_name, start);
18  if (idx == std::string::npos)
19  return; // no more occurences found, exit
20 
21  auto idx_after_arg = idx + arg_name.size();
22 
23  // skip all white space
24  for (; idx_after_arg < command_line_args.size() && std::isspace(command_line_args[idx_after_arg]); ++idx_after_arg)
25  ;
26 
27  if (idx_after_arg == command_line_args.size())
28  return;
29 
30  if (command_line_args[idx_after_arg] == '-' &&
31  // make sure we allow -5.2 (negative numbers)
32  !(idx_after_arg + 1 < command_line_args.size() &&
33  (command_line_args[idx_after_arg + 1] >= '0' && command_line_args[idx_after_arg + 1] <= '9')))
34  {
35  start = idx_after_arg;
36  continue; // next option found
37  }
38 
39  // find next non-white space character
40  auto idx_after_value = idx_after_arg;
41  for (; idx_after_value < command_line_args.size() && !std::isspace(command_line_args[idx_after_value]);
42  ++idx_after_value)
43  ;
44 
45  auto value_size = idx_after_value - idx_after_arg;
46  if (value_size > 0)
47  out_values.push_back(command_line_args.substr(idx_after_arg, value_size));
48 
49  start = idx_after_arg + 1;
50  }
51 }

◆ find_opt() [2/2]

std::vector< std::string > vw_slim::find_opt ( std::string const &  command_line_args,
std::string  arg_name 
)

Definition at line 53 of file opts.cc.

References find_opt().

54 {
55  std::vector<std::string> values;
56  find_opt(command_line_args, arg_name, values);
57  return values;
58 }
void find_opt(std::string const &command_line_args, std::string arg_name, std::vector< std::string > &out_values)
Definition: opts.cc:9

◆ find_opt_float()

bool vw_slim::find_opt_float ( std::string const &  command_line_args,
std::string  arg_name,
float &  value 
)

Definition at line 73 of file opts.cc.

Referenced by vw_slim::vw_predict< W >::load(), and TEST().

74 {
75  return find_opt_parse<float, double, atof>(command_line_args, arg_name, value);
76 }

◆ find_opt_int()

bool vw_slim::find_opt_int ( std::string const &  command_line_args,
std::string  arg_name,
int &  value 
)

Definition at line 78 of file opts.cc.

Referenced by vw_slim::vw_predict< W >::load(), and TEST().

79 {
80  return find_opt_parse<int, int, atoi>(command_line_args, arg_name, value);
81 }

◆ find_opt_parse()

template<typename T , typename S , S(*)(const char *) F>
bool vw_slim::find_opt_parse ( std::string const &  command_line_args,
std::string  arg_name,
T &  value 
)

Definition at line 61 of file opts.cc.

References find_opt().

62 {
63  std::vector<std::string> opts = find_opt(command_line_args, arg_name);
64 
65  if (opts.size() != 1)
66  return false;
67 
68  value = (T)F(opts[0].c_str());
69 
70  return true;
71 }
void find_opt(std::string const &command_line_args, std::string arg_name, std::vector< std::string > &out_values)
Definition: opts.cc:9