OTB  6.1.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 Self
ConstPointer
 
Input related typedefs
typedef TInputValue InputValueType
 
typedef
itk::VariableLengthVector
< InputValueType
InputSampleType
 
typedef
itk::Statistics::ListSample
< InputSampleType
InputListSampleType
 
Target related typedefs
typedef TTargetValue TargetValueType
 
typedef itk::FixedArray
< TargetValueType, 1 > 
TargetSampleType
 
typedef
itk::Statistics::ListSample
< TargetSampleType
TargetListSampleType
 
Confidence value typedef
typedef TConfidenceValue ConfidenceValueType
 
typedef itk::FixedArray
< ConfidenceValueType, 1 > 
ConfidenceSampleType
 
typedef
itk::Statistics::ListSample
< ConfidenceSampleType
ConfidenceListSampleType
 
- Public Types inherited from itk::Object
typedef SmartPointer< const SelfConstPointer
 
typedef SmartPointer< SelfPointer
 
typedef Object Self
 
typedef LightObject Superclass
 
- Public Types inherited from itk::LightObject
typedef SmartPointer< const SelfConstPointer
 
typedef SmartPointer< SelfPointer
 
typedef LightObject Self
 

Public Member Functions

bool HasConfidenceIndex () const
 
 itkGetObjectMacro (ConfidenceListSample, ConfidenceListSampleType)
 
TargetSampleType Predict (const InputSampleType &input, ConfidenceValueType *quality=ITK_NULLPTR) const
 
TargetListSampleType::Pointer PredictBatch (const InputListSampleType *input, ConfidenceListSampleType *quality=ITK_NULLPTR) const
 
virtual void Train ()=0
 
Standard macros
virtual const char * GetNameOfClass () const
 
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)
 
- Public Member Functions inherited from itk::Object
unsigned long AddObserver (const EventObject &event, Command *)
 
unsigned long AddObserver (const EventObject &event, Command *) const
 
virtual LightObject::Pointer CreateAnother () const override
 
virtual void DebugOff () const
 
virtual void DebugOn () const
 
CommandGetCommand (unsigned long tag)
 
bool GetDebug () const
 
const MetaDataDictionaryGetMetaDataDictionary () const
 
MetaDataDictionaryGetMetaDataDictionary ()
 
virtual ModifiedTimeType GetMTime () const
 
virtual const std::string & GetObjectName () const
 
virtual const TimeStampGetTimeStamp () const
 
bool HasObserver (const EventObject &event) const
 
void InvokeEvent (const EventObject &)
 
void InvokeEvent (const EventObject &) const
 
virtual void Modified () const
 
virtual void Register () const override
 
void RemoveAllObservers ()
 
void RemoveObserver (unsigned long tag)
 
void SetDebug (bool debugFlag) const
 
void SetMetaDataDictionary (const MetaDataDictionary &rhs)
 
virtual void SetObjectName (std::string _arg)
 
virtual void SetReferenceCount (int) override
 
virtual void UnRegister () const noexceptoverride
 
- Public Member Functions inherited from itk::LightObject
virtual void Delete ()
 
virtual int GetReferenceCount () const
 
 itkCloneMacro (Self)
 
void Print (std::ostream &os, Indent indent=0) const
 

Protected Member Functions

 MachineLearningModel ()
 
void PrintSelf (std::ostream &os, itk::Indent indent) const ITK_OVERRIDE
 
 ~MachineLearningModel () ITK_OVERRIDE
 
- Protected Member Functions inherited from itk::Object
 Object ()
 
bool PrintObservers (std::ostream &os, Indent indent) const
 
virtual void SetTimeStamp (const TimeStamp &time)
 
virtual ~Object ()
 
- Protected Member Functions inherited from itk::LightObject
virtual LightObject::Pointer InternalClone () const
 
 LightObject ()
 
virtual void PrintHeader (std::ostream &os, Indent indent) const
 
virtual void PrintTrailer (std::ostream &os, Indent indent) const
 
virtual ~LightObject ()
 

Protected Attributes

bool m_ConfidenceIndex
 
ConfidenceListSampleType::Pointer m_ConfidenceListSample
 
InputListSampleType::Pointer m_InputListSample
 
bool m_IsDoPredictBatchMultiThreaded
 
bool m_IsRegressionSupported
 
bool m_RegressionMode
 
TargetListSampleType::Pointer m_TargetListSample
 
- Protected Attributes inherited from itk::LightObject
AtomicInt< int > m_ReferenceCount
 

Private Member Functions

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

Additional Inherited Members

- Static Public Member Functions inherited from itk::Object
static bool GetGlobalWarningDisplay ()
 
static void GlobalWarningDisplayOff ()
 
static void GlobalWarningDisplayOn ()
 
static Pointer New ()
 
static void SetGlobalWarningDisplay (bool flag)
 
- Static Public Member Functions inherited from itk::LightObject
static void BreakOnError ()
 
