Skip to content
Snippets Groups Projects
Commit c260e65e authored by Guillaume Pasero's avatar Guillaume Pasero
Browse files

ENH: simplify parameters for SOM training

parent ee51b587
No related branches found
No related tags found
No related merge requests found
......@@ -34,62 +34,47 @@ TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue>
{
AddChoice("algorithm.som", "OTB SOM");
SetParameterDescription("algorithm.som",
"This group of parameters allows setting SOM parameters. "
);
AddParameter(ParameterType_Int, "algorithm.som.dim","Dimension of the map");
SetParameterDescription("algorithm.som.dim","Dimension of the SOM map.");
AddParameter(ParameterType_StringList , "algorithm.som.s", "Size");
SetParameterDescription("algorithm.som.s", "Size of the SOM map");
MandatoryOff("algorithm.som.s");
AddParameter(ParameterType_StringList , "algorithm.som.n", "Size Neighborhood");
SetParameterDescription("algorithm.som.n", "Size of the initial neighborhood in the SOM map");
MandatoryOff("algorithm.som.n");
AddParameter(ParameterType_Int, "algorithm.som.sx", "SizeX");
SetParameterDescription("algorithm.som.sx", "X size of the SOM map");
MandatoryOff("algorithm.som.sx");
AddParameter(ParameterType_Int, "algorithm.som.sy", "SizeY");
SetParameterDescription("algorithm.som.sy", "Y size of the SOM map");
MandatoryOff("algorithm.som.sy");
AddParameter(ParameterType_Int, "algorithm.som.nx", "NeighborhoodX");
SetParameterDescription("algorithm.som.nx", "X size of the initial neighborhood in the SOM map");
MandatoryOff("algorithm.som.nx");
AddParameter(ParameterType_Int, "algorithm.som.ny", "NeighborhoodY");
SetParameterDescription("algorithm.som.ny", "Y size of the initial neighborhood in the SOM map");
MandatoryOff("algorithm.som.nx");
AddParameter(ParameterType_Int, "algorithm.som.ni", "NumberIteration");
SetParameterDescription("algorithm.som.ni", "Number of iterations for SOM learning");
MandatoryOff("algorithm.som.ni");
AddParameter(ParameterType_Float, "algorithm.som.bi", "BetaInit");
SetParameterDescription("algorithm.som.bi", "Initial learning coefficient");
MandatoryOff("algorithm.som.bi");
AddParameter(ParameterType_Float, "algorithm.som.bf", "BetaFinal");
SetParameterDescription("algorithm.som.bf", "Final learning coefficient");
MandatoryOff("algorithm.som.bf");
AddParameter(ParameterType_Float, "algorithm.som.iv", "InitialValue");
SetParameterDescription("algorithm.som.iv", "Maximum initial neuron weight");
MandatoryOff("algorithm.som.iv");
SetDefaultParameterInt("algorithm.som.sx", 32);
SetDefaultParameterInt("algorithm.som.sy", 32);
SetDefaultParameterInt("algorithm.som.nx", 10);
SetDefaultParameterInt("algorithm.som.ny", 10);
SetDefaultParameterInt("algorithm.som.ni", 5);
SetDefaultParameterFloat("algorithm.som.bi", 1.0);
SetDefaultParameterFloat("algorithm.som.bf", 0.1);
SetDefaultParameterFloat("algorithm.som.iv", 10.0);
"This group of parameters allows setting SOM parameters. ");
AddParameter(ParameterType_StringList , "algorithm.som.s", "Map size");
SetParameterDescription("algorithm.som.s", "Sizes of the SOM map (one per "
"dimension). For instance, [12;15] means a 2D map of size 12x15. Support"
"2D to 5D maps.");
MandatoryOff("algorithm.som.s");
AddParameter(ParameterType_StringList , "algorithm.som.n", "Neighborhood sizes");
SetParameterDescription("algorithm.som.n", "Sizes of the initial neighborhood "
"in the SOM map (one per dimension). The number of sizes should be the same"
" as the map sizes");
MandatoryOff("algorithm.som.n");
AddParameter(ParameterType_Int, "algorithm.som.ni", "NumberIteration");
SetParameterDescription("algorithm.som.ni", "Number of iterations for SOM learning");
MandatoryOff("algorithm.som.ni");
AddParameter(ParameterType_Float, "algorithm.som.bi", "BetaInit");
SetParameterDescription("algorithm.som.bi", "Initial learning coefficient");
MandatoryOff("algorithm.som.bi");
AddParameter(ParameterType_Float, "algorithm.som.bf", "BetaFinal");
SetParameterDescription("algorithm.som.bf", "Final learning coefficient");
MandatoryOff("algorithm.som.bf");
AddParameter(ParameterType_Float, "algorithm.som.iv", "InitialValue");
SetParameterDescription("algorithm.som.iv", "Maximum initial neuron weight");
MandatoryOff("algorithm.som.iv");
std::vector<std::string> size(2, std::string("10"));
std::vector<std::string> radius(2, std::string("3"));
SetParameterStringList("algorithm.som.s", size, false);
SetParameterStringList("algorithm.som.n", radius, false);
DisableParameter("algorithm.som.s");
DisableParameter("algorithm.som.n");
SetDefaultParameterInt("algorithm.som.ni", 5);
SetDefaultParameterFloat("algorithm.som.bi", 1.0);
SetDefaultParameterFloat("algorithm.som.bf", 0.1);
SetDefaultParameterFloat("algorithm.som.iv", 10.0);
}
template <class TInputValue, class TOutputValue>
......@@ -98,8 +83,8 @@ TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue>
::BeforeTrainSOM(typename ListSampleType::Pointer trainingListSample,
std::string modelPath)
{
int SomDim = GetParameterInt("algorithm.som.dim");
std::cout << SomDim << std::endl;
std::vector<std::string> s = GetParameterStringList("algorithm.som.s");
int SomDim = s.size();
if(SomDim == 2)
{
......@@ -123,10 +108,11 @@ TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue>
{
typedef otb::SOMModel<InputValueType, 5> SOM5DModelType;
TrainSOM<SOM5DModelType >(trainingListSample,modelPath);
}
}
if(SomDim > 5 || SomDim < 2)
{
std::cerr << "k : invalid dimension" << std::endl;
otbAppLogFATAL(<< "Invalid number of dimensions : " << SomDim <<
". Only support 2, 3, 4 or 5 dimensions");
}
}
......@@ -136,26 +122,28 @@ void TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue>
::TrainSOM(typename ListSampleType::Pointer trainingListSample,std::string modelPath)
{
typename TSOM::Pointer dimredTrainer = TSOM::New();
unsigned int dim = dimredTrainer->GetDimension();
std::cout << dim << std::endl;
dimredTrainer->SetNumberOfIterations(GetParameterInt("algorithm.som.ni"));
dimredTrainer->SetBetaInit(GetParameterFloat("algorithm.som.bi"));
dimredTrainer->SetWriteMap(true);
dimredTrainer->SetBetaEnd(GetParameterFloat("algorithm.som.bf"));
dimredTrainer->SetMaxWeight(GetParameterFloat("algorithm.som.iv"));
typename TSOM::SizeType size;
std::vector<std::basic_string<char>> s= GetParameterStringList("algorithm.som.s");
for (unsigned int i=0; i<dim; i++)
std::vector<std::string> s = GetParameterStringList("algorithm.som.s");
for (unsigned int i=0; i<s.size(); i++)
{
size[i]=std::stoi(s[i]);
size[i]=boost::lexical_cast<unsigned int>(s[i]);
}
dimredTrainer->SetMapSize(size);
typename TSOM::SizeType radius;
std::vector<std::basic_string<char>> n= GetParameterStringList("algorithm.som.n");
for (unsigned int i=0; i<dim; i++)
std::vector<std::string> n = GetParameterStringList("algorithm.som.n");
if (n.size() != s.size())
{
otbAppLogFATAL(<< "Wrong number of neighborhood radii : expected "<< s.size() << " ; got "<< n.size());
}
for (unsigned int i=0; i < n.size(); i++)
{
radius[i]=std::stoi(n[i]);
radius[i]=boost::lexical_cast<unsigned int>(n[i]);
}
dimredTrainer->SetNeighborhoodSizeInit(radius);
dimredTrainer->SetInputListSample(trainingListSample);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment