blob: 585f185a754b3327c2b2aad2f3cfd7a933855ebb (
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
44
|
#include "reductions.h"
#include "multiclass.h"
#include "simple_label.h"
using namespace LEARNER;
namespace BINARY {
template <bool is_learn>
void predict_or_learn(float&, learner& base, example& ec) {
if (is_learn)
base.learn(ec);
else
base.predict(ec);
label_data* ld = (label_data*)ec.ld;//New loss
if ( ld->prediction > 0)
ld->prediction = 1;
else
ld->prediction = -1;
if (ld->label == ld->prediction)
ec.loss = 0.;
else
ec.loss = 1.;
}
learner* setup(vw& all, std::vector<std::string>&opts, po::variables_map& vm, po::variables_map& vm_file)
{//parse and set arguments
if (!vm_file.count("binary"))
{
std::stringstream ss;
ss << " --binary ";
all.options_from_file.append(ss.str());
}
all.sd->binary_label = true;
//Create new learner
learner* ret = new learner(NULL, all.l);
ret->set_learn<float, predict_or_learn<true> >();
ret->set_predict<float, predict_or_learn<false> >();
return ret;
}
}
|