Coverage for cosmoHammer/pso/MpiParticleSwarmOptimizer.py : 34%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
''' Created on Oct 28, 2013
@author: J.Akeret ''' unicode_literals
""" PSO with support for MPI to distribute the workload over multiple nodes """
self.threads = threads pool = MpiPool(self._getMapFunction()) super(MpiParticleSwarmOptimizer, self).__init__(func, low, high, particleCount=particleCount, pool=pool)
if self.threads > 1: pool = multiprocessing.Pool(self.threads) return pool.map else: return map
if(self.isMaster()): converged = super(MpiParticleSwarmOptimizer, self)._converged(it, p, m, n) else: converged = False
converged = mpiBCast(converged) return converged
mapFunction = self.pool.map
mpiSwarm = mpiBCast(swarm)
pos = numpy.array([part.position for part in mpiSwarm]) results = mapFunction(self.func, pos) lnprob = numpy.array([l[0] for l in results]) for i, particle in enumerate(swarm): particle.fitness = lnprob[i] particle.position = pos[i]
return self.pool.isMaster() |