37 #ifndef SHARK_ALGORITHMS_ONECLASSSVMTRAINER_H 38 #define SHARK_ALGORITHMS_ONECLASSSVMTRAINER_H 83 template <
class InputType,
class CacheType =
float>
105 {
return "OneClassSvmTrainer"; }
126 RealVector ret(kp + 1);
137 setNu(newParameters(kp));
151 trainSVM<PrecomputedMatrixType>(svm,inputset);
153 trainSVM<CachedMatrixType>(svm,inputset);
164 template<
class MatrixType>
171 KernelMatrixType km(*m_kernel, inputset);
173 std::size_t ic = matrix.size();
174 double upper = 1.0/(m_nu*ic);
175 SVMProblemType svmProblem(matrix,blas::repeat(0.0,ic),0.0,upper);
181 column(svm.
alpha(),0)= problem.getUnpermutedAlpha();
184 double lowerBound = -1e100;
185 double upperBound = 1e100;
187 std::size_t freeVars = 0;
188 for (std::size_t i=0; i != problem.dimensions(); i++)
190 double value = problem.gradient(i);
191 if (problem.alpha(i) == 0.0)
192 lowerBound = std::max(value,lowerBound);
193 else if (problem.alpha(i) == upper)
194 upperBound = std::min(value,upperBound);
202 svm.
offset(0) = sum / freeVars;
204 svm.
offset(0) = 0.5 * (lowerBound + upperBound);