18 #ifndef __otbSVMKernels_h
19 #define __otbSVMKernels_h
25 #include "itkNumericTraits.h"
56 return new Self(*
this);
61 return (
dot(x, x) - 2.0 *
dot(x, y) +
dot(y, y));
89 this->
SetName(
"invMultiQuadric");
90 this->SetValue<double>(
"const_coef", 1);
97 return new Self(*
this);
102 double mq = this->GetValue<double>(
"const_coef") +
m_Custom(x, y, param);
105 return itk::NumericTraits<double>::max();
107 return 1.0 / sqrt(mq);
139 this->SetValue<double>(
"const_coef", 1);
145 double mq = this->GetValue<double>(
"const_coef") +
m_Custom(x, y, param);
149 return itk::NumericTraits<double>::max();
151 return exp(param.
gamma / mq) - 1.0;
157 return new Self(*
this);
194 double den =
dot(x, x) *
dot(y, y);
199 double ss =
dot(x, y);
200 return vcl_acos(ss / vcl_sqrt(den));
206 return new Self(*
this);
240 return vcl_exp(-param.
gamma *
m_Sam(x, y, param));
246 return new Self(*
this);
277 this->
SetName(
"InverseCosSAM");
283 return 1.0 - vcl_cos(
m_Sam(x, y, param));
289 return new Self(*
this);
320 this->
SetName(
"invMultiQuadraticSAM");
321 this->SetValue<double>(
"const_coef", 1);
328 return new Self(*
this);
333 double mq = this->GetValue<double>(
"const_coef") +
m_Sam(x, y, param);
337 return itk::NumericTraits<double>::max();
339 return 1. / sqrt(mq);
371 this->SetValue<double>(
"const_coef", 1);
378 return new Self(*
this);
383 double mq = this->GetValue<double>(
"const_coef") +
m_Sam(x, y, param);
387 return itk::NumericTraits<double>::max();
389 return vcl_exp(param.
gamma / mq) - 1.0;
421 this->SetValue<double>(
"gamma_coef", 0.5);
428 return new Self(*
this);
433 double res = this->GetValue<double>(
"gamma_coef") *
m_Custom(x, y, param);
434 return vcl_exp(-res);
443 double constValue)
const
445 double gamma = this->GetValue<double>(
"gamma_coef");
446 double kernelValue = 0.;
455 while (xtemp->
index != -1 && ytemp->
index != -1 && stop ==
false)
485 kernelValue = constValue;
498 return (-2 * gamma * (yval - xval) * kernelValue);
503 this->
derivative(x, y, param, degree - 2, index, isAtEnd, constValue) +
504 (yval - xval) *
derivative(x, y, param, degree - 1, index, isAtEnd, constValue)));
539 this->SetValue<double>(
"lin_coef", 1.);
546 return new Self(*
this);
551 return (this->GetValue<double>(
"lin_coef") * vcl_exp(-param.
gamma *
m_Custom(x, y, param))
552 + (1.0 - this->GetValue<double>(
"lin_coef")) *
m_RadialSam(x, y, param));
585 this->SetValue<double>(
"const_coef", 1);
586 this->SetValue<double>(
"lin_coef", 1);
593 return new Self(*
this);
598 return this->GetValue<double>(
"const_lin") * vcl_pow(
dot(x, y) + this->GetValue<double>(
"const_coef"), param.
degree)
599 + (1.0 - this->GetValue<double>(
"const_coef"))
638 return new Self(*
this);
696 return new Self(*
this);
707 return (vcl_exp(value));
745 return new Self(*
this);
750 const char * parameters = param.
custom;
751 const char * twoPoints =
":";
752 const char * position = strpbrk (parameters, twoPoints);
753 int twoPointsPosition = 0;
756 int numberOfGroups = atoi(parameters);
758 twoPointsPosition = position - parameters;
760 parameters = parameters + twoPointsPosition + 1;
763 std::vector<int> begin;
764 begin.resize(numberOfGroups);
765 std::vector<int> end;
766 end.resize(numberOfGroups);
768 for (i = 0; i < numberOfGroups; ++i)
770 begin[i] = atoi(parameters);
771 position = strpbrk (parameters, twoPoints);
772 twoPointsPosition = position - parameters;
773 parameters = parameters + twoPointsPosition + 1;
775 end[i] = atoi(parameters);
776 parameters = parameters + twoPointsPosition + 1;
785 while (xBuff->
index != 1)
791 while (yBuff->
index != 1)
806 for (j = 0; j < numberOfGroups; ++j)
812 while (xTemp->
index != 1 && yTemp->
index != 1)
816 if ((xTemp->
index < begin[j]) || (xTemp->
index > end[j]))
818 xGroup[index].
value = 0;
819 yGroup[index].
value = 0;
840 else if ((sizeX > 0) && (sizeY == 0))
845 for (j = 0; j < numberOfGroups; ++j)
850 while (xTemp->
index != -1)
855 if ((xTemp->
index < begin[j]) || (xTemp->
index > end[j]))
857 xGroup[index].
value = 0;
858 yGroup[index].
value = 0;
863 yGroup[index].
value = 0;
880 total =
static_cast<double>(numberOfGroups) *
m_CustomLinear(x, y, param);
883 if (xTemp !=
NULL)
delete xTemp;
884 if (yTemp !=
NULL)
delete yTemp;
917 this->
SetName(
"groupingAdaptive");
918 this->SetValue<double>(
"lin_coef", 1.);
919 this->SetValue<double>(
"const_coef", 1.);
926 return new Self(*
this);
931 const char * parameters = param.
custom;
932 const char * twoPoints =
":";
933 const char * position = strpbrk (parameters, twoPoints);
934 int twoPointsPosition = 0;
937 int numberOfGroups = atoi(parameters);
939 twoPointsPosition = position - parameters;
941 parameters = parameters + twoPointsPosition + 1;
945 std::vector<int> begin;
946 begin.resize(numberOfGroups);
947 std::vector<int> end;
948 end.resize(numberOfGroups);
950 for (i = 0; i < numberOfGroups; ++i)
952 begin[i] = atoi(parameters);
953 position = strpbrk (parameters, twoPoints);
954 twoPointsPosition = position - parameters;
955 parameters = parameters + twoPointsPosition + 1;
957 end[i] = atoi(parameters);
958 parameters = parameters + twoPointsPosition + 1;
967 while (xBuff->
index != 1)
973 while (yBuff->
index != 1)
989 for (j = 0; j < numberOfGroups; ++j)
995 while (xTemp->
index != 1 && yTemp->
index != 1)
999 if ((xTemp->
index < begin[j]) || (xTemp->
index > end[j]))
1001 xGroup[index].
value = 0;
1002 yGroup[index].
value = 0;
1015 value = vcl_pow(this->GetValue<double>(
"lin_coef") *
dot(xGroup, yGroup) + this->GetValue<double>(
1016 "const_coef"), static_cast<double>(param.
degree));
1024 else if ((sizeX > 0) && (sizeY == 0))
1029 for (j = 0; j < numberOfGroups; ++j)
1034 while (xTemp->
index != 1)
1039 if ((xTemp->
index < begin[j]) || (xTemp->
index > end[j]))
1041 xGroup[index].
value = 0;
1042 yGroup[index].
value = 0;
1047 yGroup[index].
value = 0;
1054 value = vcl_pow(this->GetValue<double>(
"lin_coef") *
dot(xGroup, yGroup) + this->GetValue<double>(
1055 "const_coef"), static_cast<double>(param.
degree));
1066 total =
static_cast<double>(numberOfGroups) * custom(x, y, param);