37 #ifndef SHARK_ALGORITHMS_EPSILONSVMTRAINER_H 38 #define SHARK_ALGORITHMS_EPSILONSVMTRAINER_H 78 template <
class InputType,
class CacheType =
float>
100 : base_type(kernel, C, true, unconstrained)
106 {
return "EpsilonSvmTrainer"; }
109 {
return m_epsilon; }
137 trainSVM<PrecomputedBlockMatrixType>(svm,dataset);
139 trainSVM<CachedBlockMatrixType>(svm,dataset);
145 template<
class MatrixType>
152 std::size_t ic = km.size();
153 BlockMatrixType blockkm(&km);
155 SVMProblemType svmProblem(matrix);
156 for(std::size_t i = 0; i != ic; ++i){
157 svmProblem.linear(i) = dataset.
element(i).label(0) - m_epsilon;
158 svmProblem.linear(i+ic) = dataset.
element(i).label(0) + m_epsilon;
159 svmProblem.boxMin(i) = 0;
160 svmProblem.boxMax(i) = this->
C();
161 svmProblem.boxMin(i+ic) = -this->
C();
162 svmProblem.boxMax(i+ic) = 0;
169 RealVector alpha = problem.getUnpermutedAlpha();
170 column(svm.
alpha(),0)= subrange(alpha,0,ic)+subrange(alpha,ic,2*ic);
173 double lowerBound = -1e100;
174 double upperBound = 1e100;
177 std::size_t freeVars = 0;
178 for (std::size_t i=0; i< ic; i++)
180 if (problem.alpha(i) > 0.0)
182 double value = problem.gradient(i);
183 if (problem.alpha(i) < this->
C())
190 lowerBound = std::max(value,lowerBound);
193 if (problem.alpha(i + ic) < 0.0)
195 double value = problem.gradient(i + ic);
196 if (problem.alpha(i + ic) > -this->
C())
203 upperBound = std::min(value,upperBound);
208 svm.
offset(0) = sum / freeVars;
210 svm.
offset(0) = 0.5 * (lowerBound + upperBound);