21 #ifndef otbSVMCrossValidationCostFunction_hxx
22 #define otbSVMCrossValidationCostFunction_hxx
29 template <
class TModel>
33 template <
class TModel>
37 template <
class TModel>
43 itkExceptionMacro(<<
"Model is null, can not evaluate accuracy.");
47 if (parameters[0] <= 0)
53 this->UpdateParameters(parameters);
55 return m_Model->CrossValidation();
58 template <
class TModel>
62 derivative.SetSize(parameters.Size());
63 derivative.Fill(itk::NumericTraits<ParametersValueType>::Zero);
65 for (
unsigned int i = 0; i < parameters.Size(); ++i)
71 x1[i] -= m_DerivativeStep;
72 y1 = this->GetValue(x1);
75 x2[i] += m_DerivativeStep;
76 y2 = this->GetValue(x2);
78 derivative[i] = (y2 - y1) / (2 * m_DerivativeStep);
79 otbMsgDevMacro(<<
"x1= " << x1 <<
" x2= " << x2 <<
", y1= " << y1 <<
", y2= " << y2);
81 otbMsgDevMacro(
"Position: " << parameters <<
", Value: " << this->GetValue(parameters) <<
", Derivatives: " << derivative);
84 template <
class TModel>
89 itkExceptionMacro(<<
"Model is null, can not evaluate number of parameters.");
91 return m_Model->GetNumberOfKernelParameters();
94 template <
class TModel>
97 unsigned int nbParams = m_Model->GetNumberOfKernelParameters();
98 m_Model->SetC(parameters[0]);
100 m_Model->SetKernelGamma(parameters[1]);
102 m_Model->SetKernelCoef0(parameters[2]);