Welcome to mirror list, hosted at ThFree Co, Russian Federation.

binary.cc « vowpalwabbit - github.com/moses-smt/vowpal_wabbit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7eac0ba8b60b86efc134bf5364df9cb577b63d7e (plain)
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
#include "reductions.h"
#include "multiclass.h"
#include "simple_label.h"

using namespace LEARNER;

namespace BINARY {

  template <bool is_learn>
  void predict_or_learn(char&, base_learner& base, example& ec) {
    if (is_learn)
      base.learn(ec);
    else
      base.predict(ec);

    if ( ec.pred.scalar > 0)
      ec.pred.scalar = 1;
    else
      ec.pred.scalar = -1;

    if (ec.l.simple.label == ec.pred.scalar)
      ec.loss = 0.;
    else
      ec.loss = ec.l.simple.weight;
  }

  base_learner* setup(vw& all, po::variables_map& vm)
  {//parse and set arguments
    po::options_description opts("Binary options");
    opts.add_options()
      ("binary", "report loss as binary classification on -1,1");
    vm = add_options(all,opts);
    if(!vm.count("binary"))
      return NULL;

    all.sd->binary_label = true;
    //Create new learner
    learner<char>& ret = init_learner<char>(NULL, all.l);
    ret.set_learn(predict_or_learn<true>);
    ret.set_predict(predict_or_learn<false>);
    return make_base(ret);
  }
}