OTB  7.2.0
Orfeo Toolbox
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue > Class Template Referenceabstract

#include <otbMachineLearningModel.h>

+ Inheritance diagram for otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >:
+ Collaboration diagram for otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >:

Public Types

Standard ITK typedefs
typedef MachineLearningModel Self
 
typedef itk::Object Superclass
 
typedef itk::SmartPointer< SelfPointer
 
typedef itk::SmartPointer< const SelfConstPointer
 
Input related typedefs
typedef MLMSampleTraits< TInputValue >::ValueType InputValueType
 
typedef MLMSampleTraits< TInputValue >::SampleType InputSampleType
 
typedef itk::Statistics::ListSample< InputSampleTypeInputListSampleType
 
Target related typedefs
typedef MLMTargetTraits< TTargetValue >::ValueType TargetValueType
 
typedef MLMTargetTraits< TTargetValue >::SampleType TargetSampleType
 
typedef itk::Statistics::ListSample< TargetSampleTypeTargetListSampleType
 
Confidence value typedef
typedef MLMTargetTraits< TConfidenceValue >::ValueType ConfidenceValueType
 
typedef MLMTargetTraits< TConfidenceValue >::SampleType ConfidenceSampleType
 
typedef itk::Statistics::ListSample< ConfidenceSampleTypeConfidenceListSampleType
 
typedef itk::VariableLengthVector< double > ProbaSampleType
 
typedef itk::Statistics::ListSample< ProbaSampleTypeProbaListSampleType
 

Public Member Functions

bool HasConfidenceIndex () const
 
bool HasProbaIndex () const
 
 itkGetObjectMacro (ConfidenceListSample, ConfidenceListSampleType)
 
TargetSampleType Predict (const InputSampleType &input, ConfidenceValueType *quality=nullptr, ProbaSampleType *proba=nullptr) const
 
TargetListSampleType::Pointer PredictBatch (const InputListSampleType *input, ConfidenceListSampleType *quality=nullptr, ProbaListSampleType *proba=nullptr) const
 
virtual void Train ()=0
 
Standard macros
virtual const char * GetNameOfClass () const
 
Set and get the dimension of the model for dimensionality reduction models
virtual void SetDimension (unsigned int _arg)
 
virtual unsigned int GetDimension ()
 
Classification model file manipulation
virtual void Save (const std::string &filename, const std::string &name="")=0
 
virtual void Load (const std::string &filename, const std::string &name="")=0
 
Classification model file compatibility tests
virtual bool CanReadFile (const std::string &)=0
 
virtual bool CanWriteFile (const std::string &)=0
 
Input list of samples accessors
virtual void SetInputListSample (InputListSampleType *_arg)
 
 itkGetObjectMacro (InputListSample, InputListSampleType)
 
virtual const InputListSampleTypeGetInputListSample () const
 
Classification output accessors
virtual void SetTargetListSample (TargetListSampleType *_arg)
 
 itkGetObjectMacro (TargetListSample, TargetListSampleType)
 
Use model in regression mode
virtual bool GetRegressionMode ()
 
void SetRegressionMode (bool flag)
 

Protected Member Functions

 MachineLearningModel ()
 
void PrintSelf (std::ostream &os, itk::Indent indent) const override
 
 ~MachineLearningModel () override=default
 

Protected Attributes

bool m_ConfidenceIndex
 
ConfidenceListSampleType::Pointer m_ConfidenceListSample
 
unsigned int m_Dimension
 
InputListSampleType::Pointer m_InputListSample
 
bool m_IsDoPredictBatchMultiThreaded
 
bool m_IsRegressionSupported
 
bool m_ProbaIndex
 
bool m_RegressionMode
 
TargetListSampleType::Pointer m_TargetListSample
 
InputListSampleType::Pointer m_ValidationListSample
 

Private Member Functions

virtual TargetSampleType DoPredict (const InputSampleType &input, ConfidenceValueType *quality=nullptr, ProbaSampleType *proba=nullptr) const =0
 
virtual void DoPredictBatch (const InputListSampleType *input, const unsigned int &startIndex, const unsigned int &size, TargetListSampleType *target, ConfidenceListSampleType *quality=nullptr, ProbaListSampleType *proba=nullptr) const
 
 MachineLearningModel (const Self &)=delete
 
