#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(*(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(); 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& ret = init_learner(&p, learn, 1); return make_base(ret); } }