107 {
return "EpsilonSvmTrainer"; }
110 {
return m_epsilon; }
138 trainSVM<PrecomputedBlockMatrixType>(svm,dataset);
140 trainSVM<CachedBlockMatrixType>(svm,dataset);
146 template<
class MatrixType>
153 std::size_t ic = km.size();
156 SVMProblemType svmProblem(matrix);
157 for(std::size_t i = 0; i != ic; ++i){
158 svmProblem.linear(i) = dataset.
element(i).label(0) - m_epsilon;
159 svmProblem.linear(i+ic) = dataset.
element(i).label(0) + m_epsilon;
160 svmProblem.boxMin(i) = 0;
161 svmProblem.boxMax(i) = this->
C();
162 svmProblem.boxMin(i+ic) = -this->
C();
163 svmProblem.boxMax(i+ic) = 0;
168 QpSolver< ProblemType> solver(problem);
170 RealVector alpha = problem.getUnpermutedAlpha();
171 column(svm.
alpha(),0)= subrange(alpha,0,ic)+subrange(alpha,ic,2*ic);
174 double lowerBound = -1e100;
175 double upperBound = 1e100;
178 std::size_t freeVars = 0;
179 for (std::size_t i=0; i< ic; i++)
181 if (problem.alpha(i) > 0.0)
183 double value = problem.gradient(i);
184 if (problem.alpha(i) < this->C())
191 lowerBound = std::max(value,lowerBound);
194 if (problem.alpha(i + ic) < 0.0)
196 double value = problem.gradient(i + ic);
197 if (problem.alpha(i + ic) > -this->C())
204 upperBound = std::min(value,upperBound);
209 svm.
offset(0) = sum / freeVars;
211 svm.
offset(0) = 0.5 * (lowerBound + upperBound);