ITK  4.9.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();
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  ParticleSwarmOptimizerBase( const Self& ) ITK_DELETE_FUNCTION;
213  void operator=( const Self& ) ITK_DELETE_FUNCTION;
214 
215  virtual void ValidateSettings();
216 
220  virtual void Initialize();
221 
222  void RandomInitialization();
223  void FileInitialization();
224 
225  bool m_PrintSwarm;
226  std::ostringstream m_StopConditionDescription;
227  bool m_InitializeNormalDistribution;
228  NumberOfParticlesType m_NumberOfParticles;
229  NumberOfIterationsType m_MaximalNumberOfIterations;
230  NumberOfGenerationsType m_NumberOfGenerationsWithMinimalImprovement;
231  ParameterBoundsType m_ParameterBounds;
232  ParametersType m_ParametersConvergenceTolerance;
233  double m_PercentageParticlesConverged;
234  CostFunctionType::MeasureType m_FunctionConvergenceTolerance;
235  std::vector<ParticleData> m_Particles;
236  CostFunctionType::MeasureType m_FunctionBestValue;
237  std::vector<MeasureType> m_FunctionBestValueMemory;
238  ParametersType m_ParametersBestValue;
239  NumberOfIterationsType m_IterationIndex;
240  RandomVariateGeneratorType::IntegerType m_Seed;
241  bool m_UseSeed;
242 };
243 } // end namespace itk
244 
245 #endif
std::vector< std::pair< ParametersType::ValueType, ParametersType::ValueType > > ParameterBoundsType
This class is a base for the CostFunctions returning a single value.
Light weight base class for most itk classes.
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