|
45 | 45 | class TestPSO(DerandomizedTestCase): |
46 | 46 |
|
47 | 47 | def test_pso_quad(self): |
48 | | - f_quad = lambda x: numpy.sum(10 * (x-0.5)**2) |
49 | | - hh_opt = ParticleSwarmOptimizer(['x','y','z','a'], fitness_function = f_quad) |
| 48 | + f_quad = lambda x: numpy.sum(10 * (x - 0.5) ** 2) |
| 49 | + hh_opt = ParticleSwarmOptimizer(['x', 'y', 'z', 'a'], fitness_function=f_quad) |
50 | 50 | hh_opt() |
51 | 51 |
|
52 | 52 | def test_pso_sin_sq(self): |
53 | | - f_sin_sq = lambda x: numpy.sum(np.sin(x - 0.2)**2) |
54 | | - hh_opt = ParticleSwarmOptimizer(['x','y','z','a'], fitness_function = f_sin_sq) |
| 53 | + f_sin_sq = lambda x: numpy.sum(np.sin(x - 0.2) ** 2) |
| 54 | + hh_opt = ParticleSwarmOptimizer(['x', 'y', 'z', 'a'], fitness_function=f_sin_sq) |
55 | 55 | hh_opt() |
56 | 56 |
|
57 | 57 | def test_pso_rosenbrock(self): |
58 | | - f_rosenbrock = lambda x: numpy.sum([((x[i+1] - x[i]**2)**2 + (1 - x[i])**2)/len(x) for i in range(len(x)-1)]) |
59 | | - hh_opt = ParticleSwarmOptimizer(['x','y','z','a'], fitness_function = f_rosenbrock) |
| 58 | + f_rosenbrock = lambda x: numpy.sum([ |
| 59 | + ((x[i + 1] - x[i] ** 2) ** 2 + (1 - x[i])** 2) / len(x) |
| 60 | + for i in range(len(x) - 1) |
| 61 | + ]) |
| 62 | + hh_opt = ParticleSwarmOptimizer(['x', 'y', 'z', 'a'], fitness_function=f_rosenbrock) |
60 | 63 | hh_opt() |
61 | 64 |
|
62 | 65 |
|
|
0 commit comments