-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
binary.cc
35 lines (30 loc) · 968 Bytes
/
binary.cc
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
#include <float.h>
#include "reductions.h"
using namespace std;
template <bool is_learn>
void predict_or_learn(char&, LEARNER::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 != FLT_MAX)
{ if (fabs(ec.l.simple.label) != 1.f)
cout << "You are using label " << ec.l.simple.label << " not -1 or 1 as loss function expects!" << endl;
else if (ec.l.simple.label == ec.pred.scalar)
ec.loss = 0.;
else
ec.loss = ec.weight;
}
}
LEARNER::base_learner* binary_setup(vw& all)
{ if (missing_option(all, false, "binary", "report loss as binary classification on -1,1"))
return nullptr;
LEARNER::learner<char>& ret =
LEARNER::init_learner<char>(nullptr, setup_base(all),
predict_or_learn<true>, predict_or_learn<false>);
return make_base(ret);
}