blob: f7f0e8b4572e1c5b6d08317c6950344d23865ce6 (
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 "oaa.h"
#include "vw.h"
using namespace LEARNER;
namespace BINARY {
template <bool is_learn>
void predict_or_learn(void* d, learner& base, example* ec) {
if (is_learn)
base.learn(ec);
else
base.predict(ec);
if ( ec->final_prediction > 0)
ec->final_prediction = 1;
else
ec->final_prediction = -1;
label_data* ld = (label_data*)ec->ld;//New loss
if (ld->label == ec->final_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<void, predict_or_learn<true> >();
ret->set_predict<void, predict_or_learn<false> >();
return ret;
}
}
|