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();
251 itkGetMacro(ConfidenceMode,
unsigned int);
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;
288 void operator=(
const Self&) =
delete;
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