1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#include "example.h"
#include "simple_label.h"
#include "gd.h"
#include "float.h"
#include "reductions.h"
namespace PRINT
{
struct print{ vw* all; };
void print_feature(vw& all, float value, float& weight)
{
size_t index = &weight - all.reg.weight_vector;
cout << index;
if (value != 1.)
cout << ":" << value;
cout << " ";
}
void learn(print& p, LEARNER::base_learner& base, example& ec)
{
label_data& ld = ec.l.simple;
if (ld.label != FLT_MAX)
{
cout << ld.label << " ";
if (ld.weight != 1 || ld.initial != 0)
{
cout << ld.weight << " ";
if (ld.initial != 0)
cout << ld.initial << " ";
}
}
if (ec.tag.size() > 0)
{
cout << '\'';
cout.write(ec.tag.begin, ec.tag.size());
}
cout << "| ";
GD::foreach_feature<vw, print_feature>(*(p.all), ec, *p.all);
cout << endl;
}
LEARNER::base_learner* setup(vw& all, po::variables_map& vm)
{
po::options_description opts("Print options");
opts.add_options()
("print","print examples");
vm = add_options(all, opts);
if(!vm.count("print"))
return NULL;
print& p = calloc_or_die<print>();
p.all = &all;
size_t length = ((size_t)1) << all.num_bits;
all.reg.weight_mask = (length << all.reg.stride_shift) - 1;
all.reg.stride_shift = 0;
LEARNER::learner<print>& ret = init_learner(&p, learn, 1);
return make_base(ret);
}
}
|