ITK  4.6.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 {
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  virtual void StartOptimization( void ) ITK_OVERRIDE;
118 
119 
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 );
142  ParametersType::ValueType> &bounds,
143  unsigned int n );
145 
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 ITK_OVERRIDE;
194 
199  void PrintSwarm( std::ostream& os, Indent indent ) const;
200 
201 protected:
203  virtual ~ParticleSwarmOptimizerBase();
204  virtual void PrintSelf( std::ostream& os, Indent indent ) const ITK_OVERRIDE;
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 
225  std::ostringstream m_StopConditionDescription;
234  std::vector<ParticleData> m_Particles;
240  bool m_UseSeed;
241 };
242 } // end namespace itk
243 
244 #endif
virtual void SetParameterBounds(ParameterBoundsType &bounds)
std::vector< std::pair< ParametersType::ValueType, ParametersType::ValueType > > ParameterBoundsType
virtual const std::string GetStopConditionDescription() const ITK_OVERRIDE
This class is a base for the CostFunctions returning a single value.
Light weight base class for most itk classes.
std::vector< MeasureType > m_FunctionBestValueMemory
Statistics::MersenneTwisterRandomVariateGenerator RandomVariateGeneratorType
virtual void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
This class is a base for the Optimization methods that optimize a single valued function.
RandomVariateGeneratorType::IntegerType m_Seed
void PrintParamtersType(const ParametersType &x, std::ostream &os) const
CostFunctionType::MeasureType m_FunctionBestValue
ParameterBoundsType GetParameterBounds() const
void SetInitialSwarm(const SwarmType &initialSwarm)
CostFunctionType::MeasureType m_FunctionConvergenceTolerance
void PrintSwarm(std::ostream &os, Indent indent) const
NumberOfGenerationsType m_NumberOfGenerationsWithMinimalImprovement
void SetParametersConvergenceTolerance(ValueType convergenceTolerance, unsigned int sz)
void SetNumberOfParticles(NumberOfParticlesType n)
SingleValuedNonLinearOptimizer Superclass
Control indentation during Print() invocation.
Definition: itkIndent.h:49
virtual void StartOptimization(void) ITK_OVERRIDE
Abstract implementation of a Particle Swarm Optimization (PSO) algorithm.
CostFunctionType::MeasureType MeasureType
MeasureType GetValue() const