Vowpal Wabbit
Classes | Functions
print.cc File Reference
#include "gd.h"
#include <cfloat>
#include "reductions.h"

Go to the source code of this file.

Classes

struct  print
 

Functions

void print_feature (vw &, float value, uint64_t index)
 
void learn (print &p, LEARNER::base_learner &, example &ec)
 
LEARNER::base_learnerprint_setup (options_i &options, vw &all)
 

Function Documentation

◆ learn()

void learn ( print p,
LEARNER::base_learner ,
example ec 
)

Definition at line 22 of file print.cc.

References print::all, v_array< T >::begin(), v_array< T >::empty(), label_data::initial, example::l, label_data::label, polylabel::simple, v_array< T >::size(), example::tag, and example::weight.

Referenced by print_setup().

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 }
v_array< char > tag
Definition: example.h:63
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
float initial
Definition: simple_label.h:16
polylabel l
Definition: example.h:57
bool empty() const
Definition: v_array.h:59
vw * all
Definition: print.cc:11
float weight
Definition: example.h:62

◆ print_feature()

void print_feature ( vw ,
float  value,
uint64_t  index 
)

Definition at line 14 of file print.cc.

15 {
16  cout << index;
17  if (value != 1.)
18  cout << ":" << value;
19  cout << " ";
20 }

◆ print_setup()

LEARNER::base_learner* print_setup ( options_i options,
vw all 
)

Definition at line 45 of file print.cc.

References VW::config::option_group_definition::add(), VW::config::options_i::add_and_parse(), LEARNER::init_learner(), learn(), LEARNER::make_base(), VW::config::make_option(), parameters::stride_shift(), and vw::weights.

Referenced by parse_reductions().

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 }
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
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
typed_option< T > make_option(std::string name, T &location)
Definition: options.h:80
uint32_t stride_shift()