ITK  4.4.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 
25 namespace itk
26 {
55 class ITK_EXPORT ParticleSwarmOptimizerBase :
57 {
58 public:
64 
67 
68  typedef std::vector< std::pair<ParametersType::ValueType,
70 
71  struct ParticleData
72  {
78  };
79 
80  typedef std::vector<ParticleData> SwarmType;
81  typedef unsigned int NumberOfIterationsType;
82  typedef unsigned int NumberOfParticlesType;
83  typedef unsigned int NumberOfGenerationsType;
88 
94  itkSetMacro( InitializeNormalDistribution, bool )
95  itkGetMacro( InitializeNormalDistribution, bool )
96  itkBooleanMacro( InitializeNormalDistribution )
97 
103  void SetInitialSwarm( const SwarmType &initialSwarm );
104  void ClearSwarm();
106 
112  itkSetMacro( PrintSwarm, bool )
113  itkGetMacro( PrintSwarm, bool )
114  itkBooleanMacro( PrintSwarm )
115 
117  void StartOptimization( void );
118 
119 
122  void SetNumberOfParticles( NumberOfParticlesType n );
123  itkGetMacro( NumberOfParticles, NumberOfParticlesType )
124 
127  itkSetMacro( MaximalNumberOfIterations, NumberOfIterationsType )
128  itkGetMacro( MaximalNumberOfIterations, NumberOfIterationsType )
129 
134  itkSetMacro( NumberOfGenerationsWithMinimalImprovement, NumberOfGenerationsType )
135  itkGetMacro( NumberOfGenerationsWithMinimalImprovement, NumberOfGenerationsType )
136 
140  virtual void SetParameterBounds( ParameterBoundsType & bounds );
141  void SetParameterBounds( std::pair<ParametersType::ValueType,
142  ParametersType::ValueType> &bounds,
143  unsigned int n );
145 
146  ParameterBoundsType GetParameterBounds() const;
147 
162  itkSetMacro( FunctionConvergenceTolerance, MeasureType )
163  itkGetMacro( FunctionConvergenceTolerance, MeasureType )
164 
167  void SetParametersConvergenceTolerance( ValueType convergenceTolerance,
168  unsigned int sz );
169  itkSetMacro( ParametersConvergenceTolerance, ParametersType )
170  itkGetMacro( ParametersConvergenceTolerance, ParametersType )
171  itkGetMacro( PercentageParticlesConverged, double )
172  itkSetMacro( PercentageParticlesConverged, double )
173 
177  itkSetMacro( Seed, RandomVariateGeneratorType::IntegerType)
178  itkGetMacro( Seed, RandomVariateGeneratorType::IntegerType)
179 
183  itkSetMacro( UseSeed, bool )
184  itkGetMacro( UseSeed, bool )
185  itkBooleanMacro( UseSeed)
186 
190  MeasureType GetValue() const;
191 
193  virtual const std::string GetStopConditionDescription() const;
194 
199  void PrintSwarm( std::ostream& os, Indent indent ) const;
200 
201 protected:
203  virtual ~ParticleSwarmOptimizerBase();
204  void PrintSelf( std::ostream& os, Indent indent ) const;
205  void PrintParamtersType( const ParametersType& x, std::ostream& os ) const;
206 
209  virtual void UpdateSwarm() = 0;
210 
211  ParticleSwarmOptimizerBase( const Self& ); //purposely not implemented
212  void operator=( const Self& );//purposely not implemented
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
245