ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkParticleSwarmOptimizerBase.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 {
56 class ITKOptimizers_EXPORT ParticleSwarmOptimizerBase :
58 {
59 public:
65 
68 
69  typedef std::vector< std::pair<ParametersType::ValueType,
71 
72  struct ParticleData
73  {
74  ParametersType m_CurrentParameters;
75  ParametersType m_CurrentVelocity;
77  ParametersType m_BestParameters;
79  };
80 
81  typedef std::vector<ParticleData> SwarmType;
82  typedef unsigned int NumberOfIterationsType;
83  typedef unsigned int NumberOfParticlesType;
84  typedef unsigned int NumberOfGenerationsType;
89 
95  itkSetMacro( InitializeNormalDistribution, bool )
96  itkGetMacro( InitializeNormalDistribution, bool )
97  itkBooleanMacro( InitializeNormalDistribution )
98 
104  void SetInitialSwarm( const SwarmType &initialSwarm );
105  void ClearSwarm();
107 
113  itkSetMacro( PrintSwarm, bool )
114  itkGetMacro( PrintSwarm, bool )
115  itkBooleanMacro( PrintSwarm )
116 
118  virtual void StartOptimization( void ) ITK_OVERRIDE;
119 
120 
123  void SetNumberOfParticles( NumberOfParticlesType n );
124  itkGetMacro( NumberOfParticles, NumberOfParticlesType )
125 
128  itkSetMacro( MaximalNumberOfIterations, NumberOfIterationsType )
129  itkGetMacro( MaximalNumberOfIterations, NumberOfIterationsType )
130 
135  itkSetMacro( NumberOfGenerationsWithMinimalImprovement, NumberOfGenerationsType )
136  itkGetMacro( NumberOfGenerationsWithMinimalImprovement, NumberOfGenerationsType )
137 
141  virtual void SetParameterBounds( ParameterBoundsType & bounds );
142  void SetParameterBounds( std::pair<ParametersType::ValueType,
143  ParametersType::ValueType> &bounds,
144  unsigned int n );
146 
147  ParameterBoundsType GetParameterBounds() const;
148 
163  itkSetMacro( FunctionConvergenceTolerance, MeasureType )
164  itkGetMacro( FunctionConvergenceTolerance, MeasureType )
165 
168  void SetParametersConvergenceTolerance( ValueType convergenceTolerance,
169  unsigned int sz );
170  itkSetMacro( ParametersConvergenceTolerance, ParametersType )
171  itkGetMacro( ParametersConvergenceTolerance, ParametersType )
172  itkGetMacro( PercentageParticlesConverged, double )
173  itkSetMacro( PercentageParticlesConverged, double )
174 
178  itkSetMacro( Seed, RandomVariateGeneratorType::IntegerType)
179  itkGetMacro( Seed, RandomVariateGeneratorType::IntegerType)
180 
184  itkSetMacro( UseSeed, bool )
185  itkGetMacro( UseSeed, bool )
186  itkBooleanMacro( UseSeed)
187 
191  MeasureType GetValue() const;
192 
194  virtual const std::string GetStopConditionDescription() const ITK_OVERRIDE;
195 
200  void PrintSwarm( std::ostream& os, Indent indent ) const;
201 
202 protected:
204  virtual ~ParticleSwarmOptimizerBase() ITK_OVERRIDE;
205  virtual void PrintSelf( std::ostream& os, Indent indent ) const ITK_OVERRIDE;
206  void PrintParamtersType( const ParametersType& x, std::ostream& os ) const;
207 
210  virtual void UpdateSwarm() = 0;
211 
212  ITK_DISALLOW_COPY_AND_ASSIGN(ParticleSwarmOptimizerBase);
213 
214  virtual void ValidateSettings();
215 
219  virtual void Initialize();
220 
221  void RandomInitialization();
222  void FileInitialization();
223 
224  bool m_PrintSwarm;
225  std::ostringstream m_StopConditionDescription;
226  bool m_InitializeNormalDistribution;
227  NumberOfParticlesType m_NumberOfParticles;
228  NumberOfIterationsType m_MaximalNumberOfIterations;
229  NumberOfGenerationsType m_NumberOfGenerationsWithMinimalImprovement;
230  ParameterBoundsType m_ParameterBounds;
231  ParametersType m_ParametersConvergenceTolerance;
232  double m_PercentageParticlesConverged;
233  CostFunctionType::MeasureType m_FunctionConvergenceTolerance;
234  std::vector<ParticleData> m_Particles;
235  CostFunctionType::MeasureType m_FunctionBestValue;
236  std::vector<MeasureType> m_FunctionBestValueMemory;
237  ParametersType m_ParametersBestValue;
238  NumberOfIterationsType m_IterationIndex;
239  RandomVariateGeneratorType::IntegerType m_Seed;
240  bool m_UseSeed;
241 };
242 } // end namespace itk
243 
244 #endif
std::vector< std::pair< ParametersType::ValueType, ParametersType::ValueType > > ParameterBoundsType
This class is a base for the CostFunctions returning a single value.
Statistics::MersenneTwisterRandomVariateGenerator RandomVariateGeneratorType
This class is a base for the Optimization methods that optimize a single valued function.
SingleValuedNonLinearOptimizer Superclass
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Abstract implementation of a Particle Swarm Optimization (PSO) algorithm.
CostFunctionType::MeasureType MeasureType