void operator= (const Self &)=delete
 

Detailed Description

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
class otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >

MachineLearningModel is the base class for all classifier objects (SVM, KNN, Random Forests, Artificial Neural Network, ...) implemented in the supervised classification framework of the OTB.

MachineLearningModel is an abstract object that specifies behavior and interface of supervised classifiers (SVM, KNN, Random Forests, Artificial Neural Network, ...) in the generic supervised classification framework of the OTB. The main generic virtual methods specifically implemented in each classifier derived from the MachineLearningModel class are two learning-related methods: Train() and Save(), and three classification-related methods: Load(), DoPredict() and optionally DoPredictBatch().

Thus, each classifier derived from the MachineLearningModel class computes its corresponding model with Train() and exports it with the help of the Save() method.

It is also possible to classify any input sample composed of several features (or any number of bands in the case of a pixel extracted from a multi-band image) with the help of the Predict() method which needs a previous loading of the classification model with the Load() method.

See also
MachineLearningModelFactory
LibSVMMachineLearningModel
SVMMachineLearningModel
BoostMachineLearningModel
KNearestNeighborsMachineLearningModel
DecisionTreeMachineLearningModel
RandomForestsMachineLearningModel
NormalBayesMachineLearningModel
NeuralNetworkMachineLearningModel
SharkRandomForestsMachineLearningModel
SharkKMeansMachineLearningModel
ImageClassificationFilter

Definition at line 70 of file otbMachineLearningModel.h.

Member Typedef Documentation

◆ ConfidenceListSampleType

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
typedef itk::Statistics::ListSample<ConfidenceSampleType> otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::ConfidenceListSampleType

Definition at line 98 of file otbMachineLearningModel.h.

◆ ConfidenceSampleType

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
typedef MLMTargetTraits<TConfidenceValue>::SampleType otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::ConfidenceSampleType

Definition at line 97 of file otbMachineLearningModel.h.

◆ ConfidenceValueType

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
typedef MLMTargetTraits<TConfidenceValue>::ValueType otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::ConfidenceValueType

Definition at line 96 of file otbMachineLearningModel.h.

◆ ConstPointer

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
typedef itk::SmartPointer<const Self> otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::ConstPointer

Definition at line 78 of file otbMachineLearningModel.h.

◆ InputListSampleType

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
typedef itk::Statistics::ListSample<InputSampleType> otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::InputListSampleType

Definition at line 85 of file otbMachineLearningModel.h.

◆ InputSampleType

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
typedef MLMSampleTraits<TInputValue>::SampleType otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::InputSampleType

Definition at line 84 of file otbMachineLearningModel.h.

◆ InputValueType

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
typedef MLMSampleTraits<TInputValue>::ValueType otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::InputValueType

Definition at line 83 of file otbMachineLearningModel.h.

◆ Pointer

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
typedef itk::SmartPointer<Self> otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::Pointer

Definition at line 77 of file otbMachineLearningModel.h.

◆ ProbaListSampleType

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
typedef itk::Statistics::ListSample<ProbaSampleType> otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::ProbaListSampleType

Definition at line 102 of file otbMachineLearningModel.h.

◆ ProbaSampleType

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
typedef itk::VariableLengthVector<double> otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::ProbaSampleType

Definition at line 101 of file otbMachineLearningModel.h.

◆ Self

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
typedef MachineLearningModel otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::Self

Definition at line 75 of file otbMachineLearningModel.h.

◆ Superclass

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
typedef itk::Object otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::Superclass

Definition at line 76 of file otbMachineLearningModel.h.

◆ TargetListSampleType

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
typedef itk::Statistics::ListSample<TargetSampleType> otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::TargetListSampleType

Definition at line 92 of file otbMachineLearningModel.h.

◆ TargetSampleType

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
typedef MLMTargetTraits<TTargetValue>::SampleType otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::TargetSampleType

Definition at line 91 of file otbMachineLearningModel.h.

◆ TargetValueType

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
typedef MLMTargetTraits<TTargetValue>::ValueType otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::TargetValueType

