ITK  5.2.0
Insight Toolkit
itkParticleSwarmOptimizerBase.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 
19 #ifndef itkParticleSwarmOptimizerBase_h
20 #define itkParticleSwarmOptimizerBase_h
21 
24 #include "ITKOptimizersExport.h"
25 
26 namespace itk
27 {
57 {
58 public:
59  ITK_DISALLOW_COPY_AND_ASSIGN(ParticleSwarmOptimizerBase);
60 
66 
69 
71 
72  struct ParticleData
73  {
74  ParametersType m_CurrentParameters;
75  ParametersType m_CurrentVelocity;
77  ParametersType m_BestParameters;
79  };
80 
81  using SwarmType = std::vector<ParticleData>;
82  using NumberOfIterationsType = unsigned int;
83  using NumberOfParticlesType = unsigned int;
84  using NumberOfGenerationsType = unsigned int;
88 
94  itkSetMacro(InitializeNormalDistribution, bool) itkGetMacro(InitializeNormalDistribution, bool)
95  itkBooleanMacro(InitializeNormalDistribution)
96 
97 
102  void SetInitialSwarm(const SwarmType & initialSwarm);
103  void
104  ClearSwarm();
106 
112  itkSetMacro(PrintSwarm, bool) itkGetMacro(PrintSwarm, bool) itkBooleanMacro(PrintSwarm)
113 
114 
115  void StartOptimization() override;
116 
117 
120  void
121  SetNumberOfParticles(NumberOfParticlesType n);
122  itkGetMacro(NumberOfParticles, NumberOfParticlesType)
123 
124 
126  itkSetMacro(MaximalNumberOfIterations, NumberOfIterationsType)
127  itkGetMacro(MaximalNumberOfIterations, NumberOfIterationsType)
128 
129 
133  itkSetMacro(NumberOfGenerationsWithMinimalImprovement, NumberOfGenerationsType)
134  itkGetMacro(NumberOfGenerationsWithMinimalImprovement, NumberOfGenerationsType)
135 
136 
139  virtual void SetParameterBounds(ParameterBoundsType & bounds);
140  void
141  SetParameterBounds(std::pair<ParametersType::ValueType, ParametersType::ValueType> & bounds, unsigned int n);
143 
145  GetParameterBounds() const;
146 
161  itkSetMacro(FunctionConvergenceTolerance, MeasureType) itkGetMacro(FunctionConvergenceTolerance, MeasureType)
162 
163 
165  void SetParametersConvergenceTolerance(ValueType convergenceTolerance, unsigned int sz);
166  itkSetMacro(ParametersConvergenceTolerance, ParametersType)
167  itkGetMacro(ParametersConvergenceTolerance, ParametersType) itkGetMacro(PercentageParticlesConverged, double)
168  itkSetMacro(PercentageParticlesConverged, double)
169 
170 
173  itkSetMacro(Seed, RandomVariateGeneratorType::IntegerType)
174  itkGetMacro(Seed, RandomVariateGeneratorType::IntegerType)
175 
176 
179  itkSetMacro(UseSeed, bool) itkGetMacro(UseSeed, bool) itkBooleanMacro(UseSeed)
180 
181 
184  MeasureType GetValue() const;
185 
187  const std::string
188  GetStopConditionDescription() const override;
189 
194  void
195  PrintSwarm(std::ostream & os, Indent indent) const;
196 
197 protected:
199  ~ParticleSwarmOptimizerBase() override;
200  void
201  PrintSelf(std::ostream & os, Indent indent) const override;
202  void
203  PrintParamtersType(const ParametersType & x, std::ostream & os) const;
204 
207  virtual void
208  UpdateSwarm() = 0;
209 
210  virtual void
211  ValidateSettings();
212 
216  virtual void
217  Initialize();
218 
219  void
220  RandomInitialization();
221  void
222  FileInitialization();
223 
225  std::ostringstream m_StopConditionDescription;
234  std::vector<ParticleData> m_Particles;
235  CostFunctionType::MeasureType m_FunctionBestValue{ 0 };
236  std::vector<MeasureType> m_FunctionBestValueMemory;
238  NumberOfIterationsType m_IterationIndex{ 0 };
240  bool m_UseSeed;
241 };
242 } // end namespace itk
243 
244 #endif
itk::ParticleSwarmOptimizerBase::m_FunctionConvergenceTolerance
CostFunctionType::MeasureType m_FunctionConvergenceTolerance
Definition: itkParticleSwarmOptimizerBase.h:233
itk::SingleValuedCostFunction::MeasureType
double MeasureType
Definition: itkSingleValuedCostFunction.h:50
itk::OptimizerParameters< double >
itk::Statistics::MersenneTwisterRandomVariateGenerator
MersenneTwisterRandom random variate generator.
Definition: itkMersenneTwisterRandomVariateGenerator.h:127
itk::ParticleSwarmOptimizerBase::ParticleData
Definition: itkParticleSwarmOptimizerBase.h:72
itk::SingleValuedNonLinearOptimizer
This class is a base for the Optimization methods that optimize a single valued function.
Definition: itkSingleValuedNonLinearOptimizer.h:35
itk::ParticleSwarmOptimizerBase::m_NumberOfParticles
NumberOfParticlesType m_NumberOfParticles
Definition: itkParticleSwarmOptimizerBase.h:227
itk::ParticleSwarmOptimizerBase::ParticleData::m_CurrentVelocity
ParametersType m_CurrentVelocity
Definition: itkParticleSwarmOptimizerBase.h:75
itk::ParticleSwarmOptimizerBase::m_InitializeNormalDistribution
bool m_InitializeNormalDistribution
Definition: itkParticleSwarmOptimizerBase.h:226
itk::ParticleSwarmOptimizerBase::m_FunctionBestValueMemory
std::vector< MeasureType > m_FunctionBestValueMemory
Definition: itkParticleSwarmOptimizerBase.h:236
itk::ParticleSwarmOptimizerBase::SwarmType
std::vector< ParticleData > SwarmType
Definition: itkParticleSwarmOptimizerBase.h:81
itk::ParticleSwarmOptimizerBase::MeasureType
CostFunctionType::MeasureType MeasureType
Definition: itkParticleSwarmOptimizerBase.h:85
itk::ParticleSwarmOptimizerBase::m_ParameterBounds
ParameterBoundsType m_ParameterBounds
Definition: itkParticleSwarmOptimizerBase.h:230
itk::ParticleSwarmOptimizerBase::NumberOfParticlesType
unsigned int NumberOfParticlesType
Definition: itkParticleSwarmOptimizerBase.h:83
itk::ParticleSwarmOptimizerBase::m_MaximalNumberOfIterations
NumberOfIterationsType m_MaximalNumberOfIterations
Definition: itkParticleSwarmOptimizerBase.h:228
itk::OptimizerParameters< double >::ValueType
double ValueType
Definition: itkOptimizerParameters.h:38
itk::ParticleSwarmOptimizerBase::m_NumberOfGenerationsWithMinimalImprovement
NumberOfGenerationsType m_NumberOfGenerationsWithMinimalImprovement
Definition: itkParticleSwarmOptimizerBase.h:229
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ParticleSwarmOptimizerBase::m_ParametersConvergenceTolerance
ParametersType m_ParametersConvergenceTolerance
Definition: itkParticleSwarmOptimizerBase.h:231
itk::ParticleSwarmOptimizerBase::ParticleData::m_CurrentParameters
ParametersType m_CurrentParameters
Definition: itkParticleSwarmOptimizerBase.h:74
itk::ParticleSwarmOptimizerBase::NumberOfIterationsType
unsigned int NumberOfIterationsType
Definition: itkParticleSwarmOptimizerBase.h:82
itk::ParticleSwarmOptimizerBase::m_PercentageParticlesConverged
double m_PercentageParticlesConverged
Definition: itkParticleSwarmOptimizerBase.h:232
itk::ParticleSwarmOptimizerBase
Abstract implementation of a Particle Swarm Optimization (PSO) algorithm.
Definition: itkParticleSwarmOptimizerBase.h:56
itk::ParticleSwarmOptimizerBase::m_UseSeed
bool m_UseSeed
Definition: itkParticleSwarmOptimizerBase.h:240
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::ParticleSwarmOptimizerBase::m_ParametersBestValue
ParametersType m_ParametersBestValue
Definition: itkParticleSwarmOptimizerBase.h:237
itk::ParticleSwarmOptimizerBase::ParticleData::m_CurrentValue
CostFunctionType::MeasureType m_CurrentValue
Definition: itkParticleSwarmOptimizerBase.h:76
itkMersenneTwisterRandomVariateGenerator.h
itk::ParticleSwarmOptimizerBase::m_PrintSwarm
bool m_PrintSwarm
Definition: itkParticleSwarmOptimizerBase.h:224
itk::Statistics::MersenneTwisterRandomVariateGenerator::IntegerType
uint32_t IntegerType
Definition: itkMersenneTwisterRandomVariateGenerator.h:136
itk::ParticleSwarmOptimizerBase::ValueType
ParametersType::ValueType ValueType
Definition: itkParticleSwarmOptimizerBase.h:86
itk::ParticleSwarmOptimizerBase::m_Seed
RandomVariateGeneratorType::IntegerType m_Seed
Definition: itkParticleSwarmOptimizerBase.h:239
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ParticleSwarmOptimizerBase::ParticleData::m_BestValue
CostFunctionType::MeasureType m_BestValue
Definition: itkParticleSwarmOptimizerBase.h:78
itk::ParticleSwarmOptimizerBase::ParameterBoundsType
std::vector< std::pair< ParametersType::ValueType, ParametersType::ValueType > > ParameterBoundsType
Definition: itkParticleSwarmOptimizerBase.h:70
itk::ParticleSwarmOptimizerBase::m_Particles
std::vector< ParticleData > m_Particles
Definition: itkParticleSwarmOptimizerBase.h:234
itkSingleValuedNonLinearOptimizer.h
itk::ParticleSwarmOptimizerBase::ParticleData::m_BestParameters
ParametersType m_BestParameters
Definition: itkParticleSwarmOptimizerBase.h:77
itk::ParticleSwarmOptimizerBase::m_StopConditionDescription
std::ostringstream m_StopConditionDescription
Definition: itkParticleSwarmOptimizerBase.h:225
itk::ParticleSwarmOptimizerBase::NumberOfGenerationsType
unsigned int NumberOfGenerationsType
Definition: itkParticleSwarmOptimizerBase.h:84