static Pointer New ()
 

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
GradientBoostedTreeMachineLearningModel
NormalBayesMachineLearningModel
NeuralNetworkMachineLearningModel
SharkRandomForestsMachineLearningModel
SharkKMeansMachineLearningModel
ImageClassificationFilter

Definition at line 70 of file otbMachineLearningModel.h.

Member Typedef Documentation

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

Definition at line 99 of file otbMachineLearningModel.h.

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
typedef itk::FixedArray<ConfidenceValueType,1> otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::ConfidenceSampleType

Definition at line 98 of file otbMachineLearningModel.h.

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

Definition at line 97 of file otbMachineLearningModel.h.

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

Definition at line 79 of file otbMachineLearningModel.h.

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

Definition at line 86 of file otbMachineLearningModel.h.

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

Definition at line 85 of file otbMachineLearningModel.h.

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

Definition at line 84 of file otbMachineLearningModel.h.

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

Definition at line 78 of file otbMachineLearningModel.h.

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

Definition at line 76 of file otbMachineLearningModel.h.

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

Definition at line 77 of file otbMachineLearningModel.h.

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

Definition at line 93 of file otbMachineLearningModel.h.

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
typedef itk::FixedArray<TargetValueType,1> otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::TargetSampleType

Definition at line 92 of file otbMachineLearningModel.h.

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

Definition at line 91 of file otbMachineLearningModel.h.

Constructor & Destructor Documentation

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

Constructor

Definition at line 37 of file otbMachineLearningModel.txx.

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

Destructor

Definition at line 47 of file otbMachineLearningModel.txx.

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

Member Function Documentation

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual bool otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::CanReadFile ( const std::string &  )
pure virtual
template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual bool otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::CanWriteFile ( const std::string &  )
pure virtual
template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual TargetSampleType otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::DoPredict ( const InputSampleType input,
ConfidenceValueType quality = ITK_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
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 = ITK_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 137 of file otbMachineLearningModel.txx.

References itk::Statistics::ListSample< TMeasurementVector >::GetMeasurementVector(), itk::Statistics::ListSample< TMeasurementVector >::SetMeasurementVector(), and itk::Statistics::ListSample< TMeasurementVector >::Size().

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual const InputListSampleType* otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::GetInputListSample ( ) const
virtual
template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual const char* otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::GetNameOfClass ( ) const
virtual
template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual bool otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::GetRegressionMode ( )
virtual
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 152 of file otbMachineLearningModel.h.

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

Get the target labels

template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::itkGetObjectMacro ( ConfidenceListSample  ,
ConfidenceListSampleType   
)
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
template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
void otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::operator= ( const Self )
private
template<class TInputValue , class TOutputValue , class TConfidenceValue >
MachineLearningModel< TInputValue, TOutputValue, TConfidenceValue >::TargetSampleType otb::MachineLearningModel< TInputValue, TOutputValue, TConfidenceValue >::Predict ( const InputSampleType input,
ConfidenceValueType quality = ITK_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 70 of file otbMachineLearningModel.txx.

Referenced by otb::PersistentObjectDetectionClassifier< TInputImage, TOutputVectorData, TLabel, TFunctionType >::ThreadedGenerateData().

template<class TInputValue , class TOutputValue , class TConfidenceValue >
MachineLearningModel< TInputValue, TOutputValue, TConfidenceValue >::TargetListSampleType::Pointer otb::MachineLearningModel< TInputValue, TOutputValue, TConfidenceValue >::PredictBatch ( const InputListSampleType input,
ConfidenceListSampleType quality = ITK_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 81 of file otbMachineLearningModel.txx.

References itk::Statistics::ListSample< TMeasurementVector >::Clear(), itk::Statistics::ListSample< TMeasurementVector >::Resize(), and itk::Statistics::ListSample< TMeasurementVector >::Size().

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

PrintSelf method

Reimplemented from itk::Object.

Definition at line 173 of file otbMachineLearningModel.txx.

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
template<class TInputValue, class TTargetValue, class TConfidenceValue = double>
virtual void otb::MachineLearningModel< TInputValue, TTargetValue, TConfidenceValue >::SetInputListSample ( InputListSampleType _arg)
virtual
template<class TInputValue , class TOutputValue , class TConfidenceValue >
void otb::MachineLearningModel< TInputValue, TOutputValue, TConfidenceValue >::SetRegressionMode ( bool  flag)

Definition at line 53 of file otbMachineLearningModel.txx.

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)

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

Member Data Documentation

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 208 of file otbMachineLearningModel.h.

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

Definition at line 197 of file otbMachineLearningModel.h.

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

Input list sample

Definition at line 192 of file otbMachineLearningModel.h.

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

Is DoPredictBatch multi-threaded ?

Definition at line 211 of file otbMachineLearningModel.h.

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 205 of file otbMachineLearningModel.h.

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 200 of file otbMachineLearningModel.h.

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

Target list sample

Definition at line 195 of file otbMachineLearningModel.h.


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