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

#include <fireflyalgorithm.hpp>

+ Inheritance diagram for FireflyAlgorithm:
+ Collaboration diagram for FireflyAlgorithm:

Classes

class  Intensity
 Base intensity class. More...
 
class  RandomWalk
 Base Random Walk class. More...
 

Public Member Functions

 FireflyAlgorithm (Size M, ext::shared_ptr< Intensity > intensity, ext::shared_ptr< RandomWalk > randomWalk, Size Mde=0, Real mutationFactor=1.0, Real crossoverFactor=0.5, 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< ArrayxI_
 
std::vector< ArrayxRW_
 
std::vector< std::pair< Real, Size > > values_
 
Array lX_
 
Array uX_
 
Real mutation_
 
Real crossover_
 
Size M_
 
Size N_
 
Size Mde_
 
Size Mfa_
 
ext::shared_ptr< Intensityintensity_
 
ext::shared_ptr< RandomWalkrandomWalk_
 
std::mt19937 generator_
 
std::uniform_int_distribution< QuantLib::Sizedistribution_
 
MersenneTwisterUniformRng rng_
 

Detailed Description

The main 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 + I(X^k)_{i,j} + RandomWalk_{i,j}^k \]

The intensity function I(X) should be monotonic The optimization stops either because the number of iterations has been reached or because the stationary function value limit has been reached.

The current implementation extends the normal Firefly Algorithm with a differential evolution (DE) optimizer according to: Afnizanfaizal Abdullah, et al. "A New Hybrid Firefly Algorithm for Complex and Nonlinear Problem". Volume 151 of the series Advances in Intelligent and Soft Computing pp 673-680, 2012. http://link.springer.com/chapter/10.1007%2F978-3-642-28765-7_81

In effect this implementation provides a fully fledged DE global optimizer as well. The Firefly Algorithm was easy to combine with DE because it already contained a step where the current solutions are sorted. The population is then divided into two subpopulations based on their order. The subpopulation with the best results are updated via the firefly algorithm. The worse subpopulation is updated via the DE operator:

\[ Y^{k+1} = X_{best}^k + F(X_{r1}^k - X_{r2}^k) \]

and

\[ X_{i,j}^{k+1} = Y_{i,j}^{k+1}\ \text{if} R_{i,j} <= C \]

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

where C is the crossover constant, and R is a random uniformly distributed number.

Examples
GlobalOptimizer.cpp.

Definition at line 80 of file fireflyalgorithm.hpp.

Constructor & Destructor Documentation

◆ FireflyAlgorithm()

FireflyAlgorithm ( Size  M,
ext::shared_ptr< Intensity intensity,
ext::shared_ptr< RandomWalk randomWalk,
Size  Mde = 0,
Real  mutationFactor = 1.0,
Real  crossoverFactor = 0.5,
unsigned long  seed = SeedGenerator::instance().get() 
)

Definition at line 27 of file fireflyalgorithm.cpp.

Member Function Documentation

◆ startState()

void startState ( Problem P,
const EndCriteria endCriteria 
)

Definition at line 42 of file fireflyalgorithm.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 75 of file fireflyalgorithm.cpp.

+ Here is the call graph for this function:

Member Data Documentation

◆ x_

std::vector<Array> x_
protected

Definition at line 95 of file fireflyalgorithm.hpp.

◆ xI_

std::vector<Array> xI_
protected

Definition at line 95 of file fireflyalgorithm.hpp.

◆ xRW_

std::vector<Array> xRW_
protected

Definition at line 95 of file fireflyalgorithm.hpp.

◆ values_

std::vector<std::pair<Real, Size> > values_
protected

Definition at line 96 of file fireflyalgorithm.hpp.

◆ lX_

Array lX_
protected

Definition at line 97 of file fireflyalgorithm.hpp.

◆ uX_

Array uX_
protected

Definition at line 97 of file fireflyalgorithm.hpp.

◆ mutation_

Real mutation_
protected

Definition at line 98 of file fireflyalgorithm.hpp.

◆ crossover_

Real crossover_
protected

Definition at line 98 of file fireflyalgorithm.hpp.

◆ M_

Size M_
protected

Definition at line 99 of file fireflyalgorithm.hpp.

◆ N_

Size N_
protected

Definition at line 99 of file fireflyalgorithm.hpp.

◆ Mde_

Size Mde_
protected

Definition at line 99 of file fireflyalgorithm.hpp.

◆ Mfa_

Size Mfa_
protected

Definition at line 99 of file fireflyalgorithm.hpp.

◆ intensity_

ext::shared_ptr<Intensity> intensity_
protected

Definition at line 100 of file fireflyalgorithm.hpp.

◆ randomWalk_

ext::shared_ptr<RandomWalk> randomWalk_
protected

Definition at line 101 of file fireflyalgorithm.hpp.

◆ generator_

std::mt19937 generator_
protected

Definition at line 102 of file fireflyalgorithm.hpp.

◆ distribution_

std::uniform_int_distribution<QuantLib::Size> distribution_
protected

Definition at line 103 of file fireflyalgorithm.hpp.

◆ rng_

MersenneTwisterUniformRng rng_
protected

Definition at line 104 of file fireflyalgorithm.hpp.