21 #ifndef otbLibSVMMachineLearningModel_h
22 #define otbLibSVMMachineLearningModel_h
24 #include "itkLightObject.h"
25 #include "itkFixedArray.h"
32 template <
class TInputValue,
class TTargetValue>
59 typedef enum { CM_INDEX, CM_PROBA, CM_HYPER } ConfidenceMode;
67 void Train()
override;
70 void Save(
const std::string& filename,
const std::string& name =
"")
override;
73 void Load(
const std::string& filename,
const std::string& name =
"")
override;
79 bool CanReadFile(
const std::string&)
override;
82 bool CanWriteFile(
const std::string&)
override;
85 #define otbSetSVMParameterMacro(name, alias, type) \
86 void Set##name(const type _arg) \
88 itkDebugMacro("setting " #name " to " << _arg); \
89 if (this->m_Parameters.alias != _arg) \
91 this->m_Parameters.alias = _arg; \
102 return m_Parameters.svm_type;
115 return m_Parameters.kernel_type;
124 return m_Parameters.degree;
133 return m_Parameters.gamma;
142 return m_Parameters.coef0;
151 return m_Parameters.C;
154 itkSetMacro(ParameterOptimization,
bool);
155 itkGetMacro(ParameterOptimization,
bool);
160 m_Parameters.probability =
static_cast<int>(prob);
166 return static_cast<bool>(m_Parameters.probability);
170 bool HasProbabilities(
void)
const;
178 return m_Parameters.eps;
187 return m_Parameters.p;
196 return m_Parameters.nu;
199 #undef otbSetSVMParameterMacro
204 m_Parameters.shrinking =
static_cast<int>(s);
212 return static_cast<bool>(m_Parameters.shrinking);
218 m_Parameters.cache_size =
static_cast<double>(cSize);
226 return static_cast<int>(m_Parameters.cache_size);
229 itkSetMacro(CVFolders,
unsigned int);
230 itkGetMacro(CVFolders,
unsigned int);
232 itkGetMacro(InitialCrossValidationAccuracy,
double);
234 itkGetMacro(FinalCrossValidationAccuracy,
double);
236 itkSetMacro(CoarseOptimizationNumberOfSteps,
unsigned int);
237 itkGetMacro(CoarseOptimizationNumberOfSteps,
unsigned int);
239 itkSetMacro(FineOptimizationNumberOfSteps,
unsigned int);
240 itkGetMacro(FineOptimizationNumberOfSteps,
unsigned int);
247 this->m_ConfidenceIndex = this->HasProbabilities();
253 unsigned int GetNumberOfKernelParameters();
255 double CrossValidation(
void);
269 return m_Model->nr_class;
281 TargetSampleType DoPredict(
const InputSampleType& input, ConfidenceValueType* quality =
nullptr, ProbaSampleType* proba =
nullptr)
const override;
284 void PrintSelf(std::ostream& os, itk::Indent indent)
const override;
290 void BuildProblem(
void);
292 void ConsistencyCheck(
void);
294 void DeleteProblem(
void);
296 void DeleteModel(
void);
298 void OptimizeParameters(
void);
304 struct svm_problem m_Problem;
307 struct svm_parameter m_Parameters;
335 #ifndef OTB_MANUAL_INSTANTIATION
otbSetSVMParameterMacro(P, p, double)
int GetKernelType(void) const
bool GetDoShrinking(void) const
double GetKernelCoef0(void) const
std::vector< double > m_TmpTarget
double GetEpsilon(void) const
otbSetSVMParameterMacro(KernelGamma, gamma, double)
otbSetSVMParameterMacro(PolynomialKernelDegree, degree, int)
otbSetSVMParameterMacro(SVMType, svm_type, int)
otbSetSVMParameterMacro(C, C, double)
Superclass::InputSampleType InputSampleType
Superclass::InputValueType InputValueType
unsigned int m_CoarseOptimizationNumberOfSteps
otbSetSVMParameterMacro(Epsilon, eps, double)
itk::SmartPointer< const Self > ConstPointer
Superclass::InputListSampleType InputListSampleType
Superclass::TargetListSampleType TargetListSampleType
void operator=(const Self &)=delete
MachineLearningModel< TInputValue, TTargetValue > Superclass
itk::SmartPointer< Self > Pointer
Superclass::TargetSampleType TargetSampleType
int GetSVMType(void) const
int GetPolynomialKernelDegree(void) const
double GetKernelGamma(void) const
LibSVMMachineLearningModel Self
otbSetSVMParameterMacro(KernelCoef0, coef0, double)
LibSVMMachineLearningModel(const Self &)=delete
otbSetSVMParameterMacro(Nu, nu, double)
Superclass::TargetValueType TargetValueType
struct svm_model * m_Model
Superclass::ProbaSampleType ProbaSampleType
Superclass::ConfidenceValueType ConfidenceValueType
ConfidenceMode m_ConfidenceMode
unsigned int GetNumberOfClasses(void) const
double m_InitialCrossValidationAccuracy
double m_FinalCrossValidationAccuracy
void SetDoProbabilityEstimates(bool prob)
void SetCacheSize(int cSize)
void SetConfidenceMode(unsigned int mode)
otbSetSVMParameterMacro(KernelType, kernel_type, int)
int GetCacheSize(void) const
bool GetDoProbabilityEstimates(void) const
bool m_ParameterOptimization
unsigned int m_FineOptimizationNumberOfSteps
unsigned int GetNumberOfSupportVectors(void) const
MachineLearningModel is the base class for all classifier objects (SVM, KNN, Random Forests,...
MLMTargetTraits< TTargetValue >::SampleType TargetSampleType
OpenCV implementation of SVM algorithm.
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.