Definition at line 90 of file otbMachineLearningModel.h.

Constructor & Destructor Documentation

◆ MachineLearningModel() [1/2]

template<class TInputValue , class TOutputValue , class TConfidenceValue >
otb::MachineLearningModel< TInputValue, TOutputValue, TConfidenceValue >::MachineLearningModel ( )
protected

Constructor

Definition at line 36 of file otbMachineLearningModel.hxx.

◆ ~MachineLearningModel()

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::~MachineLearningModel ( )
overrideprotecteddefault

Destructor

◆ MachineLearningModel() [2/2]

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::MachineLearningModel ( const Self )
privatedelete

Member Function Documentation

◆ CanReadFile()

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual bool otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::CanReadFile ( const std::string &  )
pure virtual

◆ CanWriteFile()

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual bool otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::CanWriteFile ( const std::string &  )
pure virtual

◆ DoPredict()

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual TargetSampleType otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::DoPredict ( const InputSampleType input,
ConfidenceValueType quality = nullptr,
ProbaSampleType proba = nullptr 
) const
privatepure virtual

Actual implementation of single sample prediction

Parameters
inputsample to predict
qualityPointer to a variable to store confidence value, or NULL
Returns
The predicted label

◆ DoPredictBatch()

template<class TInputValue , class TOutputValue , class TConfidenceValue >
void otb::MachineLearningModel< TInputValue, TOutputValue, TConfidenceValue >::DoPredictBatch ( const InputListSampleType input,
const unsigned int &  startIndex,
const unsigned int &  size,
TargetListSampleType target,
ConfidenceListSampleType quality = nullptr,
ProbaListSampleType proba = nullptr 
) const
privatevirtual

Actual implementation of BatchPredicition Default implementation will call DoPredict iteratively

Parameters
inputThe input batch
startIndexIndex of the first sample to predict
sizeNumber of samples to predict
targetPointer to the list of produced labels
qualityPointer to the list of produced confidence values, or NULL

Override me if internal implementation allows for batch prediction.

Also set m_IsDoPredictBatchMultiThreaded to true if internal implementation allows for parallel batch prediction.

Definition at line 130 of file otbMachineLearningModel.hxx.

◆ GetDimension()

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual unsigned int otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::GetDimension ( )
virtual

◆ GetInputListSample()

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual const InputListSampleType* otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::GetInputListSample ( ) const
virtual

◆ GetNameOfClass()

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual const char* otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::GetNameOfClass ( ) const
virtual

◆ GetRegressionMode()

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual bool otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::GetRegressionMode ( )
virtual

◆ HasConfidenceIndex()

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
bool otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::HasConfidenceIndex ( ) const
inline

Query capacity to produce a confidence index

Definition at line 160 of file otbMachineLearningModel.h.

◆ HasProbaIndex()

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
bool otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::HasProbaIndex ( ) const
inline

Query capacity to produce probability values

Definition at line 166 of file otbMachineLearningModel.h.

◆ itkGetObjectMacro() [1/3]

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::itkGetObjectMacro ( InputListSample  ,
InputListSampleType   
)

◆ itkGetObjectMacro() [2/3]

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::itkGetObjectMacro ( TargetListSample  ,
TargetListSampleType   
)

Get the target labels

◆ itkGetObjectMacro() [3/3]

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::itkGetObjectMacro ( ConfidenceListSample  ,
ConfidenceListSampleType   
)

◆ Load()

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual void otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::Load ( const std::string &  filename,
const std::string &  name = "" 
)
pure virtual

◆ operator=()

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
void otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::operator= ( const Self )
privatedelete

◆ Predict()

template<class TInputValue , class TOutputValue , class TConfidenceValue >
MachineLearningModel< TInputValue, TOutputValue, TConfidenceValue >::TargetSampleType otb::MachineLearningModel< TInputValue, TOutputValue, TConfidenceValue >::Predict ( const InputSampleType input,
ConfidenceValueType quality = nullptr,
ProbaSampleType proba = nullptr 
) const

Predict a single sample

Parameters
inputThe sample
qualityA pointer to the quality variable were to store quality value, or NULL
Returns
The predicted label

