Total Complexity | 2 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # Author: Simon Blanke |
||
2 | # Email: [email protected] |
||
3 | # License: MIT License |
||
4 | |||
5 | import pytest |
||
6 | import numpy as np |
||
7 | |||
8 | from gradient_free_optimizers import ParticleSwarmOptimizer |
||
9 | from ._base_para_test import _base_para_test_func |
||
10 | |||
11 | |||
12 | def objective_function(para): |
||
13 | score = -para["x1"] * para["x1"] |
||
14 | return score |
||
15 | |||
16 | |||
17 | search_space = {"x1": np.arange(-100, 101, 1)} |
||
18 | |||
19 | |||
20 | parallel_tempering_para = [ |
||
21 | ({"inertia": 0.5}), |
||
22 | ({"inertia": 0.9}), |
||
23 | ({"inertia": 0.1}), |
||
24 | ({"inertia": 0}), |
||
25 | ({"inertia": 2}), |
||
26 | ({"cognitive_weight": 0.5}), |
||
27 | ({"cognitive_weight": 0.9}), |
||
28 | ({"cognitive_weight": 0.1}), |
||
29 | ({"cognitive_weight": 0}), |
||
30 | ({"cognitive_weight": 2}), |
||
31 | ({"social_weight": 0.5}), |
||
32 | ({"social_weight": 0.9}), |
||
33 | ({"social_weight": 0.1}), |
||
34 | ({"social_weight": 0}), |
||
35 | ({"social_weight": 2}), |
||
36 | ({"temp_weight": 0.5}), |
||
37 | ({"temp_weight": 0.9}), |
||
38 | ({"temp_weight": 0.1}), |
||
39 | ({"temp_weight": 0}), |
||
40 | ({"temp_weight": 2}), |
||
41 | ({"rand_rest_p": 0}), |
||
42 | ({"rand_rest_p": 0.5}), |
||
43 | ({"rand_rest_p": 1}), |
||
44 | ] |
||
45 | |||
46 | |||
47 | pytest_wrapper = ("opt_para", parallel_tempering_para) |
||
48 | |||
49 | |||
50 | @pytest.mark.parametrize(*pytest_wrapper) |
||
51 | def test_hill_climbing_para(opt_para): |
||
52 | _base_para_test_func(opt_para, ParticleSwarmOptimizer) |
||
53 |