Vowpal Wabbit
print.cc
Go to the documentation of this file.
1 #include "gd.h"
2 #include <cfloat>
3 #include "reductions.h"
4 
5 using namespace VW::config;
6 
7 using std::cout;
8 
9 struct print
10 {
11  vw* all;
12 }; // regressor, feature loop
13 
14 void print_feature(vw& /* all */, float value, uint64_t index)
15 {
16  cout << index;
17  if (value != 1.)
18  cout << ":" << value;
19  cout << " ";
20 }
21 
23 {
24  label_data& ld = ec.l.simple;
25  if (ld.label != FLT_MAX)
26  {
27  cout << ld.label << " ";
28  if (ec.weight != 1 || ld.initial != 0)
29  {
30  cout << ec.weight << " ";
31  if (ld.initial != 0)
32  cout << ld.initial << " ";
33  }
34  }
35  if (!ec.tag.empty())
36  {
37  cout << '\'';
38  cout.write(ec.tag.begin(), ec.tag.size());
39  }
40  cout << "| ";
41  GD::foreach_feature<vw, uint64_t, print_feature>(*(p.all), ec, *p.all);
42  cout << std::endl;
43 }
44 
46 {
47  bool print_option = false;
48  option_group_definition new_options("Print psuedolearner");
49  new_options.add(make_option("print", print_option).keep().help("print examples"));
50  options.add_and_parse(new_options);
51 
52  if (!print_option)
53  return nullptr;
54 
55  auto p = scoped_calloc_or_throw<print>();
56  p->all = &all;
57 
58  all.weights.stride_shift(0);
59 
61  return make_base(ret);
62 }
v_array< char > tag
Definition: example.h:63
parameters weights
Definition: global_data.h:537
base_learner * make_base(learner< T, E > &base)
Definition: learner.h:462
virtual void add_and_parse(const option_group_definition &group)=0
float label
Definition: simple_label.h:14
label_data simple
Definition: example.h:28
T *& begin()
Definition: v_array.h:42
size_t size() const
Definition: v_array.h:68
learner< T, E > & init_learner(free_ptr< T > &dat, L *base, void(*learn)(T &, L &, E &), void(*predict)(T &, L &, E &), size_t ws, prediction_type::prediction_type_t pred_type)
Definition: learner.h:369
float initial
Definition: simple_label.h:16
option_group_definition & add(T &&op)
Definition: options.h:90
polylabel l
Definition: example.h:57
typed_option< T > make_option(std::string name, T &location)
Definition: options.h:80
bool empty() const
Definition: v_array.h:59
vw * all
Definition: print.cc:11
uint32_t stride_shift()
Definition: print.cc:9
float weight
Definition: example.h:62