|
@@ 736-766 (lines=31) @@
|
| 733 |
|
d.update({'nmutt': self.nmutt}) |
| 734 |
|
return d |
| 735 |
|
|
| 736 |
|
def runIteration(self, task, pop, fpop, xb, fxb, **dparams): |
| 737 |
|
r"""Core function of algorithm. |
| 738 |
|
|
| 739 |
|
Args: |
| 740 |
|
task (Task): Optimization task. |
| 741 |
|
pop (numpy.ndarray): Current population of particles. |
| 742 |
|
fpop (numpy.ndarray): Current particles function/fitness values. |
| 743 |
|
xb (numpy.ndarray): Current global best particle. |
| 744 |
|
fxb (float: Current global best particles function/fitness value. |
| 745 |
|
**dparams: Additional arguments. |
| 746 |
|
|
| 747 |
|
Returns: |
| 748 |
|
Tuple[np.ndarray, np.ndarray, np.ndarray, float, dict]: |
| 749 |
|
1. New population of particles. |
| 750 |
|
2. New populations function/fitness values. |
| 751 |
|
3. New global best particle. |
| 752 |
|
4. New global best particle function/fitness value. |
| 753 |
|
5. Additional arguments. |
| 754 |
|
|
| 755 |
|
See Also: |
| 756 |
|
* :func:`NiaPy.algorithm.basic.WeightedVelocityClampingParticleSwarmAlgorithm.runIteration` |
| 757 |
|
""" |
| 758 |
|
pop, fpop, xb, fxb, d = CenterParticleSwarmOptimization.runIteration(self, task, pop, fpop, xb, fxb, **dparams) |
| 759 |
|
v = d['V'] |
| 760 |
|
v_a = (np.sum(v, axis=0) / len(v)) |
| 761 |
|
v_a = v_a / np.max(np.abs(v_a)) |
| 762 |
|
for _ in range(self.nmutt): |
| 763 |
|
g = task.repair(xb + v_a * self.uniform(task.Lower, task.Upper), self.Rand) |
| 764 |
|
fg = task.eval(g) |
| 765 |
|
if fg <= fxb: xb, fxb = g, fg |
| 766 |
|
return pop, fpop, xb, fxb, d |
| 767 |
|
|
| 768 |
|
class MutatedCenterUnifiedParticleSwarmOptimization(MutatedCenterParticleSwarmOptimization): |
| 769 |
|
r"""Implementation of Mutated Particle Swarm Optimization. |
|
@@ 639-669 (lines=31) @@
|
| 636 |
|
d.update({'nmutt': self.nmutt}) |
| 637 |
|
return d |
| 638 |
|
|
| 639 |
|
def runIteration(self, task, pop, fpop, xb, fxb, **dparams): |
| 640 |
|
r"""Core function of algorithm. |
| 641 |
|
|
| 642 |
|
Args: |
| 643 |
|
task (Task): Optimization task. |
| 644 |
|
pop (numpy.ndarray): Current population of particles. |
| 645 |
|
fpop (numpy.ndarray): Current particles function/fitness values. |
| 646 |
|
xb (numpy.ndarray): Current global best particle. |
| 647 |
|
fxb (float): Current global best particles function/fitness value. |
| 648 |
|
**dparams: Additional arguments. |
| 649 |
|
|
| 650 |
|
Returns: |
| 651 |
|
Tuple[np.ndarray, np.ndarray, np.ndarray, float, dict]: |
| 652 |
|
1. New population of particles. |
| 653 |
|
2. New populations function/fitness values. |
| 654 |
|
3. New global best particle. |
| 655 |
|
4. New global best particle function/fitness value. |
| 656 |
|
5. Additional arguments. |
| 657 |
|
|
| 658 |
|
See Also: |
| 659 |
|
* :func:`NiaPy.algorithm.basic.WeightedVelocityClampingParticleSwarmAlgorithm.runIteration` |
| 660 |
|
""" |
| 661 |
|
pop, fpop, xb, fxb, d = ParticleSwarmAlgorithm.runIteration(self, task, pop, fpop, xb, fxb, **dparams) |
| 662 |
|
v = d['V'] |
| 663 |
|
v_a = (np.sum(v, axis=0) / len(v)) |
| 664 |
|
v_a = v_a / np.max(np.abs(v_a)) |
| 665 |
|
for _ in range(self.nmutt): |
| 666 |
|
g = task.repair(xb + v_a * self.uniform(task.Lower, task.Upper), self.Rand) |
| 667 |
|
fg = task.eval(g) |
| 668 |
|
if fg <= fxb: xb, fxb = g, fg |
| 669 |
|
return pop, fpop, xb, fxb, d |
| 670 |
|
|
| 671 |
|
class MutatedCenterParticleSwarmOptimization(CenterParticleSwarmOptimization): |
| 672 |
|
r"""Implementation of Mutated Particle Swarm Optimization. |