cosmoHammer.pso package
Submodules
cosmoHammer.pso.BestFitPositionGenerator module
cosmoHammer.pso.CurvatureFitter module
cosmoHammer.pso.MpiParticleSwarmOptimizer module
Created on Oct 28, 2013
@author: J.Akeret
-
class
cosmoHammer.pso.MpiParticleSwarmOptimizer.
MpiParticleSwarmOptimizer
(func, low, high, particleCount=25, threads=1)[source]
Bases: cosmoHammer.pso.ParticleSwarmOptimizer.ParticleSwarmOptimizer
PSO with support for MPI to distribute the workload over multiple nodes
-
isMaster
()[source]
cosmoHammer.pso.ParticleSwarmOptimizer module
Created on Sep 30, 2013
@author: J. Akeret
-
class
cosmoHammer.pso.ParticleSwarmOptimizer.
Particle
(position, velocity, fitness=0)[source]
Bases: object
Implementation of a single particle
Parameters: |
- position – the position of the particle in the parameter space
- velocity – the velocity of the particle
- fitness – the current fitness of the particle
|
-
copy
()[source]
Creates a copy of itself
-
classmethod
create
(paramCount)[source]
Creates a new particle without position, velocity and -inf as fitness
-
updatePBest
()[source]
Sets the current particle representation as personal best
-
class
cosmoHammer.pso.ParticleSwarmOptimizer.
ParticleSwarmOptimizer
(func, low, high, particleCount=25, threads=1, pool=None)[source]
Bases: object
Optimizer using a swarm of particles
Parameters: |
- func – A function that takes a vector in the parameter space as input and
returns the natural logarithm of the posterior probability for that
position.
- low – array of the lower bound of the parameter space
- high – array of the upper bound of the parameter space
- particleCount – the number of particles to use.
- threads – (optional)
The number of threads to use for parallelization. If
threads == 1 ,
then the multiprocessing module is not used but if
threads > 1 , then a Pool object is created and calls to
lnpostfn are run in parallel.
- pool – (optional)
An alternative method of using the parallelized algorithm. If
provided, the value of
threads is ignored and the
object provided by pool is used for all parallelization. It
can be any object with a map method that follows the same
calling sequence as the built-in map function.
|
-
isMaster
()[source]
-
optimize
(maxIter=1000, c1=1.193, c2=1.193, p=0.7, m=0.001, n=0.01)[source]
Runs the complete optimiziation.
Parameters: |
- maxIter – maximum iterations
- c1 – cognitive weight
- c2 – social weight
- p – stop criterion, percentage of particles to use
- m – stop criterion, difference between mean fitness and global best
- n – stop criterion, difference between norm of the particle vector and norm of the global best
|
Return swarms, gBests: |
| the swarms and the global bests of all iterations
|
-
sample
(maxIter=1000, c1=1.193, c2=1.193, p=0.7, m=0.001, n=0.01)[source]
Launches the PSO. Yields the complete swarm per iteration
Parameters: |
- maxIter – maximum iterations
- c1 – cognitive weight
- c2 – social weight
- p – stop criterion, percentage of particles to use
- m – stop criterion, difference between mean fitness and global best
- n – stop criterion, difference between norm of the particle vector and norm of the global best
|
Module contents