-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwinnow.cpp
More file actions
27 lines (26 loc) · 796 Bytes
/
Copy pathwinnow.cpp
File metadata and controls
27 lines (26 loc) · 796 Bytes
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
#include "winnow.h"
namespace TDatastream {
///////////////////////////////
// Winnow
void TWinnow::Process(const TIntV& Example) {
const bool Label = Example.Last() == 1;
const bool Pred = Dot(WeightV, Example) > Treshold;
if (Label != Pred) {
const double Factor = Label ? Alpha : 1/Alpha;
for (int ElN = 0; ElN < WeightV.Len(); ++ElN) {
if (Example[ElN]) WeightV[ElN] *= Factor;
}
}
}
int TWinnow::Classify(const TIntV& Example) {
return Dot(WeightV, Example) > Treshold;
}
double TWinnow::Dot(const TFltV& WeightV, const TIntV& BoolV) {
EAssert(WeightV.Len() == BoolV.Len()-1); // last BoolV is class label
double Val = 0;
for (int ElN = 0; ElN < WeightV.Len(); ++ElN) {
Val += WeightV[ElN]*BoolV[ElN];
}
return Val;
}
} // namespace TDatastream