Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
otb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sébastien Peillet
otb
Commits
c260e65e
Commit
c260e65e
authored
7 years ago
by
Guillaume Pasero
Browse files
Options
Downloads
Patches
Plain Diff
ENH: simplify parameters for SOM training
parent
ee51b587
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainSOM.txx
+56
-68
56 additions, 68 deletions
...yReduction/include/otbDimensionalityReductionTrainSOM.txx
with
56 additions
and
68 deletions
Modules/Applications/AppDimensionalityReduction/include/otbDimensionalityReductionTrainSOM.txx
+
56
−
68
View file @
c260e65e
...
@@ -34,62 +34,47 @@ TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue>
...
@@ -34,62 +34,47 @@ TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue>
{
{
AddChoice("algorithm.som", "OTB SOM");
AddChoice("algorithm.som", "OTB SOM");
SetParameterDescription("algorithm.som",
SetParameterDescription("algorithm.som",
"This group of parameters allows setting SOM parameters. "
"This group of parameters allows setting SOM parameters. ");
);
AddParameter(ParameterType_StringList , "algorithm.som.s", "Map size");
AddParameter(ParameterType_Int, "algorithm.som.dim","Dimension of the map");
SetParameterDescription("algorithm.som.s", "Sizes of the SOM map (one per "
SetParameterDescription("algorithm.som.dim","Dimension of the SOM map.");
"dimension). For instance, [12;15] means a 2D map of size 12x15. Support"
"2D to 5D maps.");
AddParameter(ParameterType_StringList , "algorithm.som.s", "Size");
MandatoryOff("algorithm.som.s");
SetParameterDescription("algorithm.som.s", "Size of the SOM map");
MandatoryOff("algorithm.som.s");
AddParameter(ParameterType_StringList , "algorithm.som.n", "Neighborhood sizes");
SetParameterDescription("algorithm.som.n", "Sizes of the initial neighborhood "
AddParameter(ParameterType_StringList , "algorithm.som.n", "Size Neighborhood");
"in the SOM map (one per dimension). The number of sizes should be the same"
SetParameterDescription("algorithm.som.n", "Size of the initial neighborhood in the SOM map");
" as the map sizes");
MandatoryOff("algorithm.som.n");
MandatoryOff("algorithm.som.n");
AddParameter(ParameterType_Int, "algorithm.som.sx", "SizeX");
AddParameter(ParameterType_Int, "algorithm.som.ni", "NumberIteration");
SetParameterDescription("algorithm.som.sx", "X size of the SOM map");
SetParameterDescription("algorithm.som.ni", "Number of iterations for SOM learning");
MandatoryOff("algorithm.som.sx");
MandatoryOff("algorithm.som.ni");
AddParameter(ParameterType_Int, "algorithm.som.sy", "SizeY");
AddParameter(ParameterType_Float, "algorithm.som.bi", "BetaInit");
SetParameterDescription("algorithm.som.sy", "Y size of the SOM map");
SetParameterDescription("algorithm.som.bi", "Initial learning coefficient");
MandatoryOff("algorithm.som.sy");
MandatoryOff("algorithm.som.bi");
AddParameter(ParameterType_Int, "algorithm.som.nx", "NeighborhoodX");
AddParameter(ParameterType_Float, "algorithm.som.bf", "BetaFinal");
SetParameterDescription("algorithm.som.nx", "X size of the initial neighborhood in the SOM map");
SetParameterDescription("algorithm.som.bf", "Final learning coefficient");
MandatoryOff("algorithm.som.nx");
MandatoryOff("algorithm.som.bf");
AddParameter(ParameterType_Int, "algorithm.som.ny", "NeighborhoodY");
AddParameter(ParameterType_Float, "algorithm.som.iv", "InitialValue");
SetParameterDescription("algorithm.som.ny", "Y size of the initial neighborhood in the SOM map");
SetParameterDescription("algorithm.som.iv", "Maximum initial neuron weight");
MandatoryOff("algorithm.som.nx");
MandatoryOff("algorithm.som.iv");
AddParameter(ParameterType_Int, "algorithm.som.ni", "NumberIteration");
std::vector<std::string> size(2, std::string("10"));
SetParameterDescription("algorithm.som.ni", "Number of iterations for SOM learning");
std::vector<std::string> radius(2, std::string("3"));
MandatoryOff("algorithm.som.ni");
SetParameterStringList("algorithm.som.s", size, false);
SetParameterStringList("algorithm.som.n", radius, false);
AddParameter(ParameterType_Float, "algorithm.som.bi", "BetaInit");
DisableParameter("algorithm.som.s");
SetParameterDescription("algorithm.som.bi", "Initial learning coefficient");
DisableParameter("algorithm.som.n");
MandatoryOff("algorithm.som.bi");
SetDefaultParameterInt("algorithm.som.ni", 5);
AddParameter(ParameterType_Float, "algorithm.som.bf", "BetaFinal");
SetDefaultParameterFloat("algorithm.som.bi", 1.0);
SetParameterDescription("algorithm.som.bf", "Final learning coefficient");
SetDefaultParameterFloat("algorithm.som.bf", 0.1);
MandatoryOff("algorithm.som.bf");
SetDefaultParameterFloat("algorithm.som.iv", 10.0);
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);
}
}
template <class TInputValue, class TOutputValue>
template <class TInputValue, class TOutputValue>
...
@@ -98,8 +83,8 @@ TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue>
...
@@ -98,8 +83,8 @@ TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue>
::BeforeTrainSOM(typename ListSampleType::Pointer trainingListSample,
::BeforeTrainSOM(typename ListSampleType::Pointer trainingListSample,
std::string modelPath)
std::string modelPath)
{
{
int SomDim
= GetParameter
In
t("algorithm.som.
dim
");
std::vector<std::string> s
= GetParameter
StringLis
t("algorithm.som.
s
");
std::cout << SomDim << std::endl
;
int SomDim = s.size()
;
if(SomDim == 2)
if(SomDim == 2)
{
{
...
@@ -123,10 +108,11 @@ TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue>
...
@@ -123,10 +108,11 @@ TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue>
{
{
typedef otb::SOMModel<InputValueType, 5> SOM5DModelType;
typedef otb::SOMModel<InputValueType, 5> SOM5DModelType;
TrainSOM<SOM5DModelType >(trainingListSample,modelPath);
TrainSOM<SOM5DModelType >(trainingListSample,modelPath);
}
}
if(SomDim > 5 || SomDim < 2)
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>
...
@@ -136,26 +122,28 @@ void TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue>
::TrainSOM(typename ListSampleType::Pointer trainingListSample,std::string modelPath)
::TrainSOM(typename ListSampleType::Pointer trainingListSample,std::string modelPath)
{
{
typename TSOM::Pointer dimredTrainer = TSOM::New();
typename TSOM::Pointer dimredTrainer = TSOM::New();
unsigned int dim = dimredTrainer->GetDimension();
std::cout << dim << std::endl;
dimredTrainer->SetNumberOfIterations(GetParameterInt("algorithm.som.ni"));
dimredTrainer->SetNumberOfIterations(GetParameterInt("algorithm.som.ni"));
dimredTrainer->SetBetaInit(GetParameterFloat("algorithm.som.bi"));
dimredTrainer->SetBetaInit(GetParameterFloat("algorithm.som.bi"));
dimredTrainer->SetWriteMap(true);
dimredTrainer->SetWriteMap(true);
dimredTrainer->SetBetaEnd(GetParameterFloat("algorithm.som.bf"));
dimredTrainer->SetBetaEnd(GetParameterFloat("algorithm.som.bf"));
dimredTrainer->SetMaxWeight(GetParameterFloat("algorithm.som.iv"));
dimredTrainer->SetMaxWeight(GetParameterFloat("algorithm.som.iv"));
typename TSOM::SizeType size;
typename TSOM::SizeType size;
std::vector<std::
basic_string<char>
> s= GetParameterStringList("algorithm.som.s");
std::vector<std::
string
> s
= GetParameterStringList("algorithm.som.s");
for (unsigned int i=0; i<
dim
; i++)
for (unsigned int i=0; i<
s.size()
; i++)
{
{
size[i]=st
d
::
stoi
(s[i]);
size[i]=
boo
st::
lexical_cast<unsigned int>
(s[i]);
}
}
dimredTrainer->SetMapSize(size);
dimredTrainer->SetMapSize(size);
typename TSOM::SizeType radius;
typename TSOM::SizeType radius;
std::vector<std::basic_string<char>> n= GetParameterStringList("algorithm.som.n");
std::vector<std::string> n = GetParameterStringList("algorithm.som.n");
for (unsigned int i=0; i<dim; i++)
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]=st
d
::
stoi
(n[i]);
radius[i]=
boo
st::
lexical_cast<unsigned int>
(n[i]);
}
}
dimredTrainer->SetNeighborhoodSizeInit(radius);
dimredTrainer->SetNeighborhoodSizeInit(radius);
dimredTrainer->SetInputListSample(trainingListSample);
dimredTrainer->SetInputListSample(trainingListSample);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment