Request for changes-102: Extend MachineLearningModel sample and target types

From OTBWiki
Jump to: navigation, search

Status

Summary

The goal of this pull request is to be able to use itk::VariableLengthVector<> as Target type in otb::MachineLearningModel, so as to avoid code duplication when the following remote module will be merged in otb:

http://tully.ups-tlse.fr/traizetc/cb_dimensionality_reduction

Rationale

Currently, MachineLearningModel excepts scalar types TSample and TTarget and defines

TargetSampleType = itk::FixedArray<TTarget,1>
InputSampleType  = itk::VariableLenghtVector<TSample>

It is therefore impossible to use different containers for TargetSampleType and InputSampleType.

Implementation details

The main idea of this RFC is that MachineLearningModel will use MachineLearningModelTraits to define TargetSampleType and InputSampleType. The traits will then switch beween two cases: if TTarget (resp. TSample) is a scalar type, it will use the current containers typedef, and if TTarget is a container itself, it will use it instead:

https://git.orfeo-toolbox.org/otb.git/blob/1f14c5d13a4d245a6b842e2ef5082706293b2eec:/Modules/Learning/LearningBase/include/otbMachineLearningModelTraits.h

Using those traits allows to reach the goal with a very limited impact on MachineLearningModel, and not a single line of code changes in derived classes.

Classes and files

New traits are defined in:

Modules/Learning/LearningBase/include/otbMachineLearningModelTraits.h

The otb::MachineLearningModel class has been updated to use the new traits:

Modules/Learning/LearningBase/include/otbMachineLearningModel.h

Tests

Modules/Learning/LearningBase/test/otbMachineLearningModelTemplates.cxx

has been extended to test that we can

typedef otb::MachineLearningModel<float,itk::VariableLengthVector<double>> MachineLearningModelType2;

Documentation

Doxygen documentation is provided for MachineLearningModelTraits.