Skip to content

Commit 58113ef

Browse files
Add files via upload
1 parent 1411a6f commit 58113ef

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""This script has been used in Qiqi Duan's Ph.D. Dissertation (HIT&SUSTech).
2+
3+
Chinese: 该绘图脚本被段琦琦的博士论文(哈工大与南科大联合培养)所使用。
4+
"""
5+
import numpy as np
6+
import matplotlib
7+
import matplotlib.pyplot as plt
8+
9+
from pypop7.benchmarks.utils import generate_xyz
10+
# abstract class for all evolution Strategies
11+
from pypop7.optimizers.es.es import ES
12+
# Matrix Adaptation Evolution Strategy
13+
from pypop7.optimizers.es.maes import MAES
14+
15+
16+
matplotlib.rcParams['font.family'] = 'sans-serif'
17+
matplotlib.rcParams['font.sans-serif'] = 'SimSun'
18+
matplotlib.rcParams['axes.unicode_minus'] = False
19+
matplotlib.rcParams['font.size'] = 10 # 对应5号字体
20+
21+
22+
def cd(x): # from https://arxiv.org/pdf/1610.00040v1.pdf
23+
return 7.0 * (x[0] ** 2) + 6.0 * x[0] * x[1] + 8.0 * (x[1] ** 2)
24+
25+
26+
# helper function for 2D-plotting
27+
def plot_contour(func, x, y):
28+
x, y, z = generate_xyz(func, x, y, 500)
29+
plt.contourf(x, y, z, cmap='cool')
30+
plt.contour(x, y, z, colors='white', alpha=0.5)
31+
32+
33+
if __name__ == '__main__':
34+
ndim_problem = 2
35+
bound=[-10.0, 10.0]
36+
plt.figure(figsize=(5, 5))
37+
plt.title('不可分函数', fontsize=10)
38+
plt.xlim(bound)
39+
plt.ylim(bound)
40+
plt.xticks(fontsize=10)
41+
plt.yticks(fontsize=10)
42+
plot_contour(cd, bound, bound)
43+
plt.xlabel('维度1', fontsize=10)
44+
plt.ylabel('维度2', fontsize=10, labelpad=-1)
45+
plt.savefig(str(cd.__name__) + '.png', dpi=700, bbox_inches='tight')
46+
plt.show()

0 commit comments

Comments
 (0)