Definition at line 62 of file otbMachineLearningModel.hxx.

◆ PredictBatch()

template<class TInputValue , class TOutputValue , class TConfidenceValue >
MachineLearningModel< TInputValue, TOutputValue, TConfidenceValue >::TargetListSampleType::Pointer otb::MachineLearningModel< TInputValue, TOutputValue, TConfidenceValue >::PredictBatch ( const InputListSampleType input,
ConfidenceListSampleType quality = nullptr,
ProbaListSampleType proba = nullptr 
) const

Predict a batch of samples (InputListSampleType)

Parameters
inputThe batch of sample to predict
qualityA pointer to the list were to store quality value, or NULL
Returns
The predicted labels Note that this method will be multi-threaded if OTB is built with OpenMP.

Definition at line 72 of file otbMachineLearningModel.hxx.

◆ PrintSelf()

template<class TInputValue , class TOutputValue , class TConfidenceValue >
void otb::MachineLearningModel< TInputValue, TOutputValue, TConfidenceValue >::PrintSelf ( std::ostream &  os,
itk::Indent  indent 
) const
overrideprotected

PrintSelf method

Definition at line 181 of file otbMachineLearningModel.hxx.

◆ Save()

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual void otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::Save ( const std::string &  filename,
const std::string &  name = "" 
)
pure virtual

◆ SetDimension()

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual void otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::SetDimension ( unsigned int  _arg)
virtual

◆ SetInputListSample()

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual void otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::SetInputListSample ( InputListSampleType _arg)
virtual

◆ SetRegressionMode()

template<class TInputValue , class TOutputValue , class TConfidenceValue >
void otb::MachineLearningModel< TInputValue, TOutputValue, TConfidenceValue >::SetRegressionMode ( bool  flag)

Definition at line 47 of file otbMachineLearningModel.hxx.

◆ SetTargetListSample()

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual void otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::SetTargetListSample ( TargetListSampleType _arg)
virtual

Set the target labels (to be used before training)

◆ Train()

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual void otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::Train ( )
pure virtual

Member Data Documentation

◆ m_ConfidenceIndex

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
bool otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::m_ConfidenceIndex
protected

flag that tells if the model support confidence index output

Definition at line 228 of file otbMachineLearningModel.h.

◆ m_ConfidenceListSample

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
ConfidenceListSampleType::Pointer otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::m_ConfidenceListSample
protected

Definition at line 217 of file otbMachineLearningModel.h.

◆ m_Dimension

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
unsigned int otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::m_Dimension
protected

Output Dimension of the model, used by Dimensionality Reduction models

Definition at line 237 of file otbMachineLearningModel.h.

◆ m_InputListSample

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
InputListSampleType::Pointer otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::m_InputListSample
protected

Input list sample

Definition at line 209 of file otbMachineLearningModel.h.

◆ m_IsDoPredictBatchMultiThreaded

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
bool otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::m_IsDoPredictBatchMultiThreaded
protected

Is DoPredictBatch multi-threaded ?

Definition at line 234 of file otbMachineLearningModel.h.

◆ m_IsRegressionSupported

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
bool otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::m_IsRegressionSupported
protected

flag that indicates if the model supports regression, child classes should modify it in their constructor if they support regression mode

Definition at line 225 of file otbMachineLearningModel.h.

◆ m_ProbaIndex

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
bool otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::m_ProbaIndex
protected

flag that tells if the model support probability output

Definition at line 231 of file otbMachineLearningModel.h.

◆ m_RegressionMode

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
bool otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::m_RegressionMode
protected

flag to choose between classification and regression modes

Definition at line 220 of file otbMachineLearningModel.h.

◆ m_TargetListSample

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
TargetListSampleType::Pointer otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::m_TargetListSample
protected

Target list sample

Definition at line 215 of file otbMachineLearningModel.h.

◆ m_ValidationListSample

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
InputListSampleType::Pointer otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::m_ValidationListSample
protected

Validation list sample if provided for some models

Definition at line 212 of file otbMachineLearningModel.h.


The documentation for this class was generated from the following files: