blob: d9afc63b77aab3258016bd5598b4aa43178c5f80 (
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 <float.h>
#include "reductions.h"
#include "multiclass.h"
#include "simple_label.h"
namespace BINARY {
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 a label not -1 or 1 with a loss function expecting that!" << endl;
else
if (ec.l.simple.label == ec.pred.scalar)
ec.loss = 0.;
else
ec.loss = ec.l.simple.weight;
}
}
LEARNER::base_learner* setup(vw& all)
{//parse and set arguments
new_options(all,"Binary options")
("binary", "report loss as binary classification on -1,1");
if(missing_required(all)) return NULL;
//Create new learner
LEARNER::learner<char>& ret =
LEARNER::init_learner<char>(NULL, setup_base(all),
predict_or_learn<true>, predict_or_learn<false>);
return make_base(ret);
}
}
|