15 KernelLogisticRegressor::KernelLogisticRegressor
17 const std::vector<int>& labels) :
18 trainSet_(data), labels_(labels)
26 KernelLogisticRegressor::KernelLogisticRegressor
28 const GMatrix& gramMatrix,
29 const std::vector<int>& labels) :
30 trainSet_(data), gramMatrix_(gramMatrix), labels_(labels)
39 const std::vector<int>& labels)
44 vklr_ = boost::optional<GMatrix>();
47 void KernelLogisticRegressor::computeGramMatrix()
50 gramMatrix_ = GMatrix(trainSet_.
size(), trainSet_.
size());
52 for (
unsigned i = 0; i < trainSet_.
size(); ++i)
54 for (
unsigned j = 0; j < trainSet_.
size(); ++j)
56 gramMatrix_(i, j) = trainSet_.
at(i).polyEval(trainSet_.
at(j));
63 const unsigned itrNewton)
72 klr_train(gramMatrix_, gramMatrix_.GetRows(), gramMatrix_.GetColumns(),
73 &labels_.front(), labels_.size(),
77 vklr_ =
vklr.Transpose();
88 GMatrix Ktest(trainSet_.
size(), 1);
89 for (
unsigned i = 0; i < trainSet_.
size(); ++i)
91 Ktest(i, 0) = trainSet_.
at(i).polyEval(t);
94 GMatrix f = *vklr_ * Ktest;
95 double m = std::max(f(0,0), f(1,0));
97 double e1 = std::exp(f(0,0)-m), e2 = std::exp(f(1,0)-m);
108 NUKLEI_TRACE_BEGIN();
110 GMatrix pr(2, testSet.
size());
113 ti != testSet.
end(); ++ti)
115 Vector2 p =
test(*ti);
116 pr(0,std::distance(testSet.
begin(), ti)) = p.X();
117 pr(1,std::distance(testSet.
begin(), ti)) = p.Y();