QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Attributes | List of all members
ParticleSwarmOptimization Class Reference

#include <ql/experimental/math/particleswarmoptimization.hpp>

+ Inheritance diagram for ParticleSwarmOptimization:
+ Collaboration diagram for ParticleSwarmOptimization:

Classes

class  Inertia
 Base inertia class used to alter the PSO state. More...
 
class  Topology
 Base topology class used to determine the personal and global best. More...
 

Public Member Functions

 ParticleSwarmOptimization (Size M, ext::shared_ptr< Topology > topology, ext::shared_ptr< Inertia > inertia, Real c1=2.05, Real c2=2.05, unsigned long seed=SeedGenerator::instance().get())
 
 ParticleSwarmOptimization (Size M, ext::shared_ptr< Topology > topology, ext::shared_ptr< Inertia > inertia, Real omega, Real c1, Real c2, unsigned long seed=SeedGenerator::instance().get())
 
void startState (Problem &P, const EndCriteria &endCriteria)
 
EndCriteria::Type minimize (Problem &P, const EndCriteria &endCriteria) override
 minimize the optimization problem P More...
 
- Public Member Functions inherited from OptimizationMethod
virtual ~OptimizationMethod ()=default
 
virtual EndCriteria::Type minimize (Problem &P, const EndCriteria &endCriteria)=0
 minimize the optimization problem P More...
 

Protected Attributes

std::vector< ArrayX_
 
std::vector< ArrayV_
 
std::vector< ArraypBX_
 
std::vector< ArraygBX_
 
Array pBF_
 
Array gBF_
 
Array lX_
 
Array uX_
 
Size M_
 
Size N_
 
Real c0_
 
Real c1_
 
Real c2_
 
MersenneTwisterUniformRng rng_
 
ext::shared_ptr< Topologytopology_
 
ext::shared_ptr< Inertiainertia_
 

Detailed Description

The process is as follows: M individuals are used to explore the N-dimensional parameter space: \( X_{i}^k = (X_{i, 1}^k, X_{i, 2}^k, \ldots, X_{i, N}^k) \) is the kth-iteration for the ith-individual.

X is updated via the rule

\[ X_{i, j}^{k+1} = X_{i, j}^k + V_{i, j}^{k+1} \]

with V being the "velocity" that updates the position:

\[ V_{i, j}^{k+1} = \chi\left(V_{i, j}^k + c_1 r_{i, j}^k (P_{i, j}^k - X_{i, j}^k) + c_2 R_{i, j}^k (G_{i, j}^k - X_{i, j}^k)\right) \]

where c are constants, r and R are uniformly distributed random numbers in the range [0, 1], and \( P_{i, j} \) is the personal best parameter set for individual i up to iteration k \( G_{i, j} \) is the global best parameter set for the swarm up to iteration k. \( c_1 \) is the self recognition coefficient \( c_2 \) is the social recognition coefficient

This version is known as the PSO with constriction factor (PSO-Co). PSO with inertia factor (PSO-In) updates the velocity according to:

\[ V_{i, j}^{k+1} = \omega V_{i, j}^k + \hat{c}_1 r_{i, j}^k (P_{i, j}^k - X_{i, j}^k) + \hat{c}_2 R_{i, j}^k (G_{i, j}^k - X_{i, j}^k) \]

and is accessible from PSO-Co by setting \( \omega = \chi \), and \( \hat{c}_{1,2} = \chi c_{1,2} \).

These two versions of PSO are normally referred to as canonical PSO.

Convergence of PSO-Co is improved if \( \chi \) is chosen as \( \chi = \frac{2}{\vert 2-\phi-\sqrt{\phi^2 - 4\phi}\vert} \), with \( \phi = c_1 + c_2 \). Stable convergence is achieved if \( \phi >= 4 \). Clerc and Kennedy recommend \( c_1 = c_2 = 2.05 \) and \( \phi = 4.1 \).

Different topologies can be chosen for G, e.g. instead of it being the best of the swarm, it is the best of the nearest neighbours, or some other form.

In the canonical PSO, the inertia function is trivial. It is simply a constant (the inertia) multiplying the previous iteration's velocity. The value of the inertia constant determines the weight of a global search over local search. Like in the case of the topology, other possibilities for the inertia function are also possible, e.g. a function that interpolates between a high inertia at the beginning of the optimization (hence prioritizing a global search) and a low inertia towards the end of the optimization (hence prioritizing a local search).

The optimization stops either because the number of iterations has been reached or because the stationary function value limit has been reached.

Examples
GlobalOptimizer.cpp.

Definition at line 92 of file particleswarmoptimization.hpp.

Constructor & Destructor Documentation

◆ ParticleSwarmOptimization() [1/2]

ParticleSwarmOptimization ( Size  M,
ext::shared_ptr< Topology topology,
ext::shared_ptr< Inertia inertia,
Real  c1 = 2.05,
Real  c2 = 2.05,
unsigned long  seed = SeedGenerator::instance().get() 
)

Definition at line 28 of file particleswarmoptimization.cpp.

◆ ParticleSwarmOptimization() [2/2]

ParticleSwarmOptimization ( Size  M,
ext::shared_ptr< Topology topology,
ext::shared_ptr< Inertia inertia,
Real  omega,
Real  c1,
Real  c2,
unsigned long  seed = SeedGenerator::instance().get() 
)
explicit

Definition at line 42 of file particleswarmoptimization.cpp.

Member Function Documentation

◆ startState()

void startState ( Problem P,
const EndCriteria endCriteria 
)

Definition at line 52 of file particleswarmoptimization.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ minimize()

EndCriteria::Type minimize ( Problem P,
const EndCriteria endCriteria 
)
overridevirtual

minimize the optimization problem P

Implements OptimizationMethod.

Definition at line 95 of file particleswarmoptimization.cpp.

+ Here is the call graph for this function:

Member Data Documentation

◆ X_

std::vector<Array> X_
protected

Definition at line 113 of file particleswarmoptimization.hpp.

◆ V_

std::vector<Array> V_
protected

Definition at line 113 of file particleswarmoptimization.hpp.

◆ pBX_

std::vector<Array> pBX_
protected

Definition at line 113 of file particleswarmoptimization.hpp.

◆ gBX_

std::vector<Array> gBX_
protected

Definition at line 113 of file particleswarmoptimization.hpp.

◆ pBF_

Array pBF_
protected

Definition at line 114 of file particleswarmoptimization.hpp.

◆ gBF_

Array gBF_
protected

Definition at line 114 of file particleswarmoptimization.hpp.

◆ lX_

Array lX_
protected

Definition at line 115 of file particleswarmoptimization.hpp.

◆ uX_

Array uX_
protected

Definition at line 115 of file particleswarmoptimization.hpp.

◆ M_

Size M_
protected

Definition at line 116 of file particleswarmoptimization.hpp.

◆ N_

Size N_
protected

Definition at line 116 of file particleswarmoptimization.hpp.

◆ c0_

Real c0_
protected

Definition at line 117 of file particleswarmoptimization.hpp.

◆ c1_

Real c1_
protected

Definition at line 117 of file particleswarmoptimization.hpp.

◆ c2_

Real c2_
protected

Definition at line 117 of file particleswarmoptimization.hpp.

◆ rng_

MersenneTwisterUniformRng rng_
protected

Definition at line 118 of file particleswarmoptimization.hpp.

◆ topology_

ext::shared_ptr<Topology> topology_
protected

Definition at line 119 of file particleswarmoptimization.hpp.

◆ inertia_

ext::shared_ptr<Inertia> inertia_
protected

Definition at line 120 of file particleswarmoptimization.hpp.